Upcoming Events
Workshop on Network and Systems Support for Games (NetGames 2009)
11/23 - 11/25 @ Paris, France

LOOP 2009
11/26 - 11/29  

EVA 2009
12/4 - 12/5 @ Buenos Aires, Argentina

ICIDS 2009 Interactive Storytelling
12/9 - 12/11 @ Guimarães, Portugal

More events...


Quick Stats
6464 people currently visiting GDNet.
2341 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!



Link to us

Link to us

  Intel sponsors gamedev.net search:   

Java Games: Active Rendering


Active rendering is a style of programming that allows Java code to handle all of the rendering in a simple while loop. This approach resembles traditional game programming, allowing more time to be spent developing a game and less time spent worrying about which paint method to override.

What is Active Rendering?

There are two different kinds of rendering: active and passive. Anyone who has ever written a swing application has experienced passive rendering. The drawing code is placed in a paint method and the code is called in response to repaint requests. These can come from the code itself, but may also come from the operating system in response to events such as resizing a window or clicking on a component.

Figure 1 shows an example of Passive rendering. There is nothing wrong with letting java handle painting for you, but it is not the only way to develop an application.

Figure 1 - Passive Rendering

Active rendering (Figure 2) is just the opposite. Instead of letting someone else decide when to paint, the program constantly repaints the screen in a very tight while loop. While this sort of behavior is not recommended for regular applications, it is exactly the kind of control needed to make computer games.

Figure 2 - Active Rendering

Why use Active Rendering?

The first time I tried to write a computer game in Java, I wanted to write the following:
public class Game {

    public static void main(String [] args) {
        setup();
        while( isRunning() ) {
            gameLoop();
        }
        shutDown();
        System.exit(0);
    }
}
As I started looking at the various tutorials on the web, they all made Applets and put custom painting code in the paint method. By using active rendering we can write all the code in main and have fun playing around with 2D graphics without bothering with opaque settings, rendering threads, and the differences between paint, repaint, update, and paintComponent.



Active Rendering in a Window

Contents
  Active Rendering Overview
  Active Rendering in a Window
  Full Screen Active Rendering

  Printable version
  Discuss this article