0

So I am making a game in LWJGL (2 I think) and I have been working on a tile grid. but when I am binding my textures I am getting an exception and the game won't open (obviously) so I have been trying to solve this for an hour but I can't seem to get it to work. here is my code, can someone correct it for me?

FILEPATH: filepath

code: (main class) http://pastebin.com/GvxEyGRQ

code: (GridHandler class) http://pastebin.com/2fcwLXU5

code: (TileType class - it is an enum) http://pastebin.com/Dk0v3BRc

code: (Tile class) http://pastebin.com/TNATAjJW

code: (renderer class) http://pastebin.com/MBhReiAb

my error:
Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: 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:200) at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:64) at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:24) at Functions.renderer.loadTexture(renderer.java:58) at Functions.renderer.quickLoad(renderer.java:67) at Window.Tile.(Tile.java:20) at Window.GridHandler.(GridHandler.java:30) at Window.Main.(Main.java:31)

Thanks in advance, Bryan.

Bryan
  • 13
  • 4
  • It has to do with the OpenGL context. The thread executing the commands doesn't own it. Unfortunately I don't know lwjgl to help you, but that's should be the direction you should look into.. – elect Apr 13 '16 at 08:44
  • Okay, Ill keep that in mind. Thanks – Bryan Apr 13 '16 at 09:05

1 Answers1

0

I think it might be because your static GridHandler grid = new GridHandler(map) is instantiated before the main method.

You create the context in the beginning of your main method but the GridHandler is instantiated before the main() and therefore the context hasn't been created yet and you try to load texture with quickload method from the renderer in your TileHandler class - map[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.stone);

In order to execute gl commands you need a context first(Display.create() creates the current context). What TextureLoader does is that it loads the texture on the GPU(therefore executing commands).

Nikolai Nikolov
  • 428
  • 3
  • 13
  • That worked, I already figures it out when I saw the "No OpenGL context found in the current thread, how do I fix this error?" javac posted, but thank you anyway – Bryan Apr 13 '16 at 15:08