Screen won't update!

Hey,

I wrote this little peice of code that blits a sprite onto my
background, but for some reason the screen is not updated until i move
the window (or do something else that causes a refresh). Here’s the
code:

SDL_Rect dest = { 64, 64, dude->w, dude->h };
SDL_BlitSurface(dude, NULL, screen, &dest);
SDL_Event event;
bool done = false;
while (done == false)
while (SDL_PollEvent(&event))
switch (event.type) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_LEFT:
dest.x -= 64;
draw_map(screen);
SDL_BlitSurface(dude, NULL, screen, &dest);
break;
case SDLK_RIGHT:
dest.x += 64;
draw_map(screen);
SDL_BlitSurface(dude, NULL, screen, &dest);
break;
case SDLK_UP:
dest.y -= 64;
draw_map(screen);
SDL_BlitSurface(dude, NULL, screen, &dest);
break;
default:
done = false;
break;
}
break;
case SDL_QUIT:
done = true;
break;
default:
done = false;
break;
}

It seems like this should be sufficient… I don’t remember having to
update the screen on my own in the past (maybe i just have a bad
memory?)

Thanks,
Cameron Matheson_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Do you have double-buffering turned on? If so, you have to call
SDL_Flip.–

Olivier A. Dagenais - Software Architect and Developer

“Cameron Matheson” wrote in message
news:995420716.21923.8.camel at dustpuppy…

Hey,

I wrote this little peice of code that blits a sprite onto my
background, but for some reason the screen is not updated until i
move
the window (or do something else that causes a refresh). Here’s the
code:

SDL_Rect dest = { 64, 64, dude->w, dude->h };
SDL_BlitSurface(dude, NULL, screen, &dest);
SDL_Event event;
bool done = false;
while (done == false)
while (SDL_PollEvent(&event))
switch (event.type) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_LEFT:
dest.x -= 64;
draw_map(screen);
SDL_BlitSurface(dude, NULL, screen, &dest);
break;
case SDLK_RIGHT:
dest.x += 64;
draw_map(screen);
SDL_BlitSurface(dude, NULL, screen, &dest);
break;
case SDLK_UP:
dest.y -= 64;
draw_map(screen);
SDL_BlitSurface(dude, NULL, screen, &dest);
break;
default:
done = false;
break;
}
break;
case SDL_QUIT:
done = true;
break;
default:
done = false;
break;
}

It seems like this should be sufficient… I don’t remember having
to
update the screen on my own in the past (maybe i just have a bad
memory?)

Thanks,
Cameron Matheson


Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

It seems like this should be sufficient… I don’t remember having to
update the screen on my own in the past (maybe i just have a bad
memory?)

If you were not writing to a double-buffered surface, that might have been
sufficient in the past. What you need to do is call SDL_Flip() to present
everything.

-Jesse

Hey,

I wrote this little peice of code that blits a sprite onto my
background, but for some reason the screen is not updated until i move
the window (or do something else that causes a refresh). Here’s the
code:

SDL_Rect dest = { 64, 64, dude->w, dude->h };
SDL_BlitSurface(dude, NULL, screen, &dest);
SDL_Event event;
bool done = false;
while (done == false)
while (SDL_PollEvent(&event))
switch (event.type) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_LEFT:
dest.x -= 64;
draw_map(screen);

What is the function “draw_map(…)” ?

Anyway, just from a pure SDL standpoint, I’d say you need to update the
screen (either using an SDL_UpdateRect(), SDL_UpdateRects() or SDL_Flip()).

It seems like this should be sufficient… I don’t remember having to
update the screen on my own in the past (maybe i just have a bad
memory?)

Actually, I’m pretty certain that if you do not update the screen, SDL’s
behavior isn’t really defined (someone correct me if I am wrong). So perhaps
on some platforms it’ll refresh for you, but on many others it wont.On Wednesday 18 July 2001 05:58pm, Cameron Matheson wrote:


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: < http://www.geekcomix.com/snh/ >
PGP Info: < http://www.geekcomix.com/snh/contact/ >
Advogato: < http://advogato.org/person/criswell/ >

Actually, I’m pretty certain that if you do not update the screen, SDL’s
behavior isn’t really defined (someone correct me if I am wrong). So perhaps
on some platforms it’ll refresh for you, but on many others it wont.

It is defined. If the display surface has SDL_HWSURFACE set, then if
SDL_DOUBLEBUF is set you need to call SDL_Flip(), otherwise you are
writing directly to visible video memory. If the display surface
doesn’t have SDL_HWSURFACE set, then you need to call SDL_UpdateRects()
(or SDL_Flip() if you want to update the whole screen)

See ya!
-Sam Lantinga, Lead Programmer, Loki Software, Inc.

Oh, that’s right. This reminds me I had a question I think I may have asked
about this but was never answered.

If your hardware supports double-buffering, then calling SDL_Flip causes the
hardware to wait for the next vertical retrace before swapping buffers.
However, if your hardware does not support double-buffering, calling SDL_Flip
is the same as calling SDL_UpdateRect(…) on the entire video screen. (which,
of course, does not [cannot] wait for the next vertical retrace.)

Is there anyway to know before hand whether the hardware supports
double-buffering or not so you can choose dynamically the best way to update
your screen? I.e., is there some return value for SDL_GetVideoInfo (or
something else) that will tell us whether our request for double-buffering
actually gave us double-buffering?On Thursday 19 July 2001 03:52pm, Sam Lantinga wrote:

Actually, I’m pretty certain that if you do not update the screen, SDL’s
behavior isn’t really defined (someone correct me if I am wrong). So
perhaps on some platforms it’ll refresh for you, but on many others it
wont.

It is defined. If the display surface has SDL_HWSURFACE set, then if
SDL_DOUBLEBUF is set you need to call SDL_Flip(), otherwise you are
writing directly to visible video memory.


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: < http://www.geekcomix.com/snh/ >
PGP Info: < http://www.geekcomix.com/snh/contact/ >
Advogato: < http://advogato.org/person/criswell/ >

[ found a way to read my mail after all ]

However, if your hardware does not support double-buffering, calling SDL_Flip
is the same as calling SDL_UpdateRect(…) on the entire video screen. (which,
of course, does not [cannot] wait for the next vertical retrace.)

I wouldn’t count on that; as soon as there is a way to do that (and be
reasonably certain the update will complete during the time the beam
is outside the visible portion of the screen) it would be a good thing
to add. (yet another reason not to call UpdateRects/UpdateRect more
than once per frame)

Is there anyway to know before hand whether the hardware supports
double-buffering or not so you can choose dynamically the best way to update
your screen?

Not beforehand, but after you’ve set the video mode you can look at the
screen surface flags (look for SDL_HWSURFACE and SDL_DOUBLEBUF)
This can be important for selecting updating strategies