Jump to content
  • Advertisement
Sign in to follow this  
rafaelmgn

[SDL] How to copy the screen to another surface?

This topic is 2673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello!

I'm trying to make a copy of the actual screen to another SDL_Surface. I tried to use SDL_BlitSurface and SDL_DisplayFormat, rounded and non-rounded by callings of SDL_LockSurface and SDL_UnlockSurface, but I can't get the copy. I only get an empty surface.

Anyone can help me?

Share this post


Link to post
Share on other sites
Advertisement
SDL_BlitSurface() should work, without SDL_LockSurface(). How are you allocating the destination surface? Have you tried checking the return value of SDL_BlitSurface(), and the value of SDL_GetError()?

Share this post


Link to post
Share on other sites
I did the following:

SDL_Surface *mySurface, *temp;
SDL_Rect rect;

temp = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, screen->w, screen->h, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);

if (temp) {
mySurface = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
}

rect.x = 0;
rect.y = 0;

SDL_BlitSurface(screen, NULL, mySurface, &rect);


I tried to use SDL_GetError() but it didn't returned anything.

Share this post


Link to post
Share on other sites
SDL_CreateRGBSurface takes 8 arguments but you only pass 7 arguments. How is that possible?

SDL_DisplayFormat creates a copy so all you should have to do to create a copy of the screen surface ismySurface = SDL_DisplayFormat(screen);

Share this post


Link to post
Share on other sites
Sorry, I mistyped that line:

temp = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, screen->w, screen->h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);


I tried to use SDL_DisplayFormat, but no result and no error... huh.gif

Share this post


Link to post
Share on other sites
Sorry, I just put a fragment of the code, just a explanation of what I'm doing...

SDL_Surface *mySurface, *temp;
SDL_Rect rect;

temp = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, screen->w, screen->h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);

if (temp) {
mySurface = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
}

rect.x = 0;
rect.y = 0;

SDL_BlitSurface(screen, NULL, mySurface, &rect);

if (!mySurface) {
cerr << string(SDL_GetError()) << endl;
exit(-1);
}


It pass through the 'if'... there's no error, but it gives me a black surface.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!