animator causes blank white screen

I am getting very strange results when I run this program. Most of the time the program works as it should, other times a white bar is displayed across the bottom of the screen (where the XP taskbar goes). Is this just a JOGL glitch? The main problem I am having is trying to add an Animator object. When I do, the screen goes blank white, and the init and display methods do not get called. I have noticed the NEHE tutorials use static classes and objects whereas my code does not. Is this necessary to use JOGL properly?



import java.nio.*;
import java.awt.*;
import java.awt.event.*;
import net.java.games.jogl.*;
import net.java.games.jogl.util.*;


public class Cube extends Frame implements GLEventListener, KeyListener
{
      private Animator animator;
      private FloatBuffer vertices;
      private IntBuffer indices;


    public Cube (GraphicsConfiguration gc)
    {
            super(gc);

        // create an OpenGL canvas
        GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

        // add a GLEventListener
        canvas.addGLEventListener(this);

        // now add the canvas to the frame
        add(canvas, BorderLayout.CENTER);

        // add a key listener to the frame and to the canvas
        addKeyListener(this);
            canvas.addKeyListener(this);

//            animator = new Animator(canvas);
    }


    public static void main (String[] args)
    {
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice gd = ge.getDefaultScreenDevice();
            GraphicsConfiguration gc = gd.getDefaultConfiguration();

            // create the frame with 800 x 600 resolution
        Cube frame = new Cube(gc);
            frame.setSize(640, 480);
            frame.setUndecorated(true);

            // set to full screen mode
            if( gd.isFullScreenSupported() )
                  gd.setFullScreenWindow(frame);

        //frame.setVisible(true);
        frame.show();
    }


    public void display (GLDrawable drawable)
    {
        System.out.println("display()");

            // retrieve the GL object
        GL gl = drawable.getGL();
        GLU glu = drawable.getGLU();

            // set the camera up
            glu.gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

            // clear the screen
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);

            // set the draw color to white
            gl.glColor3f(1.0f, 1.0f, 1.0f);

            // draw the cube
            gl.glDrawElements(GL.GL_QUADS, 24, GL.GL_UNSIGNED_INT, indices);

        // flush the buffer
        gl.glFlush();
    }


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


    public void init (GLDrawable drawable)
    {
            System.out.println("init()");

            // retrieve the GL object
        GL gl = drawable.getGL();

        // set the clear color to black
        gl.glClearColor(0, 0, 0, 0);

            // clear the screen
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);

            // set the polygon mode
            gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);

            // disable culling
            gl.glDisable(GL.GL_CULL_FACE);

            // create the cube object
            vertices = BufferUtils.newFloatBuffer(24);
            indices = BufferUtils.newIntBuffer(24);


            // load cube vertices
            vertices.put
            (
                  new float[]
                  {
                         1.0f,  1.0f,  1.0f,
                         1.0f,  1.0f, -1.0f,
                        -1.0f,  1.0f, -1.0f,
                        -1.0f,  1.0f,  1.0f,
                         1.0f, -1.0f,  1.0f,
                         1.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f,  1.0f
                  }
            );

            // load cube indices
            indices.put
            (
                  new int[]
                  {
                        0, 1, 2, 3,            // top face
                        4, 5, 6, 7,            // bottom face
                        0, 3, 7, 4,            // front face
                        1, 2, 6, 5,            // back face
                        0, 1, 5, 4,            // right face
                        2, 3, 7, 6            // left face
                  }
            );

            // enable the open GL vertex array
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);

            // fill up the vertex array with the cube vertices
            gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices);

//            animator.start();
    }


    public void reshape (GLDrawable drawable, int x, int y, int width, int height)
      {
            // retrieve the GL object
        GL gl = drawable.getGL();

            gl.glViewport(x, y, width, height);
            gl.glMatrixMode(GL.GL_PROJECTION);
            gl.glLoadIdentity();
            gl.glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
            gl.glMatrixMode(GL.GL_MODELVIEW);
    }

      public void keyPressed(KeyEvent ke)
      {
            int key = ke.getKeyCode();

            if(key == KeyEvent.VK_ESCAPE)
            {
//                  animator.stop();
                   System.exit(0);
            }
      }

      public void keyReleased(KeyEvent ke)
      {
      }

      public void keyTyped(KeyEvent ke)
      {
      }

}


I have a related problem. It seems that (only in full-screen mode), the animator just gets my application to show a blank screen (white if it’s a Frame that contains the glCanvas and grey if it’s a JFrame.getContentPane() that contains the glCanvas).

I did manage to solve this blank screen by making sure there was no frame.show() or frame.setVisible(true) before the

GraphicsEnvironment
      .getLocalGraphicsEnvironment()
      .getDefaultScreenDevice()
      .setFullScreenWindow(frame);

Unfortunately, the application now just shows the first frame, and then freezes. The display() method is still being called about 70 times per second (according to a println statement I put in it.) But nothing ever changes on the screen.

