Basic JOGL Test flickers on reshape...

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 :slight_smile: 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();
    }
}

Maybe you are experiencing this bug: http://www.java-gaming.org/index.php/topic,16573.msg130553/topicseen.html#msg130553

thanks for the link. it seems this is indeed the case but the last mention of it was over a year ago. i have Java 6 installed from the latest updates. i assume the issue was never resolved??

Did you specify -Dsun.awt.noerasebackground=true on the commandline when starting your app?

oh yeah sorry i did and it worked fine - was just wondering if they added this to the API yet in the background or just left it up to people to just use the flag.

thanks cylab for your help!

Hello,

it seems the problem is back in Java 6u10 or 6u11 on Windows (XP and Vista)
Setting -Dsun.awt.noerasebackground=true does not help now.

Is there any way to fix it in Jogl? Or do we need Sun to fix it?

–
Marek