I use SDL for my programs graphics and I have a problem with it in flipping surfaces.When I compile following code:
int main(int argc , char* argv[])
{
SDL_Surface* scr1 = SDL_SetVideoMode(880 , 600 , 0 , SDL_HWSURFACE |SDL_DOUBLEBUF );
SDL_Surface* scr2 = SDL_SetVideoMode(880 , 600 , 0 , SDL_HWSURFACE |SDL_DOUBLEBUF );
aacircleRGBA(scr1 , 50 , 50 , 30 , 255 , 0 , 0 , 255);
SDL_Flip(scr2);
return 0;
}
It shows the circle on the screen.But I flipped only scr2.Why does it show the circle?
After you call
SDL_SetVideoMode()a second time, the original screen buffer pointer is, in the general case, invalid. You shouldn’t be reusing it, because it doesn’t point to an allocated surface anymore.In this case, calling
SDL_SetVideoMode()twice with the same parameters givesscr2 == scr1, because there is no need for SDL to reallocate the video surface. Drawing on the surface referred to byscr1is thus the same as drawing on that referred to byscr2.