Reputation: 435
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?
Upvotes: 0
Views: 356
Reputation: 156138
On success. The returned surface is freed by SDL_Quit and must not be freed by the caller. This rule also includes consecutive calls to SDL_!SetVideoMode (i.e. resize or resolution change) because the existing surface will be released automatically. Whatever flags SDL_!SetVideoMode could satisfy are set in the flags member of the returned surface.
-- SDL_SetVideoMode function (emphasis mine)
There is only one hardware surface to render to, the one that appears on screen immediately after calling SDL_SetVideoMode
. where else would you expect that buffer to draw to?
Upvotes: 2
Reputation: 54971
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 gives scr2 == scr1
, because there is no need for SDL to reallocate the video surface. Drawing on the surface referred to by scr1
is thus the same as drawing on that referred to by scr2
.
Upvotes: 2