TextureIO.newTexture() and "No OpenGL context current on this thread"
in
Core Library Questions
•
2 years ago
Here is a description of what I'm trying to accomplish:
I am creating an application which loads in a series of images sequentially on the fly and displays them using OpenGL. The images are loaded in a separate thread, and each time one is loaded the image is passed to a callback method in a listener object in my processing thread. The image is added to a linked list, and continually checks on draw if the new image has been loaded and can be displayed. The end result is a collection of images stacked in z-space, with the older images moving back and the newer ones fading-in in front.
I got this working successfully, however I was running into a memory leak issue similar to the one described here:
Since I do not yet want to use an unstable release of processing, I attempted to find a workaround by using direct OpenGL calls to display the image as a texture similar to how it is done here (reply #5 specifically):
However, I still want to be able to load the image in a separate thread so that the rest of my graphics being displayed continue to do so without hanging or stuttering. With this in mind, I am loading a BufferedImage in the separate thread, passing it to the callback method, and then attempting to convert it to a Texture object using TextureIO:
- texture = TextureIO.newTexture(photo, true);
I get this error when I run it:
javax.media.opengl.GLException: No OpenGL context current on this threadat javax.media.opengl.glu.GLU.getCurrentGL(GLU.java:234)at com.sun.opengl.util.texture.Texture.<init>(Texture.java:179)at com.sun.opengl.util.texture.TextureIO.newTexture(TextureIO.java:445)at com.sun.opengl.util.texture.TextureIO.newTexture(TextureIO.java:539)at edu.mit.senseable.backtalk.Photo.<init>(Photo.java:69)at edu.mit.senseable.backtalk.PhotoStack.imageLoaded(PhotoStack.java:145)at edu.mit.senseable.backtalk.ImageLoader.run(ImageLoader.java:41)
A little more detail about the classes:
PhotoStack exists at the top level of my class extending PApplet.
ImageLoader extends Thread and it's instance exists within PhotoStack.
PhotoStack implements the ImageListener to provide a callback method.
Photo is instantiated within PhotoStack whenever a new BufferedImage has been passed into PhotoStack via the callback.
Photo attempts to create the Texture object within it's constructor.
I'm at a bit of a loss at this point attempting to set the current OpenGL context. It's my understanding that the object utilizing TextureIO should already be running within the OpenGL context (of which there is only one). Any advice/assistance would be greatly appreciated.
1