From: <NM...@th...> - 2001-10-09 08:10:29
|
Hi, I've recently managed to get the GLJPanel displaying on my system(Win 2000. JDK 1.3.1). I've noticed, however, that there is a weird error occurring regarding axis orientation. I may be missing something but it seems as though the Y axis is correct in GLCanvas but is inverted when the same world is rendered in GLJPanel. Odd error. I've included an example below that illustrates the issues. STEP 1: The code below will originally launch an Internal Frame containing a GLCanvas. In the canvas I draw 3 cones, a Red pointing out towards us along the Positive Z Axis, a Blue one pointing down the positive X Axis and a Green one pointing up the Positive Y Axis. STEP 2: If you then go into the code and ONLY: (SEE COMMENTS IN CODE TOO) Uncomment lines : 16, 23 Comment lines : 13, 78 STEP 3: and recompile you will then see the same example but this time with a GLJPanel in the internal frame. The example is in all other cases identical. In this case all axis are the same except that the Y Axis, the Green Cone, is now pointing in the opposite direction. Obviously a JPanel and a Canvas should not produce different orientation. Am I not setting something correctly? Or is this a bug? Thanks in advance for your help, Noah Keen HERE IS THE EXAMPLE CODE : import javax.swing.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import gl4java.*; import gl4java.awt.*; import gl4java.utils.glut.*; import gl4java.swing.*; /*** COMMENT THE LINE BELOW TO RUN GLJPANEL *****/ public class GLCanvasTest extends GLCanvas { /*** UNCOMMENT THIS TO RUN GLJPANEL ********/ //public class GLCanvasTest extends GLJPanel { public GLCanvasTest() { super(200, 200); /*** UNCOMMENT BELOW TO RUN GLJPANEL ****/ //super(); } /** * Sets up all basic OpenGL parameters. Adds lights and sets default material. **/ public void init() { gl.glShadeModel(GL_SMOOTH); gl.glEnable(GL_LIGHTING); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glEnable(GL_LIGHT1); float ambient[] = {0.2f, 0.2f, 0.2f, 0.0f}; float diffuse[] = {0.6f, 0.6f, 0.6f, 0.0f}; float specular[] = {1.0f, 1.0f, 1.0f, 0.0f}; float position[] = {1.0f, 1.0f, 1.0f, 0.0f}; gl.glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); gl.glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); gl.glLightfv(GL_LIGHT1, GL_SPECULAR, specular); gl.glLightfv(GL_LIGHT1, GL_POSITION, position); gl.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); gl.glEnable(GL_NORMALIZE); // init the projection and ModelView matrix gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity(); } /** * Rotates, translates and displays the world **/ public void display() { /* Standard GL4Java Init */ if ( cvsIsInit()==false || glj.gljMakeCurrent() == false ) { return; } // clear old gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //draw drawAxis(); // a GL4Java necessity glj.gljSwap(); /*** COMMENT THE LINE BELOW TO RUN GLJPANEL *****/ glj.gljFree(); } /** * Empty. For simplicity **/ public void reshape(int width, int height) { } /** * Draws three arrows on the X, Y and Z axis. * A cone which points from the origin to the POS plane of the axis * * NOTE!!!! - glu.gluCylinder() by default draws from the origin along * the POS Z axis. * **/ private void drawAxis() { float red[] = {1.0f, 0.0f, 0.0f, 0.0f}; float green[] = {0.0f, 1.0f, 0.0f, 0.0f}; float blue[] = {0.0f, 0.0f, 1.0f, 0.0f}; // draw a GREEN Y axis gl.glPushMatrix(); gl.glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); gl.glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green); glu.gluCylinder(glu.gluNewQuadric(), 0.05f, 0.0f, 0.5f, 5, 5); gl.glPopMatrix(); // draw a GREEN Y axis gl.glPushMatrix(); gl.glRotatef(90.0f, 0.0f, 1.0f, 0.0f); gl.glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue); glu.gluCylinder(glu.gluNewQuadric(), 0.05f, 0.0f, 0.5f, 5, 5); gl.glPopMatrix(); // draw a RED Z AXIS gl.glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red); glu.gluCylinder(glu.gluNewQuadric(), 0.05f, 0.0f, 0.5f, 5, 5); } static GLCanvasTest canvas; public static void main(String[] args) { JFrame frame = new JFrame("Test"); JDesktopPane desktop = new JDesktopPane(); JInternalFrame iFrame = new JInternalFrame("Test", true, true, true, true); canvas = new GLCanvasTest(); frame.setSize(300,300); iFrame.setSize(200, 200); iFrame.setVisible(true); iFrame.getContentPane().add(canvas); desktop.add(iFrame); iFrame.getContentPane().add(canvas); frame.getContentPane().add(desktop); desktop.setVisible(true); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { canvas.cvsDispose(); System.exit(0); } }); } } |