Still an't see the result of a blit on the screen, but thank you for the explanation

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.

do you have some code available that you care to post?

if the SDL_Surfaces that you are blitting with actually exist then i
don’t know what is wrong.

if you are following this general system:

set_up_screen();

set_up_backgroud();

while( not_end ){
Blit_background_to_screen();
blit_tiles_to_screen();
SDL_Flip( screen );
check_for_quit_action();
}

then it should work

make sure that the tiles( whatever they are ) exist and are not black
or colourkey transparent,

from the other reply do you recreate the backgroud every frame?(
shouldn’t cause problem you are having, but still a bit strange )

try a simpler and simpler approach until you get it working, and build
from there

e,g.

int main(…)
{
SDL_Init( SDL_INIT_VIDEO);
//check for failure
SDL_Surface * screen = SDL_SetVideoMde( … + SDL_DOUBLEBUF );
SDL_Surface * pic = SDL_LoadBMP( “some_bright_bitmap”);
//test all surfaces for NULL
int done = 0
while( !done ){

SDL_BlitSurface( pic , NULL, screen , NULL );

SDL_Event event;
while( SDL_PollEvent( &event ) ){
if( event.type == SDL_QUIT )
done = 1;
}

SDL_Flip( screen );
}
}
then build up the background, then add tiles etc, etc

void DrawScene()
{
ScreenLock(screen);
FullBlit(background, screen, 0, 0);
^^^
|
where is this function, i can’t find it in the api i have or in the wiki.
is it pseudo code or did you actually define it. if so, does it work?> ScreenUnlock(screen);
SDL_Flip(screen);
SDL_UpdateRect(screen, 0, 0, 320, 200);
}