Fullscreen Problem on Mac

Hello to everyone,

I have problems running fullscreen jogl applications on macs.
I tried both my code and jogl sample gears-fullscreen demo and
the screen is completely black. These programs run correctly
in windowed mode. They also run correctly on windows xp machines
in fullscreen mode.

I also noticed that the first frame of gears demo is rendered
correctly. Perhaps this is done before the frame becomes fullscreen.

I tried a non-jogl fullscreen java application work well on these macs.

macs are:
emac with java 1.4.2,
powerbook g4 with java 1.5

win machines are:
java 1.6 and 1.4.2
with radeon x1600 video card

the code is compiled for java version 1.1

Has anyone successful experience with macs in fullscreen mode?
What is wrong with this code:


package test;
import javax.media.opengl.*;
import java.awt.*;
import java.awt.event.*;

public class Test implements GLEventListener {			
    private GLCanvas canvas;
	private int sizex, sizey;

	public static void main(String[] args) {	
		new Test();
	}	
	Test() {		
		create_window();
		while(true)	{
			canvas.display();
			Thread.yield();
		}	
	}	
	private void create_window() {
		GraphicsDevice dev = GraphicsEnvironment.
			getLocalGraphicsEnvironment().
			getDefaultScreenDevice();
	
		if (!dev.isFullScreenSupported())
			die("!dev.isFullScreenSupported()");

		int initWidth = 400, initHeight = 300;

		DisplayMode mode = null;
		DisplayMode[] modes = dev.getDisplayModes();
		//	find any 32 bit mode:
		for(int i = 0 ; i < modes.length; i++) 
		{
			if (modes[i].getBitDepth() == 32 && modes[i].getWidth() >= 640) 
			{
				mode = modes[i];
				break;
			}
		}

		initWidth = mode.getWidth();		
		initHeight = mode.getHeight();

		canvas = new GLCanvas();
		canvas.addGLEventListener(this);
		canvas.addGLEventListener(new FullscreenWorkaround(initWidth, initHeight));

		Frame frame = new Frame("test");
		frame.setUndecorated(true);
		frame.setLayout(new BorderLayout());
		canvas.setSize(initWidth, initHeight);
		frame.add(canvas, BorderLayout.CENTER);
		frame.pack();
		canvas.setFocusable(true);
		canvas.requestFocus();

		frame.addWindowListener(new WindowAdapter() 
		{
			public void windowClosing(WindowEvent e) 
			{
				System.exit(0);
			}
		});

		dev.setFullScreenWindow(frame);
		if (!dev.isDisplayChangeSupported())
			die("!dev.isDisplayChangeSupported()");
		dev.setDisplayMode(mode);
	
		frame.setVisible(true);
	}
	
	public void init(GLAutoDrawable drawable){ }
	public void reshape(GLAutoDrawable drawable, int x1, int y1, int x2, int y2) { 
		sizex = x2-x1;
		sizey = y2-y1;
	}
	public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){}
	public void display(GLAutoDrawable drawable) 
	{
		GL gl = drawable.getGL();
		gl.glViewport(0, 0, sizex, sizey);
		gl.glMatrixMode(GL.GL_PROJECTION);
		gl.glLoadIdentity();
		gl.glOrtho(0, sizex, 0, sizey, -1, 1);
		gl.glMatrixMode(GL.GL_MODELVIEW);
		gl.glLoadIdentity();

		gl.glColor3f(1,1,1);
		gl.glRectf(100, 100, 500, 400);
	}

	private static void die(String message) {
		javax.swing.JOptionPane.showMessageDialog( 
		null, message, "message", 
		javax.swing.JOptionPane.PLAIN_MESSAGE, null);
	}
}

I don’t get a black screen with the GearsFullscreen demo (on the Mac G5 tower in my office), but I do see that the GLCanvas is the wrong size after switching into full-screen mode. There have been bugs in the full-screen implementations on all platforms in various JDK releases, the Mac included, and unfortunately it seems it’s still necessary to do workarounds. I can’t reproduce the behavior with your test case you mention, but have you tried using a JFrame instead of a Frame, and removing the use of the FullscreenWorkaround? That seems to improve the behavior of the GearsFullscreen demo on my machine at least. You should also glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) at the top of your display() method.

Thanks a lot!
While experimenting with JFrame, i discovered that removing FullscreenWorkaround solved the problem.
So it seems like either i am not using FullscreenWorkaround correctly or it does not work on some macs.

The problem’s probably with the FullScreenWorkaround. It was a best effort attempt to work around bugs seen on all platforms a while back. I’ll revise the demos and remove it as needed.