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