Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (788)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (860)
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 10058 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  

hadezbladez (2127 views)
2018-11-16 13:46:03

hadezbladez (808 views)
2018-11-16 13:41:33

hadezbladez (2099 views)
2018-11-16 13:35:35

hadezbladez (416 views)
2018-11-16 13:32:03

EgonOlsen (3451 views)
2018-06-10 19:43:48

EgonOlsen (3680 views)
2018-06-10 19:43:44

EgonOlsen (2272 views)
2018-06-10 19:43:20

DesertCoockie (3002 views)
2018-05-13 18:23:11

nelsongames (3072 views)
2018-04-24 18:15:36

nelsongames (3852 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20 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!