Why GLCanvas does not show up in Full Screen mode

Started by Wojtek, October 26, 2009, 11:04:26 PM

Previous topic - Next topic

Wojtek

Hello,

Recently I tried to use full screen mode in my game but I found that GLCanvases that I use did not showed up after my change.

Here is an example code that shows my problem:

package Test;

import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;

public class FullScreenTest extends JFrame
{
    private GraphicsDevice device;
    private FrameBuffer buffer;
    private Canvas canvas;
    private World world;
    private Object3D object;
    private Timer timer;

    public static void main(String[] args)
    {
FullScreenTest frame = new FullScreenTest();
frame.setVisible(true);
    }

    public FullScreenTest()
    {
initResolution();
initComponents();
initCanvas();
initWorld();
startRendering();
    }

    private void startRendering()
    {
timer = new Timer(50, new ActionListener()
{

    @Override
    public void actionPerformed(ActionEvent e)
    {
renderScene();
    }
});
    }

    protected void renderScene()
    {
object.rotateX(0.1f);
object.rotateY(0.2f);

buffer.clear(java.awt.Color.BLACK);

world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
canvas.repaint();
    }

    private void initWorld()
    {
world = new World();
world.setAmbientLight(10, 10, 10);
world.addLight(new SimpleVector(0, 0, -150), 40, 40, 40);

world.getCamera().setPosition(0, 0, -10);
world.getCamera().lookAt(new SimpleVector(0, 0, 0));

object = Primitives.getCube(2);
object.setAdditionalColor(Color.RED);
object.build();
object.setCenter(new SimpleVector(0, 0, 0));
world.addObject(object);
    }

    private void initCanvas()
    {
buffer = new FrameBuffer(400, 400, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);

canvas = buffer.enableGLCanvasRenderer();
add(canvas, BorderLayout.CENTER);
    }

    private void initComponents()
    {
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel buttonBox = new JPanel();
buttonBox.setLayout(new BoxLayout(buttonBox, BoxLayout.LINE_AXIS));
getContentPane().add(buttonBox, BorderLayout.PAGE_END);
JButton button = new JButton("Start");
buttonBox.add(button);
button.addActionListener(new ActionListener()
{
    @Override
    public void actionPerformed(ActionEvent arg0)
    {
timer.start();
    }
});
button = new JButton("Exit");
buttonBox.add(button);
button.addActionListener(new ActionListener()
{
    @Override
    public void actionPerformed(ActionEvent arg0)
    {
timer.stop();
device.setFullScreenWindow(null);
setVisible(false);
dispose();
    }
});
    }

    private void initResolution()
    {
setUndecorated(true);
setResizable(false);

device = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
device.setFullScreenWindow(this);
DisplayMode mode = device.getDisplayMode();
setSize(mode.getWidth(), mode.getHeight());

    }
}


If I comment out the device.setFullScreenWindow(this) line it works.
Does anyone know what I have to change to make it work in full screen mode?
I use: JPCT 1.18 and java 1.6

Thanks,
Wojtek

EgonOlsen

I'm not sure...i've never used a GLCanvas in a fullscreen window myself. Maybe you want to try the jogl-option instead to see, if this works better. More information about this can be found here: http://www.jpct.net/wiki/index.php/The_different_renderers#JOGL_support. It requires Jogl 1.1, not the 2.0beta stuff.

Wojtek

Quote from: EgonOlsen on October 27, 2009, 04:29:01 PM
I'm not sure...i've never used a GLCanvas in a fullscreen window myself. Maybe you want to try the jogl-option instead to see, if this works better. More information about this can be found here: http://www.jpct.net/wiki/index.php/The_different_renderers#JOGL_support. It requires Jogl 1.1, not the 2.0beta stuff.

Unfortunately it does not seem to work as well :(

EgonOlsen

Does the rest of the GUI actually work fine in fullscreen mode?

Wojtek

Yes, the rest of GUI is working correctly in FullScreen mode. I am not getting any exceptions or warnings...
In fact even mouse events are working for GLCanvas, so canvas is present in place where it should be. The only thing is that there is nothing displayed in it.

The example code that I put in first post recreates the display problem.

Thanks,
Wojtek

EgonOlsen

#5
Works fine on my machine (Windows Vista, Java6, ATI Radeon HD4870). After pressing the "Start"-button, a rotating cube appears. Seems to be a problem on your machine with the GL/fullscreen combination. Fullscreen mode in Java2D was never really reliable. Maybe trying without the D3D-2d-Pipeline helps: Just start your app with -Dsun.java2d.d3d=false.

Wojtek

Great, it works with that parameter :) Thank you for help.

By the way, what that parameter means?

Thanks,
Wojtek

EgonOlsen

With Java6u10, Sun introduced a new 2d pipeline based on Direct3D instead of the usual 2D acceleration available in Windows. This pipeline is the new default (sad, but true...). Here's a little rant about it: http://www.jpct.net/forum2/index.php/topic,1004.0.html.

And while you are there, why not vote for this bug: http://bugs.sun.com/view_bug.do?bug_id=6652116... ;D

Wojtek


redfood

Quote from: EgonOlsen on October 28, 2009, 04:39:02 PM
. Maybe trying without the D3D-2d-Pipeline helps: Just start your app with -Dsun.java2d.d3d=false.

I created an account just to thank you for this old post.  You saved me hours of banging my head against the wall trying to get old code to work again.