Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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 2350 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."

http://docs.oracle.com/javase/tutorial/extra/fullscreen/rendering.html

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)

"It's after the end of the world! Don't you know that yet?"
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.

"It's after the end of the world! Don't you know that yet?"
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (38 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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
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!