Search code examples
opengljoglopenglcontext

How can I create my own openGL context and bind it to a GLCanvas?


So when I got to grips with the java

paint(Graphics g){}

method I moved on to creating my own render methods but I had to learn about buffer strategies and how to 'get' Graphics

So now I am learning openGL, I have got to grips with the method:

@Override
public void display(GLAutoDrawable arg0){}

and now I would like to create my own render methods, so far I have constantly run up against one exception:

Exception in thread "main" javax.media.opengl.GLException: No OpenGL context current on this thread

EDIT: Question: If I want to make glDraw calls outside of the

@Override
public void display(GLAutoDrawable arg0){}

method, how do I ensure the glContext of my GLCanvas is "current"

Preferably as a code example, as I Have looked through the api's and used google extensivly, many links you guys have already been so kind as to put here I have already found before and I am still drawing a blank... literally! Closest I've got was when it didn't throw a "no current context" exception but the screen just went black permenantly!


Solution

  • I found documentation discussing this issue here:

    http://fivedots.coe.psu.ac.th/~ad/jg2/ch15/index.html

    The GLContext.makeCurrent()/release() hack seems to work for me under Linux/OpenJDK 6/JOGL 2, but we will see... in particular, making the OpenGL context switch thread all the time like that will incur (too much?) overhead.

    Then there is NEWT of JOGL 2 and LWJGL's toolkit, but they seem to be a whole new ball of wax to handle, bye bye Swing. :(