I'm having trouble figuring out how to switch over to the use of active rendering and taking advantage of BufferStrategy. Was wondering if I could use this thread to get some help as I try to do this!

As a first step, all rendering code has been put into draw(g2) methods (where g2 is a Graphics2D object), with one exception. I have a three JPanels where in each I have written a render(g2) method. Of these JPanels, only one is showing at any one time.

In the gameloop, I call the render(g2) for the JPanel that is showing, and it handles calls to all draw(g2) methods associated with that JPanel. I also left in the paintComponent(g) method in these JPanels that I was previously using, and now have these calling the render(g2) method for that JPanel.

The hope was that by doing this, I would be following the first item of advice in the tutorial that states "Don't put drawing code in the paint routine."

When I follow the second bit of advice: "setIgnoreRepaint(true)" on the JPanels, the following problem occurs: the JMenuBar that is associated with that JPanel will not repaint after minimizing and restoring.

How are components "repainted" when using active rendering? I tried including a call to paintComponents() in the render(g2) method, and also tried menuBar.paintComponents(). These would thus be called with each gameloop.

Any thoughts? Any suggestions on guidelines as to how to go through this conversion process?

Motivation: I'm currently hovering around 50% cpu on this game, would like to make it more efficient. (Pentium 4, 3.2 GHz, 3 GB Ram, dual core.) There's also a graphics glitch that is occurring which I was thinking might go away or be easier to deal with if the game were using active rendering, and some additional load I'd like to put on the graphics if possible (but not absolutely necessary).

I'm looking at the final product running as either an Applet or Application. (Hexara WIP)

Active rendering is a technique where each renderable object is redrawn to the screen at it's fullest as fast as possible. (Full redraw on every frame) This mean, that heavy computation has quite a high impact on the performance.

Passive rendering is a technique, where the framework identifies the regions where the UI has changed and redraws them. This means less rendering and more room for other computations, including calculating the regions that need updating.

Swing has been built to be a passive rendering UI framework. While it has the methods to make it active-render-like, in the core it's still a passive render framework, the inner workings are still intact and eating up Your cpu cycles and whatnot.

My suggestion is, don't do active render with Swing. It's not the right tool for it. If You need to stick to the plain java, go with Java2D (awt), even better if You use one of the opengl alternatives: Libgdx or raw lwjgl.

For Your menu problem, it might be You need to get direct access to the object and need to redraw it Yourself.

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

If I read you correctly, active rendering may actually require more cpu rather than less?

I snagged a copy of Brackeen's "Developing Games in Java". The second chapter covers active rendering and BufferStrategy. I will give that a close read and see if that makes the process clearer.

So many folks here prefer active rendering and BufferStrategy--it seems like it should be a good next step. I'm not ready to deal with Libgdx or LWJGL for various reasons that do not need to be stated here.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org