If I replace

GraphicsEnvironment
      .getLocalGraphicsEnvironment()
      .getDefaultScreenDevice()
      .setFullScreenWindow(frame);

with

frame.setSize(400,300);      
frame.show();

The program animates and works correctly! But I need full screen. Arse. Frustrating.

I feel like the display method is writing to the wrong part of memory, because the OS (Windows 2000) has taken over that new full-screen window or something. A vague sugestion…but I’m at a loss.

Has anyone had any luck resolving an animator-full screen problem like this?

Here is the section of my code that you might be able to see a bug in:

public static void main(String[] args) {

            JFrame frame = new JFrame("Endosim");
            frame.setUndecorated(true); //Undecorated for fullscreen mode 
            frame.setIgnoreRepaint(true); //Ignore Repaint for fullscreen mode
            GLCanvas drawable = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
            System.err.println("DRAWABLE GL IS: " + drawable.getGL().getClass().getName());
            System.err.println("DRAWABLE GLU IS: " + drawable.getGLU().getClass().getName());
            drawable.addGLEventListener(new Endosim(frame));
            
            frame.getContentPane().add(drawable);
      
            //usedDevice.setDisplayMode(usedDevice.getDisplayModes()[40]);
            
            GraphicsEnvironment
                  .getLocalGraphicsEnvironment()
                  .getDefaultScreenDevice()
                  .setFullScreenWindow(
                  frame);
                  
//            frame.setSize(400,300);      
//            frame.show();
                        

            animator_ = new Animator(drawable);
            animator_.start();
      }

I believe the frame’s contentPane has a FlowLayout as default. Which will not resize the GLCanvas… Try switching it to a BorderLayout and add the GLCanvas using the BorderLayout.CENTER attribute.

Thats what I do, and my app runs fine in full screen. On both, Linux and Windows.

This didn’t seem to help. The application goes to full screen, draws the first frame…and then never draws anything again (but the display() method is called regularly as it should be, by the Animator).

Cheers for the idea tho…any other suggestions? I’m going to try this on another PC. I wonder if it’s a specific driver based problem.

It’s windows 2000 with an Intel on-board graphics adapter…82845 chipset…

Try specifying -Dsun.java2d.noddraw=true on the command line. This disables the use of DirectDraw in the Java2D implementation and changes how full-screen mode works in the AWT on Windows.

Thanks. That trick solved the problem.

Trick repost: JVM command line argument…

-Dsun.java2d.noddraw=true

No more blank screen s…no more frozen first frames. It works with a JFrame containing the glCanvas or a regular old Frame containing the glCanvas.

Incidentally, I tried running my app on a different PC – and it worked fine (without the -Dsun.java2d.noddraw=true ). Both machines run Windows 2000, but they have different graphics cards.

Thanks again for your help! 8) ;D

i’m having the same problem under MacOS X.
the vm-trick won’t help me - i have no directx.

i get it running in a frame, but not in fullscreen. just a black screen.
display() is called. glFlush() and glFinish() do not help.

any idea?

I’m having a hanging problem in Mac OS X too. I’m running only in windowed mode-it seems like jogl fullscreen in os x is just broken. Sometimes my program works perfectly, but sometimes it prints an error, runs init and draws the first frame, and then never updates. The error comes up right after animator.start(), before the init() gets called:

 Error: view width or height == 0at "src/native/jogl/MacOSXWindowSystemInterface.m:createContext:44"
      net.java.games.jogl.GLException: Error creating nsContext
          at net.java.games.jogl.impl.macosx.MacOSXGLContext.create(MacOSXGLContext.java:140)
          at net.java.games.jogl.impl.macosx.MacOSXGLContext.makeCurrent(MacOSXGLContext.java:149)
          at net.java.games.jogl.impl.macosx.MacOSXOnscreenGLContext.makeCurrent(MacOSXOnscreenGLContext.java:137)
          at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:203)
          at net.java.games.jogl.impl.macosx.MacOSXOnscreenGLContext.invokeGL(MacOSXOnscreenGLContext.java:84)
          at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:186)
          at net.java.games.jogl.GLCanvas.display(GLCanvas.java:74)
          at net.java.games.jogl.Animator$1.run(Animator.java:104)
          at java.lang.Thread.run(Thread.java:552)

Is it trying to draw before it’s finished setting up the context? I want to run it as a subwindow within a larger program, so it’s in a modified JPanel that contains a GLCanvas, instead of a Frame, in case that could have anything to do with it.

Just to note, I have never been able to get my or anyone elses JOGL applications to work in fullscreen under Mac OS X.

I’m sure this is a well known problem, is there a list anywhere with bug reports for the JOGL API? What is the status on this bug?

Regards,

Ribot.

Sys: Mac OS X (10.3.4), ATI Radeon 9700, Java 1.4.2_03