How do I know when to update the screen?

Hi!

I have been trying to code some small snippets with SDL, but before I
start something big I have a question I hoep somebody can help me
with. It’s probably pretty stupid so if it’s in the manual, don’t hesitate
to tell me to read it as long as you point me in the right direction.

My problem is that I want to make sure that when I update the screen,
using SDL_UpdateRects() I don’t update it while it’s being drawn.

In the manual page for SDL_UpdateRects() it says:

“Note: It is adviced to call this function only once per frame, since
each call has some processing overhead.”

So how do I know that a new frame has been drawn? There doesn’t seems to
be any event for new-frame in the event system and I’m not sure how I’d
use the timers to accomplish it.

So, how do I sync my update to the new-frame interrupt, if there is sucha
beast?

Any help appreciated.

/andreas

=================== Emacs =====================
mail: @Andreas_Davour
or try: Koraq at yahoo.com
groove out: http://www.update.uu.se/~ante/
====== The choice of a GNU generation! ========

I have been trying to code some small snippets with SDL, but before I
start something big I have a question I hoep somebody can help me
with. It’s probably pretty stupid so if it’s in the manual, don’t hesitate
to tell me to read it as long as you point me in the right direction.

My problem is that I want to make sure that when I update the screen,
using SDL_UpdateRects() I don’t update it while it’s being drawn.

You can use SDL_GetTicks() to count the frames, but usually I’d just suggest
to use double buffering and SDL_Flip() once per game loop.

HTH, KaiOn Monday 12 August 2002 16:12, Andreas Davour wrote:


Kai Blin Linux system administrator Tel: Ring-86592
Allgemeine Chirurgie Universitaetsklinikum Tuebingen

“I know the answer! The answer lies within the heart of all mankind!
The answer is twelve? I think I’m in the wrong building.”
– Charles Schulz

andreas wrote:

[…]

My problem is that I want to make sure that when I update the
screen,
using SDL_UpdateRects() I don’t update it while it’s being drawn.

You generally don’t have to worry about this. Use SDL_Flip() if your
hardware and software supports it (this syncs to the vertical blank of
the screen), or just use SDL_UpdateRects(). On some targets it’s
impossible to sync explicitly (for example Linux-X11, iirc).

In the manual page for SDL_UpdateRects() it says:

“Note: It is adviced to call this function only once per frame,
since
each call has some processing overhead.”

That is frame' as inframe you draw’, not as drawn by your
monitor.

[…]

So, how do I sync my update to the new-frame interrupt, if there
is sucha beast?

As another poster indicated: Use SDL_Flip() or just forget about it
and update every 1/50 second or as fast as possible or something.
Check out David Olofson’s smoothscroll demo for more ideas about
how to use OpenGL to get (surprise) smooth scrolling:
http://olofson.net/mixed.html

[…]

/andreas

–ulf