No opengl context in current thread

Started by Percy, December 30, 2014, 21:01:30

Previous topic - Next topic

Percy

This being my first project, I used some organization that maybe wasnt perfect, but seemed functional. I have some "utility" functions interspersed in the "main" loop for texturing and rendering quads, and have more than 1 class making calls to Opengl and slick util. All of this was working perfectly fine. I decided to make a super simplistic text rendering system based on a custom limited spritesheet with only the characters i needed. To implement this I copied a method from my generic entity class that bound textures. Heres where the trouble started. Now nearly everything I do with Opengl throws the above "java exception", no matter what  I do. I tried gathering all methods that used Opengl into one utility class, specifically for loading textures and placing quads on the screen, (Im using depreciated yet functional Opengl commmands)but this did not work. I am not multithreading. I have no idea what this exception means or why it's being thrown, or why it is thrown from a method in one class yet not thrown from the same method copied into an essentially IDENTICAL class with a different name, regardless of order of call. When I looked online someone had "shoehorned" a solution by just declaring the current thread the open gl context. This did not work for me.  I am at a complete loss as to how to proceed.
Edit: I once again moved all the methods that use Opengl into one class, yet it still throws the exception when certain classes try to call these methods. Not others, even though both classes are passing identical arguments. This whole business seems random and is irritating.  ???
Edit 2: so now I got it work but i dont understand why- It seems that if the static main method calls a method of a particular class, it occurs, but if the main calls a method of a class which has instances of another class and calls the same method that way its fine.....

Cornix

Are you using different threads? Are you using any third party libraries that are spawning additional threads?
OpenGL is not multi-threaded. Any OpenGL calls must be invoked on the Thread that created the OpenGL context.

Percy

I havent manually created multiple threads, (I barely understand threads) however, I am using the slick util library, as pretty much anywhere online that attempts to explain how to texture polygons always points you to slickutil.

Cornix

The OpenGL error you get is pretty clear about that. Somewhere in your code you invoke OpenGL calls on a Thread that has no OpenGL context. That is, either you are using several Threads or you call the methods before you have initialized the OpenGL context.

abcdef

Or you haven't created a context in the first place, how do you initialise opengl?