GLJPanel in Eclipse

Hello,

I have a strange behaviour. I’m having a GLJPanel in a project in Eclipse, When I run it, everythins is as should be (the (0, 0) coördinate is at the center of the screen). When I try to run everything from command-line, everything is moved downwards.

If I use a GLCanvas, embedded in a JPanel, they both (Eclipse and command-line) show the (0, 0)-coördinate in the center of the screen.

Does anybody know what the problem could be??

Thanks in advance,
Nico

Okay, it has something to do with -Dsun.java2d.opengl=“true”, if I remove that part, the strange behaviour doesn’t apear.

Hello,

I have been searching for a while and made a small testcase.

GLDemo.java


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.media.opengl.*;

public class GLDemo{
	public GLDemo(){
		JFrame frame = new JFrame("test");
		frame.setPreferredSize(new Dimension(800, 600));

		JPanel upperPanel = new JPanel();
		upperPanel.setLayout(null);
		upperPanel.setBackground(Color.GREEN);

		//GLCanvas glpanel = new GLCanvas();
		GLJPanel glpanel = new GLJPanel();
		glpanel.addGLEventListener(new GLDemoRenderer());

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		glpanel.setSize(450, 450);
		upperPanel.add(glpanel);
		frame.add(upperPanel);

		frame.pack();

		frame.setVisible(true);
	}

	public static void main (String args[]) {
		SwingUtilities.invokeLater(new Runnable(){
			public void run(){
				GLDemo gldemo = new GLDemo();
			}
		});
	}
}

GLDemoRenderer.java


import javax.media.opengl.*;
import javax.media.opengl.glu.GLU;
import com.sun.opengl.util.*;

public class GLDemoRenderer implements GLEventListener{

	public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){
	}

	public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height){
		final GL gl = drawable.getGL();
		gl.glViewport(0, 0, width, height);
		gl.glMatrixMode(GL.GL_PROJECTION);
		gl.glLoadIdentity();
		gl.glOrtho(-2, 2, -2, 2,0, 10);
		gl.glMatrixMode(GL.GL_MODELVIEW);
	}

	public void display(GLAutoDrawable drawable){
		final GL gl = drawable.getGL();
		final GLUT glut = new GLUT();

		gl.glClear(GL.GL_COLOR_BUFFER_BIT);
		gl.glLoadIdentity();

		gl.glTranslatef(0.0f, 0.0f, -6.0f);
		glut.glutWireCube(1.0f);
		gl.glLoadIdentity();
	}

	public void init(GLAutoDrawable drawable){
		final GL gl = drawable.getGL();
		gl.glClearColor(0,0,0,0);
	}
}

When, in GLDemo.java,

GLJPanel glpanel = new GLJPanel

is changed into

GLCanvas glpanel = new GLCanvas()

the cube is drawn on an other place.

I’m working on Ubuntu 7.10, java 6, jsr-231-1.1.0

thanks,
Nico

You’re ignoring the x and y coming in to your reshape() method. If you pay attention to them you should get the correct results.

stupid me…,

Still, strange that it only happens with GLJPanel on the command line with -Dsun.java2d.opengl=“true”. Or is this just coincidence?

Nico

This is by design and is how the Java 2D / JOGL bridge works.