Advertisement

Duplicating SDL_Surface's

Started by February 06, 2005 04:42 AM
2 comments, last by graveyard filla 19 years, 7 months ago
How do I copy SDL_Surfaces? It is my understanding that the below only points to the image, and is not a copy: SDL_Surface *first, *second; first = LoadBMP("blah.bmp"); second = first;
I'm still a bit of a noob with SDL but you could try using SDL_convertSurface().

I think somethign like this should suffice:
SDL_Surface *first, *second;first = LoadBMP("blah.bmp");second = SDL_ConvertSuface( first, first->format, SDL_SWSURFACE );
Advertisement
Use SDL_DisplayFormat().

It would be..

SDL_Surface *foo, *bar;

foo = SDL_LoadBMP("blah.bmp");

bar = SDL_DisplayFormat( foo );


That makes bar it's own seperate surface, with no pointers to foo, but it is the exact same image.

Cheers.
gib.son
Quote: Original post by c-gibson-s
Use SDL_DisplayFormat().

It would be..

SDL_Surface *foo, *bar;

foo = SDL_LoadBMP("blah.bmp");

bar = SDL_DisplayFormat( foo );


That makes bar it's own seperate surface, with no pointers to foo, but it is the exact same image.

Cheers.


you should note one thing though. using this method bar will be created with the format of the screen. if foo was not originally the format of the screen surface, then foo and bar will have a different format.

you should be convering all images to the screen format anyway though. this makes things much faster if the screen surface is different then the surfaces you render with.

however, if you want to make an exact copy of a surface, the solution is simple. first, create a empty / blank surface using SDL_CreateRGBSurface. then, simply blit the original surface onto this surface. now you have a copy.
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement