Skip to main content

Action-driven pure immediate mode in Swing: How to do this?

No replies
bartj
Offline
Joined: 2005-08-23

Hi all,

I'm trying to write a pure immediate Java3D application. The scene changes only in response to user input so I would like to avoid running a renderer thread. My Canvas3D is in a JPanel.

Rendering should also occur after a resize, or when (part of) the canvas becomes visible after having been obscured by other windows. To achieve this, I tried the following:

canvas = new Canvas3D(config) {
public void paint(Graphics g) {
super.paint(g);
getGraphicsContext3D().clear();
swap();
}
};

Strangely, if I successively enlarge the window, the scene appears only half the time. The other half of the time, the underlying JPanel shows through.

The following does work, but it flickers.

canvas = new Canvas3D(config) {
public void paint(Graphics g) {
super.paint(g);
getGraphicsContext3D().clear();
swap();
getGraphicsContext3D().clear();
swap();
}
};

One aspect of this is that it seems that the frame, when painting itself, does not clip its heavyweight children (in particular, the Canvas3D). Shouldn't it do so? Could this be the cause of my problem?