Smooth rendering?

Member
Posts: 196
Joined: 2002.04
Post: #1
Hi,
I'm using OpenGL in Cocoa. I'm wondering how I should make my Cocoa game move and render as smoothly as games like Slope Rider and Lugaru. I'm using VBL syncing but the game still seems to slow down when something starts to move. Is there something more I should do with the timer to make sure it fires consistently?

Thanks,
Iceman
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #2
For smooth video, you need to render one frame per display refresh. Period.

VBL sync (which btw, still doesn't work for me in Lugaru) just makes sure the start of your frame is displayed in sync with the start of the display refresh. You still have to produce frames quickly.

Explaining how to do this is beyond the scope of any bulletin board post. You'll have to "optimize" your "engine" to run "fast enough" on your "target hardware."
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #3
Thanks. An interesting tidbit is Lugaru runs at 15 fps on my machine and somehow it looks great. I still don't know why. Are there any good tutorials for optimizing OpenGL Games correctly for this? Or should I buy a book?

Thanks,
Iceman
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #4
Does VBL Syncing pertain to just fullscreen contexts, or should it be used in windowed contexts as well?

From http://cocoa.mamasam.com/COCOADEV/2002/12/1/51903.php:

Quote:Lacking a proper way to do it, there _is_ a hackish kludgy way, if you
are using OpenGL. Basically, you set an NSTimer to fire at 1000Hz,
much faster than you need it to, and use a double-buffered OpenGL
context set to sync to VBL. When your update method is called,
the graphics hardware will pause for you at VBL which has the effect of
slowing down the actual rate to whatever the display refresh rate is.
This is what much of the Apple sample code does. Of course, if you want
to know what that rate is (for instance, to adjust your animation
speed) you'll have to measure it empirically since there is still no API to get it programmatically.
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #5
Quote:Originally posted by MacFiend
Does VBL Syncing pertain to just fullscreen contexts, or should it be used in windowed contexts as well?

It applies to both fullscreen contexts and windows (I just tested it with my game).

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #6
Quote:Originally posted by MacFiend
Does VBL Syncing pertain to just fullscreen contexts, or should it be used in windowed contexts as well?

Both. Although in theory all Quartz window flushes are automatically VBL synced, in practice this is not true with GL content (or with any Quartz content, on 10.2.3 or 10.2.4 on ATI hardware. It was busted.)

Go download the Apple VBL sample code and run it in fullscreen and windowed mode, turning VBL on and off. The tearing with VBL off should be immediately noticable.

(my post you quoted there, btw... ;)
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #7
Quote:Originally posted by Iceman
Are there any good tutorials for optimizing OpenGL Games

Follow the standard optimizing procedure. Run your code. Profile it. See what's taking up "too much" time. Optimize that section (this may involve redesigning your engine, black voodoo, waiting for OS upgrades...) Rinse, repeat.

For example, if you are writing Quake 4, you'll be concerned with vertex throughput. If you're writing Super Mario 12, you'll be concerned with fill rate and eliminating overdraw. These are two different problems which need two different optimization strategies.

In either case, you'll want to become good friends with:
a) your compiler, general code optimization
b) Shark
c) OpenGL Profiler

Once you know what is causing you problems, come back and OSC or other knowledgeable people can help. Smile
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #8
Quote:Originally posted by Iceman
Thanks. An interesting tidbit is Lugaru runs at 15 fps on my machine and somehow it looks great.

One other thing--

if it is impossible to render one frame per display refresh, because the hardware simply can't do everything you want it to, then the best fallback for "smoothness" is to limit the frame rate to an integral divisor of the display refresh. VBL sync helps in this regard.

That means: a game running at 20 or 30 Hz on a 60 Hz display will appear "smoother" than a game running at 22 or 36 Hz on the same display, even though there are less fps. The added / skipped frames in the irregular framerate destroys the "smoothness."

See "Legend of Zelda: Ocarina of Time" for a good example.
Quote this message in a reply
w_reade
Unregistered
 
Post: #9
Quote:Originally posted by Iceman
...the game still seems to slow down when something starts to move.


Is your physics (or updating or whatever) dependent on your frame rate?
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #10
Quote:Originally posted by arekkusu
That means: a game running at 20 or 30 Hz on a 60 Hz display will appear "smoother" than a game running at 22 or 36 Hz on the same display, even though there are less fps. The added / skipped frames in the irregular framerate destroys the "smoothness."

See "Legend of Zelda: Ocarina of Time" for a good example.


I DEFY YOU AND RUN MY GAMES AT 40FPS! Wink
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
fool!
Quote this message in a reply
Member
Posts: 100
Joined: 2006.05
Post: #12
I don't know much on the subject but, aren't you supposed to run your game at the highest frame rate possible and then adjust your physics accordingly?
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #13
Quote:Originally posted by Nevada
I don't know much on the subject but, aren't you supposed to run your game at the highest frame rate possible and then adjust your physics accordingly?


Yes and No. If your monitor is refreshing at 60 HZ and your game is at 22FPS, you will get an occasional Double Frame that can look "Choppier" than a game at 20 FPS.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #14
Physics and video refresh are two totally separate areas. If you are doing time-based animation (which you probably should, if you are deploying your game across the wide variety of hardware available) then you need to worry about physics timing in addition to video timing, not instead of.

Suppose I have a neon billboard in my world, which is flickering between white and black as fast as possible. For the flicker to appear "smooth" as I intend, it needs to happen at the same rate as the display refresh. Failing that, it should happen at a common integral divisor of the display rate. Not an irregular rate. Physics don't have anything to do with this problem.
Quote this message in a reply
Moderator
Posts: 434
Joined: 2002.09
Post: #15
I think there is some ambiguity as to what Iceman meant by saying the game wasn't smooth. Possible interpretations:

1) VBL syncing (already discussed)
2) Frame rate varies a lot
3) When frame rate drops, the game objects move slower too
4) Frame rate is too low

Based on the comment about Lugaru, my guess is Iceman meant some combination of 2 & 3. Solutions might including capping the frame rate at some steady rate that each particular machine can manage, adjusting the physics with the frame rate so that objects seem to be moving at a constant speed, or performance analysis + tuning.

Iceman, can you put your finger on what specifically doesn't seem smooth about it?

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Irrlicht Gouraud/Smooth Shading merrill541 4 5,648 Feb 3, 2010 01:13 PM
Last Post: merrill541
  Smooth model surfaces imikedaman 3 2,741 Jul 12, 2006 10:34 PM
Last Post: imikedaman
  2d smooth scroll Luzander 3 3,760 Jan 9, 2006 03:42 PM
Last Post: kelvin
  Smooth plane help Iceman 7 3,447 Jul 26, 2002 11:48 AM
Last Post: Iceman