How can I render a scene in fullscreen?
I can set the size like:
frame.setSize(640, 480);
But how to make it fullscreen?
How can I render a scene in fullscreen?
I can set the size like:
frame.setSize(640, 480);
But how to make it fullscreen?
See the jogl-demos source code under src/demos/fullscreen for a few examples of making JOGL applications go fullscreen.
Hey maybe i have something selfmade for you!
Sorry for the german comments, i made this in my language.
Its a GLEventlistener subclass to use it directly with a JFrame and
to control it easily.
May it is something for you!
package soul2d.engine.graphic;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import soul2d.GameEngine;
import soul2d.engine.BGraphic;
import net.java.games.jogl.GL;
import net.java.games.jogl.GLCanvas;
import net.java.games.jogl.GLCapabilities;
import net.java.games.jogl.GLDrawable;
import net.java.games.jogl.GLDrawableFactory;
import net.java.games.jogl.GLU;
/**
* Erstellt eine Jogl-Oberfläche innerhalb eines Fullscreens
*
* @author Soulfly alias Ingo Müller
*/
public class FullscreenMode extends GLEventListener
{
/**
* Grafikkarte die benutzt wird
*/
private GraphicsDevice device;
/**
* JOGL Zeichenbereich
*/
private volatile GLCanvas glcanvas;
/**
* Höhe der Anzeigefläche
*/
private int height;
/**
* Engine Parent
*/
private GameEngine parent;
/**
* Breite der Anzeigefläche
*/
private int width;
/**
* Konstruktor
*
* @param WIDTH
* Breite
* @param HEIGHT
* Höhe
*/
public FullscreenMode(int WIDTH, int HEIGHT)
{
GraphicsEnvironment enviroment = GraphicsEnvironment.getLocalGraphicsEnvironment();
device = enviroment.getDefaultScreenDevice();
width = WIDTH;
height = HEIGHT;
}
/*
* (non-Javadoc)
*
* @see net.java.games.jogl.GLEventListener#display(net.java.games.jogl.GLDrawable)
*/
public void display(GLDrawable gld)
{
GL gl = gld.getGL();
GLU glu = gld.getGLU();
parent.display(gl, glu);
}
/*
* (non-Javadoc)
*
* @see net.java.games.jogl.GLEventListener#displayChanged(net.java.games.jogl.GLDrawable,
* boolean, boolean)
*/
public void displayChanged(GLDrawable arg0, boolean arg1, boolean arg2)
{
parent.displayChanged(arg0, arg1, arg2);
}
/**
* Gibt die momentanen Bildschirmeinstellungen zurück
*
* @return Aktueller DisplayMode
*/
public DisplayMode getCurrentDisplayMode()
{
return device.getDisplayMode();
}
/**
* Gibt aktuellen Frame aus
*
* @return Aktueller JFrame
*/
public JFrame getFrame()
{
return (JFrame) device.getFullScreenWindow();
}
/**
* Gibt die JOGL-Oberfläche zurück
*
* @return Aktueller GLCanvas
*/
public GLCanvas getGLCanvas()
{
return glcanvas;
}
/**
* Gibt die Höhe zurück
*
* @return Höhe
*/
public int getHeight()
{
return glcanvas.getHeight();
}
/**
* Gibt die Breite zurück
*
* @return Breite
*/
public int getWidth()
{
return glcanvas.getWidth();
}
/**
* initialisiert die Anzeige
*
* @param ge
* Aktuelle GameEngine
*/
public void init(GameEngine ge)
{
parent = ge;
setFullscreen();
}
/*
* (non-Javadoc)
*
* @see net.java.games.jogl.GLEventListener#init(net.java.games.jogl.GLDrawable)
*/
public void init(GLDrawable gld)
{
GL gl = gld.getGL();
GLU glu = gld.getGLU();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(0.0, (double) width, 0.0, (double) height);
//Aktiviert die Beachtung von Alphawerten
gl.glEnable(GL.GL_ALPHA_TEST);
gl.glAlphaFunc(GL.GL_GREATER, 0.0f);
parent.init(gl, glu);
}
/**
* Das Vollbild wird verlassen und der Bildschirm wird wieder hergestellt.
*/
public void removeFullscreen()
{
Window fenster = getFrame();
if (fenster != null)
fenster.dispose();
device.setFullScreenWindow(null);
}
/*
* (non-Javadoc)
*
* @see net.java.games.jogl.GLEventListener#reshape(net.java.games.jogl.GLDrawable,
* int, int, int, int)
*/
public void reshape(GLDrawable arg0, int arg1, int arg2, int arg3, int arg4)
{
parent.reshape(arg0, arg1, arg2, arg3, arg4);
}
/**
* Setzt die Bildschirmeinstellung
*
* @param width
* Auflösungbreite
* @param height
* Auflösungshöhe
* @param color
* Farbtiefe
* @param freq
* Bildschirmfrequenz
*/
public void setDisplayMode(int width, int height, int color, int freq)
{
if (width != 0 && height != 0 && color != 0 && freq != 0 && device.isDisplayChangeSupported())
{
try
{
device.setDisplayMode(new DisplayMode(width, height, color, freq));
}
catch (IllegalArgumentException ex)
{
}
getFrame().setSize(width, height);
}
}
/**
* Erstellt den Fullscreen
*/
public void setFullscreen()
{
final JFrame frame = new JFrame();
frame.setSize(width, height);
frame.setUndecorated(true);
frame.setIgnoreRepaint(true);
frame.setResizable(false);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
GameEngine.getFPSAnimator().stop();
System.exit(0);
}
});
glcanvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
glcanvas.addGLEventListener(this);
frame.add(glcanvas);
// den JFrame als Vollbild setzen
device.setFullScreenWindow(frame);
setDisplayMode(width, height, 32, 60);
glcanvas.requestFocusInWindow();
}
}
Great code soulfly32! My only concern is that awt is faster than swing, and thus I would use a frame, not a jframe.
-peace
What about using a JFrame with a GLCanvas inside? Seems to work…
When only using a single Jframe with GLCanvas there are no performance problems AFAIK.
Thank you for comment.