Active rendering: configure TopLevel or all components?

Hi all,

a lot of time has passed since I was into java game development, but now I need some update
(of the last years ;D).
For the basics in active rendering and fullscreen/ windowed mode I looked into Kevs example of
Space Invaders. What confuses me is the way of using the graphic components. In his example
is basically this:


public class Game extends Canvas 
....
public Game() 
{
		// create a frame to contain our game
		JFrame container = new JFrame("Space Invaders 101");
		
		// get hold the content of the frame and set up the resolution of the game
		JPanel panel = (JPanel) container.getContentPane();
		panel.setPreferredSize(new Dimension(800,600));
		panel.setLayout(null);
		
		// setup our canvas size and put it into the content of the frame
		setBounds(0,0,800,600);
		panel.add(this);
		
		// Tell AWT not to bother repainting our canvas since we're
		// going to do that our self in accelerated mode
		setIgnoreRepaint(true);
		
                // create the buffering strategy which will allow AWT
		// to manage our accelerated graphics
		createBufferStrategy(2);
		strategy = getBufferStrategy();
}

My main problem is to understand which component specifies the graphical configuration (rendering
method, acceleration etc). In the example the configuration is made for the canvas, not for the top
level Container. Is this enough to activate direct rendering? Should’nt the Jframe setIgnoreRepaint(true)?
Could something happen like an embedded component is configured for active rendering and creates
the suitable Bufferstrategy but the enclosing Component (in this case the JFrame) is running in passive
rendering mode? That would mess up both strategies …

The example is OK. The BufferStrategy is created for the heavyweight component, in this case - Canvas. I’d also disable Swing’s double buffering so that it doesn’t maintain its own back buffer.

I don’t know why would one use JFrame in this case at all actually - why pull swing classes if all you do is slap AWT’s canvas on top of it. I’d just use Frame.

Dmitri

createBufferStrategy(2);

notice that this may only work in a full-screen exclusive mode. otherwise createBufferStrategy(1); is needed (which disables double buffer).