[JOGL2]Little patch suggestions for GLJPanel

Hi,

I tried to use GL3 with the GLJPanel, but it gives me an exception:

Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: Not a GL2 implementation[..]

So I looked at the source code of the GLJPanel Class and found three little pieces of code that need to be changed to make GLJPanel compatible with GL3 and GL2.

The first two are easy:

573c573
<         getGL().getGL2().glViewport(viewportX, viewportY, panelWidth, panelHeight);
---
>         getGL().getGL().glViewport(viewportX, viewportY, panelWidth, panelHeight); 
816c816
<           GL2 gl = getGL().getGL2();
---
>           GL gl = getGL().getGL();

The third one is a little ugly, but maybe there is a better jogl way for doing the same:

831c831,833
<           gl.glReadBuffer(GL2.GL_FRONT);
---
>           if(getGL().isGL3()) getGL().getGL3().glReadBuffer(GL2.GL_FRONT);
>           else getGL().getGL2().glReadBuffer(GL2.GL_FRONT);

Additionally, I had a problem with the width of the GLJPanel. This problem is irrespectively from GL2/GL3 and seems to be the same as described here: http://www.java-gaming.org/index.php/topic,21772.0.html

I debug this, but the panel and the offscreenImage had the right size. The pBuffer is big enough, too. But the offscreenImage had a black strip on the right side. So I do not really know where the problem exactly is, but this work around works here:

1094,1095c1096
<         pbufferWidth = getNextPowerOf2(panelWidth);
<         pbufferHeight = getNextPowerOf2(panelHeight);
---
>         pbufferWidth = pbufferHeight = Math.max(getNextPowerOf2(panelWidth), getNextPowerOf2(panelHeight)); 

(I think this need a little more research)

If you want to try this, you can download the whole GLJPanel.java from here: http://too-late.de/snippets/GLJPanel.java

It will be very nice if one of the jogl maintainer can look over this suggestions, make it jogl conform and use a little bit of it in the official source.

Thanks and best regards,
Fancy

This could be:


getGL().getGL2GL3().glReadBuffer(GL2.GL_FRONT);

The GL2GL3 profile is the profile intersection between GL2 and GL3, which I find very useful in situations such as this.

Oh yes, that’s much clearer! (I never noticed the GL2GL3 profile before.)

Best regards,
Fancy