Clearing the Screen

Hullo

i want to develope a game, and because many open souce games use the sdl graphic
libary i thougth i should do soo too. Anyway, i am still learning the basics,
and came to a problem.

So my Question:

How can i clear the Screen? or the App window?

Because i found no function or something similar ,i tried the following

unsigned long ul_pixelsize;
SDL_LockSurface(screen);
ul_pixelsize=screen->format->BytesPerPixelscreen->wscreen->h;
memset(&(screen->pixels),0,ul_pixelsize);
SDL_UnlockSurface(screen);

but this doesnt seem to work, it eaven seems to me its f****up the whole
displaying routine of Win2k, although i am running the programm as an normal
user. (I think i might have misscalculated the actuale size of the pixel array)

So, is there any “nice” way to clear the screen?

thx

Use

SDL_FillRect(screen,0,0);

Which blacks the screen. Then you can draw on top of it.

-TomT64

none yet wrote:>Hullo

i want to develope a game, and because many open souce games use the sdl graphic
libary i thougth i should do soo too. Anyway, i am still learning the basics,
and came to a problem.

So my Question:

How can i clear the Screen? or the App window?

Because i found no function or something similar ,i tried the following

unsigned long ul_pixelsize;
SDL_LockSurface(screen);
ul_pixelsize=screen->format->BytesPerPixelscreen->wscreen->h;
memset(&(screen->pixels),0,ul_pixelsize);
SDL_UnlockSurface(screen);

but this doesnt seem to work, it eaven seems to me its f****up the whole
displaying routine of Win2k, although i am running the programm as an normal
user. (I think i might have misscalculated the actuale size of the pixel array)

So, is there any “nice” way to clear the screen?

thx


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

none yet wrote:

Hullo
So my Question:

How can i clear the Screen? or the App window?
<…>
So, is there any “nice” way to clear the screen?
very easy :
SDL_FillRect( screen, NULL, SDL_MapRGB(screen->format, 0,0,0) );
(don’t forget to call SDL_Blit if you use SDL_DOUBLEBUF)

Thx for the Fast Answers

but it doest to work.

I am drawing a bmp picture with the showBMP function in the sdl introductin
document, and than i move this picture(I draw it at another position).
But the old one is still there, althoug i did a SDL_FillRect().
How can this be?

Can you show some code?

-TomT64

none yet wrote:>Thx for the Fast Answers

but it doest to work.

I am drawing a bmp picture with the showBMP function in the sdl introductin
document, and than i move this picture(I draw it at another position).
But the old one is still there, althoug i did a SDL_FillRect().
How can this be?


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

How did you update the surface? If you called SDL_UpdateRect(), be sure
to ALSO include the FillRect()'d area that you ‘cleared’. :slight_smile:

(This JUST came up a few days ago, didn’t it?)

-bill!
bill at newbreedsoftware.com Man, some trip this turned out to be.
http://www.newbreedsoftware.com/ All we caught is a tire, a boot,
New Breed Software a tin can and this book of cliches.On Sun, Sep 05, 2004 at 11:12:51PM +0000, none yet wrote:

Thx for the Fast Answers

but it doest to work.

I am drawing a bmp picture with the showBMP function in the sdl introductin
document, and than i move this picture(I draw it at another position).
But the old one is still there, althoug i did a SDL_FillRect().
How can this be?

I do the following:

loading the bmp file#
(*pC_image)=SDL_LoadBMP(file);
if(!(*pC_image))
return 1;
return 0;

displaying the bmp:

SDL_Rect dest;

/* Blit onto the screen surface.
   The surfaces should not be locked at this point.
 */
dest.x = pst_bmp->ui_x;
dest.y = pst_bmp->ui_y;
dest.w = pst_bmp->pC_bmp->w;
dest.h = pst_bmp->pC_bmp->h;
if(SDL_BlitSurface(pst_bmp->pC_bmp, NULL, screen, &dest)) return 1;

/* Update the changed portion of the screen */
SDL_UpdateRects(screen, 1, &dest);
return 0;

clearing the screen:

SDL_LockSurface(screen);
SDL_FillRect( screen, NULL, SDL_MapRGB(screen->format, 0,0,0) );
SDL_UnlockSurface(screen);
return 0;

calling the display function again

none yet wrote:

I do the following:

Can we see the entire code please ?
thanks

Murlock