AWTGLCanvas not painting

Can anyone point me to a working application using AWTGLCanvas?

I’ve subclassed it and overriden paintGL() and update(), both of which are getting called, but nothing is happening. I tried some simple OGL as follows:


    protected void paintGL() {
        System.out.print("paint ");
        System.out.println(getWidth()+" "+getHeight());
        GL11.glClearColor(1f, 0f, 0f, 0f); // Red
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
   }

I though something would happen, but it doesn’t (I tried alpha=1 also);

Incidentally, If I want to initialise the projection matrix where does the initialisation go? Can I call makeCurrent() in the constructor (after explicitly calling underlying constructor to be on safe side), and then do some GL?

Alan

Edit: I added a swapBuffers() at the end of paintGL(), and got a nice red square. I’d still like recommendations on where (and how) to put in the initialisation code.


java.lang.IllegalStateException: Canvas not yet displayable

Initialisation… Ho Hum.

Edit2: Does each context have its own projection and model matrices, or is there a common one. I.e. there is more then one AWTGLCanvas do I need to set up projection on each paint() call?

I can’t help you with most of this thread except to say that as far as programs are concerned, every context is completely totally unique, each with its own state. There are one or two extensions to let them share a bit of memory here and there.

Cas :slight_smile:

Cas,

Thanks for confirming that the contexts are completely separate. For initialisation, I’m going with a flag which I check on every paintGL() call. If it’s false, the initialisation code gets called, which in turn sets the flag. Perhaps not the most elegant solution, but it works. Think that covers my initial queries :slight_smile:

So far I’ve converted most of my (very basic) software renderer based level editor over to a AWTGLCanvas based implementation. The only visible difference is some missing pixels along the edges of the faces in the opengl version, which needs looking at. Lots to do yet, but very promising.

Alan