Java2D/JOGL Interoperability problem?

Hello All,

When I am learning JOGL, I find something strange with the Java2D/JOGL interoperability.
I am not sure if I did anything wrong, or if there is a bug in the Java2D/JOGL Interoperability
implementation? Below is a description of the problem:

When I run my program with /usr/java/jdk1.6.0/bin/java TestJogl, I got result as shown in the first image
(testjogl1.jpg).

When I run the program with /usr/java/jdk1.6.0/bin/java -Dsun.java2d.opengl=true TestJogl, I got result
in the second image (testjogl2.jpg).

If I increase the number of rows of the table, the sphere will go down more in the case of un.java2d.opengl
enabled. It seems to me that the GLPanel does not respect the layout and insists on using the lower space.

I also attach my program. Please help me to solve this problem. Thank you very much.

Guo

You need to pay attention to the (x, y) coordinates coming down in your reshape() callback. Your call to glViewport should look like


        gl.glViewport(x, y, width, height);

or just skip this call altogether as it is done for you by the JOGL implementation.

I’d also be concerned about the fact that you aren’t clearing the color buffer but that doesn’t seem to be a problem in your test case. There are only some situations where it’s legal and expected for the app to not clear the color buffer; specifically, when your GLJPanel is not opaque and GLJPanel.shouldPreserveColorBufferIfTranslucent() returns true.

Thank you very much, Ken. I even did not notice the glViewport call. It must come in
from a copy and paste :-[ And I did not clear the color buffer because I do not know
how to make it transparent. I will study the JGears and Gears examples more carefully.

One more question: why the results are correct, if I do not enable the sun.java2d.opengl option?

Thanks again.

Enabling the Java2D/OpenGL pipeline in Mustang turns on the new Java2D/JOGL interoperability which causes JOGL to draw its results directly to the Swing back buffer. Previously it had been drawing to either a heavyweight Canvas or to an appropriately-sized pbuffer and in both cases the (x, y) coordinates for the reshape() callbacks had always been (0, 0). Several of the JOGL demos had to be updated to fix exactly this bug, btw.