clear a SDL screen

Started by
7 comments, last by Rob Loach 18 years ago
Is there a command to clear the sdl screen to a certain RGB color? thanks
Advertisement
SDL_FillRect(screen_surface, NULL, color)

is your friend. The color can be gained from SDL_MapRGB or SDL_MapRGBA.

For questions like this you should take a look at the SDL Doc-Wiki.

-Raven
even though it may seem easy to find things like this in the docs, its really not that way for some people.
I am one of those some people.

Thanks :)
A tip for alot of documentation: don't search for, say, "clear". Instead search for SDL_Surface and see what functions relate to it. That's what I do alot when I don't know what a function would be called.
This is how I do it:

void oth::Window::Clear(int r, int g, int b){	SDL_FillRect(SDL_GetVideoSurface(), NULL, SDL_MapRGB(SDL_GetVideoSurface()->format, r,g,b));}
Quote:Original post by ontheheap
This is how I do it:

*** Source Snippet Removed ***


If by chance that is your current code, I'd like to strongly suggest you store the SDL_Surface* for the main screen in your Window class to avoid the unnecessary overhead calls of calling the SDL_GetVideoSurface twice in one function. That or at least store the result of SDL_GetVideoSurface once in the function and use that. It seems rather minor, but little things such as that go a long way when this function is being called every frame (which there will be at least 60+ calls per second) It adds up fast [smile]
Quote:Original post by Drew_Benton
Quote:Original post by ontheheap
This is how I do it:

*** Source Snippet Removed ***


If by chance that is your current code, I'd like to strongly suggest you store the SDL_Surface* for the main screen in your Window class to avoid the unnecessary overhead calls of calling the SDL_GetVideoSurface twice in one function. That or at least store the result of SDL_GetVideoSurface once in the function and use that. It seems rather minor, but little things such as that go a long way when this function is being called every frame (which there will be at least 60+ calls per second) It adds up fast [smile]


Thanks for the tip.
Thanks for all the tips, you guys are great :)
If you're going to be filling the screen, you should do something like this:

// Initialize the screen and keep hold of it (*screen)SDL_Surface* screen = SDL_SetVideoMode( /* ... */ );// MAIN LOOP// Clear the screen bufferSDL_FillRect(screen, NULL, 255); // 255 is Blue, 0 is Black// Draw all your stuff on the screen// ... Like your little character guy and all the enemies!// Output the screen buffer onto the screen and flip the bufferSDL_Flip(screen);// END MAIN LOOP
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement