Drawing over an already blitted surface

Hi, I’m a bit of a newbie to SDL and have
simple question to ask, I have a game that uses
a main function to run, RunGame() which draws a
background right at the start, using the folowing code;

SDL_Rect dst;
dst.x = 0;
dst.y = 0;
dst.w = background->w;
dst.h = backgroung->h;
SDL_BlitSurface (background, NULL, screen, &dst);

when the game finishes the next function is an Intro’
screen intro(); so I want to have a dfferent background drawn to
SDL_Surface *screen. I have achieved this by using the code
above to simply draw a different background to screen.

What I would like to know is how to completely remove the original
background before I draw a new one to the SDL_surfae *screen, at the
moment it seems as if I’m forever blitting a new background on top
of the old on without first removing it, or does this not matter.

Thanks
Damian B

[…]

What I would like to know is how to completely remove the original
background before I draw a new one to the SDL_surfae *screen, at the
moment it seems as if I’m forever blitting a new background on top
of the old on without first removing it, or does this not matter.

It doesn’t matter as long as the background images you’re blitting from are
opaque. (That is, not partially transparent or translucent.) Actually,
clearing the background first would just be a waste of time.

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Tuesday 20 March 2001 13:48, Damian L Brasher wrote:

It doesn’t really matter. Truthfully for whole frame redraws (such as new
backgrounds) the way you are doing it is one of the most straightforward and
simple ways to handle it. I mean, once you wipe the old background with a new
one, it’s not like the old background stays on the surface just under the new
one.

But if you /really/ do want to wipe the old background, use SDL_FillRect(…) [
http://sdldoc.csn.ul.ie/sdlfillrect.html ], to fill the entire screen with a
solid color (eg, black). Eg.:

SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0))

where SDL_MapRGB(screen->format…) ensures that the black you use is the same
as the screen format’s black.On Tue, 20 Mar 2001, you wrote:

Hi, I’m a bit of a newbie to SDL and have
simple question to ask, I have a game that uses
a main function to run, RunGame() which draws a
background right at the start, using the folowing code;

SDL_Rect dst;
dst.x = 0;
dst.y = 0;
dst.w = background->w;
dst.h = backgroung->h;
SDL_BlitSurface (background, NULL, screen, &dst);

when the game finishes the next function is an Intro’
screen intro(); so I want to have a dfferent background drawn to
SDL_Surface *screen. I have achieved this by using the code
above to simply draw a different background to screen.

What I would like to know is how to completely remove the original
background before I draw a new one to the SDL_surfae *screen, at the
moment it seems as if I’m forever blitting a new background on top
of the old on without first removing it, or does this not matter.


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: < http://www.geekcomix.com/snh/ >
PGP Info: < http://www.geekcomix.com/snh/contact/ >
Advogato: < http://advogato.org/person/criswell/ >

Yes. Typically in a game you use double buffering, draw everything you need
and blit it over to the main screen like 30 frames per second (or more).
Therefore you don’t have to worry about rewriting the old screen.

But any way you do it, the memory area used by each surface is constant to
that surface, so when you draw something to the screen its not like it
consumes any less or more memory…its like rewriting over the same array.
Of course each new surface you might create will takes up more memory, and
that can be freed by using SDL_FreeSurface

Matt> Hi, I’m a bit of a newbie to SDL and have

simple question to ask, I have a game that uses
a main function to run, RunGame() which draws a
background right at the start, using the folowing code;

SDL_Rect dst;
dst.x = 0;
dst.y = 0;
dst.w = background->w;
dst.h = backgroung->h;
SDL_BlitSurface (background, NULL, screen, &dst);

when the game finishes the next function is an Intro’
screen intro(); so I want to have a dfferent background drawn to
SDL_Surface *screen. I have achieved this by using the code
above to simply draw a different background to screen.

What I would like to know is how to completely remove the original
background before I draw a new one to the SDL_surfae *screen, at the
moment it seems as if I’m forever blitting a new background on top
of the old on without first removing it, or does this not matter.

Thanks
Damian B