hi all this is my first post after registering last week and first off i have been doing openGL for about 5 years now so if any of you need help you can IM me or just post as i will be starting to look into these forums a lot this is a great site btw.
back to the topic at hand i have this basic jogl program but whenever i resize their is a flickering, sorta like the buffer isnt being swapped correctly or something. usually in my openGL programs using glut i do a glutSwapBuffers() in the draw function instead of flush but this is what i have right now as i donβt know what the basic set up is or what the correct set up for me would be. basically all i want Java to do is set up for me a window and a place for me to use SWT or swing for my widget stuff. i dont need much fancier than that. anyway here is the code so if you would look at the code and try to make some suggestions or maybe try out the code for yourself to see where the flickering is coming from then that would be great and thanks so much in advance!
i am on Ubuntu Linux with a GeForce 4200 Ti(i know very old but i am waiting any day now on an upgrade to a Geforce 7600 GS). the version of java i have is /JOGL/jogl-1.1.0-rc3-linux-i586. thanks again!
import com.sun.opengl.util.Animator;
import com.sun.opengl.util.GLUT;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
public class TestGL implements GLEventListener
{
public void init(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
System.err.println("INIT GL IS: " + gl.getClass().getName());
// Enable VSync
gl.setSwapInterval(1);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearDepth(1.0);
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
{
GL gl = drawable.getGL();
GLU glu = new GLU();
if (height <= 0)
height = 1;
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void display(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
GLUT myglut = new GLUT();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(-1.5f, 0.0f, -6.0f);
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glVertex3f(0.0f, 1.0f, 0.0f);
gl.glColor3f(0.0f, 1.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, 0.0f);
gl.glColor3f(0.0f, 0.0f, 1.0f);
gl.glVertex3f(1.0f, -1.0f, 0.0f);
gl.glEnd();
gl.glTranslatef(3.0f, 0.0f, 0.0f);
gl.glBegin(GL.GL_QUADS);
gl.glColor3f(0.5f, 0.5f, 1.0f);
gl.glVertex3f(-1.0f, 1.0f, 0.0f);
gl.glVertex3f(1.0f, 1.0f, 0.0f);
gl.glVertex3f(1.0f, -1.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, 0.0f);
gl.glEnd();
gl.glFlush();
//myglut.glutSwapBuffers();
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)
{
}
public static void main(String[] args)
{
Frame frame = new Frame("Testing a JOGL Application");
GLCanvas canvas = new GLCanvas();
// canvas.setAutoSwapBufferMode(true);
canvas.addGLEventListener(new TestGL());
frame.add(canvas);
frame.setSize(640, 480);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
new Thread(new Runnable()
{
public void run()
{
animator.stop();
System.exit(0);
}
}).start();
}
});
// Center frame
frame.setLocationRelativeTo(null);
frame.setVisible(true);
animator.start();
}
}