Sign in to follow this  
SelethD

clear a SDL screen

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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));
}

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 buffer
SDL_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 buffer
SDL_Flip(screen);

// END MAIN LOOP


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this