Good practise for graphic rendering

Hello everyone,

Having encountered some problems to get high quality graphic rendering for my Java app (but the game isn’t over), I have explored many Java web resources, mainly posts in this forum. Here are the important points and advices I have grabbed, hoping they will be used, proofread or completed by you:

1- work with Java 1.5 (or wait for it for mac users!)
2- use a high resolution timer (such as System.nanoTime() in 1.5 or GAGETimer for windows)
3- prefer designing in one thread
4- use active rendering with a BufferStrategy (and setIgnoreRepaint(true))
5- “let the system breath” with a Thread.yield() in your game loop

For FPS concerns :
6- avoid the fillRect(), drawString() etc. methods of Graphics2D objects, drawing images is faster
7- create accelerated images with GraphicsConfiguration.createCompatibleImage()
8- avoid translucent images if possible
9- run in full screen mode
10- stabilize your FPS rate by sleeping the right amount of time between two loops

For sight concerns :
11- don’t stay close to your screen when you’re game is displaying dozens of ugly flickering sprites.

What I am still wondering are the effects of the JFrame/Canvas choice, the RenderingHints settings, the synchronized methods use (and other time expensive operations such as casting) on the FPS rate. And I am not sure of having set everything right as I run my game at 100 FPS (it’s enough I know) when other people here obtain more than 500 FPS…

Guillaume Smoothed Denis

Hehe. These 100 fps are fullscreen huh? :slight_smile:

Well, vsync is enabled then. That means you can only get <=hz fps. Most likely your monitor runs at 100hz in that resolution and you maxed that out.

So… for benchmarking use windowed mode. Fullscreen is a tad faster, but you won’t see that effect if it’s maxed out anyways.

i believe using a JFrame instead of a canvas for rendering with bufferStrategy would be more efficient, as it is an all in one component, rather than two, but i also think the diference is minimal… not sure though

My monitor runs at 60 Hz, so I don’t think vsync is enabled. How to ?

60hz is a little low… unless it’s a laptop screen.

in any case, if it is in v-sync, you will get a maximum of 60fps in full screen with BufferStrategy. v-sync is only available in full screen mode.

[quote]i believe using a JFrame instead of a canvas for rendering with bufferStrategy would be more efficient, as it is an all in one component, rather than two, but i also think the diference is minimal… not sure though
[/quote]
Why a JFrame? A frame is enough.
A JFrame extends a frame.

Oh. I thought plain AWT Frames did not support BufferStrategy, but they do. you could even just use a Window on its own without a Canvas it seems.

-JuddMan