Reputation: 946
I've just started playing with slick2d's state based game structure. I've set up the main class as follows
public static final int newMenu = 0;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
AppGameContainer appgc;
try {
appgc = new AppGameContainer(new StateBased("StateBased Test"));
appgc.setDisplayMode(640, 360, false);
appgc.start();
} catch (SlickException e) {
}
}
public StateBased(String name) throws SlickException {
super(name);
this.addState(new NewMenu(newMenu));
}
@Override
public void initStatesList(GameContainer gc) throws SlickException {
this.getState(newMenu).init(gc, this);
}
now the new menu class so far has
private final int state;
private final Image bg;
private final static String directory = "Images/StartScreen/";
public NewMenu(int state) throws SlickException {
this.state = state;
bg = new Image(directory + "loadbg.png");
}
but i'm getting at error at the "bg=new image" line. "No OpenGL context found in the current thread." I'm confused since I haven't got this when using basicgame instead of statebasedgame
Can anyone help me solve this
This is the full error
Exception in thread "main" java.lang.RuntimeException: No OpenGL context found in the current thread. at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124) at org.lwjgl.opengl.GL11.glGetError(GL11.java:1299) at org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer.glGetError(ImmediateModeOGLRenderer.java:384) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:249) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:187) at org.newdawn.slick.Image.(Image.java:192) at org.newdawn.slick.Image.(Image.java:166) at org.newdawn.slick.Image.(Image.java:154) at org.newdawn.slick.Image.(Image.java:132) at statebased.NewMenu.(NewMenu.java:23) at statebased.StateBased.(StateBased.java:36) at statebased.StateBased.main(StateBased.java:27)
Upvotes: 1
Views: 2254
Reputation: 946
Fixed by moving the code from the constructor to the init method
Upvotes: 1