calccrypto
calccrypto

Reputation: 9001

dereferencing SDL_Surfaces?

is there any way to copy a SDL surface to another, like creating a backup copy, without modifying the original when the copy is modified? *surface = *original_surface dosnt work. SDL_Surface does not have any constructors, so i cant do anything like surface = new SDL_Surface (original_surface). currently, i am opening the original image constantly, but it takes longer to open the image than for one loop to finish. this causes a lot of lagging, and eventually errors, causing my program to end

Upvotes: 0

Views: 139

Answers (1)

Omri Barel
Omri Barel

Reputation: 9490

You can create a new compatible surface:

copy = SDL_CreateRGBSurface(flags, width, height, original->format.BitsPerPixel,
                            original->format.Rmask, original->format.Gmask,
                            original->format.Bmask, original->format.Amask);

And then blit the original into the copy:

SDL_BlitSurface(original, NULL, copy, NULL);

Upvotes: 1

Related Questions