Active rendering and GUI components

Hello all,
I’ve read this tutorial ( http://docs.oracle.com/javase/tutorial/extra/fullscreen/rendering.html ) about active rendering, but I don’t know if any GUI components can still be used in conjunction with active rendering. Can active rendering be only used in full-screen mode or also on a single component in a GUI application window?

As far as I understand, GUI components can’t be used when doing active rendering, because active rendering means bypassing the OS’s GUI control and give it completely to the application.

Please correct me if my understanding is wrong :slight_smile:

This can be used on single components, but you really should not draw this way.
Active rendering just repaints the component multiple times a second.
So all events and functions would still work on this and other coponents.

However you really should NOT use this method to draw a game.
Use something with hardware accelleration, so you dont stress (and eventually max out) your cpu usage.
When you hit this limit (what happens really fast) you need to convert your code to other rendering methods anyways.
OPENGL is the way to go, using a library like LWJGL or LIBGDX will make it easyer.

LibGDX’s GUI uses active rendering, and is built on OpenGL, so it’s very fast. And it’s generally much easier for game- and mobile-related purposes than Swing (i.e. theming, touch input, etc).

Thanks. I have read here http://docs.oracle.com/javase/1.5.0/docs/guide/2d/flags.html that the standard Java 2D API is also hardware accelerated, hence I don’t understand why I a 3rd party library is more efficient.

Because Java2D decides for its own when to do this, most of the time it uses software accelleration only.
Java2D only works for really light stuff, try rendering a big texture (1024 x 1024), it will take a lot of time in java2d.
Imagine needing to draw 20 of these images, Java2D will maybe get at 5fps, while OpenGL still draws at 1000+ fps.

Java2D is just not trustworthy when it comes to hardware accelleration.

Thank you. So you would generally recommend to get accustomed to OpenGL, even when doing 2D games?

The docu here http://docs.oracle.com/javase/1.5.0/docs/guide/2d/new_features.html#ogl says: “J2SE 5.0 includes a new OpenGL-based pipeline for Java 2D. This pipeline provides hardware acceleration for simple rendering operations (text, images, lines, and filled primitives) as well as those that involve complex transforms, paints, composites, and clips. This pipeline is available on all platforms (Solaris, Linux, and Microsoft Windows) and is currently disabled by default. To silently enable the OpenGL-based pipeline, specify the following system property on the command line:
-Dsun.java2d.opengl=true”.

Well, that sounds like OpenGl could be explicitly enabled.

Indeed, its possible to use Java2D with the opengl pipeline, but you wil still hit some limit soon enough.
Most functions just dont translate to opengl very well.
I also tryd to use Java2D as long as possible(also using this pipeline), you will really hit a wall eventually as your game expands.

If you have an really simple game with limited particles (particle engines will be really slow) Java2d will suffice.
But why stay at such an limited platform, as you get more experienced and the game grows, you will eventually use opengl anyways.
Pure opengl also has advantages like Shaders and Vertex buffers (or displaylists) wich will open a new world for you.

Also as sidenote, Opengl is not for 3D games, its for rendering anything on screen.
The librarys also provide acces to the other accellerated outputs (OpenAL for sound), (OpenCL for hardware calculations), and others

As library LibGDX is really recommended, it makes the switch from Java2D not very hard.

Aside from the performance; it also makes more sense to use a 3rd party game-centric library to reduce the time you spend writing boilerplate, and increase your overall productivity. For example; fonts, GUI, tiled map loading, asset loading management, and so forth. And, best of all, LibGDX will distribute to more platforms than Java2D (i.e. mobile, WebGL).

I think writing your own library the first time is important for knowing whats happening under the hood.
But besides that or extreme performance tuning, there is no reason for not using an library.

Thanks for your helpful answers :slight_smile: I learned a lot about OpenGL and computer graphics theory (midpoint algorithm, render pipeline, projections, matrix transformations and blabla…) some years ago, but I can’t work creatively with it. However, as far as I know OpenGL is nearly the same on all platforms, hence it’s easy to write portable games which wouldn’t be possible with an API like Java2D.