Hi,
This code is orignally from Pro Java 6 3D Game Development, I removed parts that I didn’t want and added some other bits just to test things out.
The program creates a frame with a canvas inside and then displays the FPS in the botton left hand corner. The FPS is calculated very simply by just seeing how many frames are rendered in 1 second, and then displaying the number of frames.
I thought that the FPS should be high but something is limiting it so that it only renders at my monitors refresh rate (tested at 60 and 75). Does anyone have any ideas why this is, and how I can use active rendering in JOGL that runs as fast as possible? This is really bugging me 
//CubeGL.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.media.opengl.*;
public class CubeGL extends JFrame implements WindowListener
{
private static final int PWIDTH = 512; // size of panel
private static final int PHEIGHT = 512;
private CubeCanvasGL canvas;
public CubeGL()
{
super("GAMEEEEE (Active)");
Container c = getContentPane();
c.setLayout( new BorderLayout() );
c.add( makeRenderPanel(), BorderLayout.CENTER);
addWindowListener(this);
pack();
setVisible(true);
} // end of CubeGL()
private JPanel makeRenderPanel()
// construct the canvas, inside a JPanel
{
JPanel renderPane = new JPanel();
renderPane.setLayout( new BorderLayout() );
renderPane.setOpaque(false);
renderPane.setPreferredSize( new Dimension(PWIDTH, PHEIGHT));
canvas = makeCanvas();
renderPane.add(canvas, BorderLayout.CENTER);
canvas.setFocusable(true);
canvas.requestFocus(); // the canvas now has focus, so receives key events
// detect window resizes, and reshape the canvas accordingly
renderPane.addComponentListener( new ComponentAdapter() {
public void componentResized(ComponentEvent evt)
{ Dimension d = evt.getComponent().getSize();
// System.out.println("New size: " + d);
canvas.reshape(d.width, d.height);
} // end of componentResized()
});
return renderPane;
} // end of makeRenderPanel()
private CubeCanvasGL makeCanvas()
{
// get a configuration suitable for an AWT Canvas (for CubeCanvasGL)
GLCapabilities caps = new GLCapabilities();
AWTGraphicsDevice dev = new AWTGraphicsDevice(null);
AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration)
GLDrawableFactory.getFactory().chooseGraphicsConfiguration(caps, null, dev);
GraphicsConfiguration config = null;
if (awtConfig != null)
config = awtConfig.getGraphicsConfiguration();
return new CubeCanvasGL(this, PWIDTH, PHEIGHT, config, caps);
} // end of makeCanvas()
// ----------------- window listener methods -------------
public void windowActivated(WindowEvent e)
{ canvas.resumeGame(); }
public void windowDeactivated(WindowEvent e)
{ canvas.pauseGame(); }
public void windowDeiconified(WindowEvent e)
{ canvas.resumeGame(); }
public void windowIconified(WindowEvent e)
{ canvas.pauseGame(); }
public void windowClosing(WindowEvent e)
{ canvas.stopGame(); }
public void windowClosed(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
// -----------------------------------------
public static void main(String[] args)
{
new CubeGL(); // ms --> nanosecs
} // end of main()
} // end of CubeGL class