Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (686)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Converting existing Swing 2D WIP to ActiveRendering & BufferStrategy  (Read 3143 times)
0 Members and 1 Guest are viewing this topic.
Offline philfrei
« Posted 2013-10-08 07:43:41 »

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)

music and music apps:
Offline xsvenson
« Reply #1 - Posted 2013-10-08 08:02:51 »

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
Offline philfrei
« Reply #2 - Posted 2013-10-08 18:06:58 »

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.

music and music apps:
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (63 views)
2015-11-07 13:29:08

Rems19 (77 views)
2015-10-31 01:36:56

Rems19 (69 views)
2015-10-31 01:32:37

williamwoles (103 views)
2015-10-23 10:42:59

williamwoles (91 views)
2015-10-23 10:42:45

Jervac_ (105 views)
2015-10-18 23:29:12

DarkCart (131 views)
2015-10-16 00:58:11

KaiHH (114 views)
2015-10-11 14:10:14

KaiHH (153 views)
2015-10-11 13:26:18

BurntPizza (167 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!