Drake Wilson <drake libcom.com> writes:
Quoth djulzz <julien.esposito gmail.com>, on 2005-05-23 04:32:12 +0000:
void DrawPlentyOfTiles(SDL_Surface *s)
{
[drawing code…]
SDL_Flip(s);
}
When applied to screen, this draws on screen, then flips it. That is
reasonable enough, but you should probably not put the flip in
DrawPlentyOfTiles if it is to operate on any surface; see below.
void DrawBackground()
{
background = SDL_CreateRGBSurface(SDL_HWSURFACE, screen->w,
screen->h,
screen->format->BitsPerPixel,
screen->format->Rmask,
screen->format->Gmask,
screen->format->Bmask,
screen->format->Amask);
DrawPlentyOfTiles(background);
}
When applied to background, this draws on background, then flips it.
However, flipping background makes no sense. Flip transfers the back
buffer of a double-buffered surface to the front buffer (possibly by
flipping them; the contents of the back buffer are subsequently
undefined). background is a software surface, and does not have a
back buffer. SDL_Flip is generally applied only to the screen after a
frame has been drawn, and only then when it is double-buffered and not
an OpenGL video mode.
void DrawScene()
{
ScreenLock(screen);
FullBlit(background, screen, 0, 0);
ScreenUnlock(screen);
SDL_Flip(screen);
SDL_UpdateRect(screen, 0, 0, 320, 200);
}
SDL_Flip updates the front buffer from the back buffer, possibly by
flipping them, and then SDL_UpdateRect updates the front buffer from
the back buffer, which is now possibly the previous front buffer. If
you are using double-buffering (as you seem to be), perform a flip;
otherwise, perform rectangle updating. Do not do both, as this will
cause problems.
---> Drake Wilson_______________________________________________
SDL mailing list
SDL libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
Thank you for your answer. So following your advice, I cancelled my SDL_Flip(s)
in my “void DrawPlentyOfTiles(SDL_Surface *s)” (because flipping background does
not make any sense, as you explained it to me). I still want to use double
buffered technique. So I kept my “screen = SDL_SetVideoMode(320, 200, 8,
SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);” declaration. Then, in the
"void DrawScene()" function, I took off the “SDL_UpdateRect(screen, 0, 0, 320,
200);”, and kept “SDL_Flip(screen);”. So I think I followed your advice, and my
program is still not working (I mean I can only see a black screen). So I’m VERY
frustrated, because I wanted to port a lot of “old atari st effects” using SDL,
and up to now, I can’t do nothing. Could somebody help me ? Thank you.