Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

How to copy a certain portion of the screen to SDL_Surface

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 codeboyjimmy   Members   

100
Like
0Likes
Like

Posted 08 February 2012 - 01:28 AM

I am a beginner in SDL graphics. I am trying to copy a certain portion of the screen to SDL_Surface. And I tried using this code but it didn't work out

SDL_Surface* original=NULL;
SDL_Rect rct;
rct.x=90;
rct.y=70;
rct.w=100;
rct.h=100;


SDL_BlitSurface(screen,&rct,original,NULL);

//It should blit the area of the screen bounded by rct at 0,0 of the original

apply_surface(500,100,original,screen);

//now it should blit the original at 500,100 of the screen

SDL_Flip(screen);

but nothing was blitted on the screen.


but the same code worked out well when it was written this way


SDL_Surface* original=NULL;
SDL_Rect rct;
rct.x=90;
rct.y=70;
rct.w=100;
rct.h=100;

original=IMG_Load("pics/picture1.png"); //I loaded a picture in the original

SDL_BlitSurface(screen,&rct,original,NULL);

apply_surface(500,100,original,screen);

SDL_Flip(screen);

And it worked out very well. It blitted a small part of my window i.e. screen to 500,100 of the screen

So I think there must be something wrong with my understanding about surface blitting function.
I am using SDL 1.2.14 and Code::Blocks for IDE.

And if there is a better way to do what I am trying to do, then please suggest

Thank you in advance.

#2 RulerOfNothing   Members   

1448
Like
0Likes
Like

Posted 08 February 2012 - 05:16 AM

The problem is that in your first piece of code, original is not pointing to a valid SDL_Surface when you try to blit. As SDL_BlitSurface doesn't create surfaces for you, you need to use the SDL_CreateRGBSurface function to give a second surface to blit to. Keep in mind that you need to free any surface you create yourself using SDL_FreeSurface.

#3 codeboyjimmy   Members   

100
Like
0Likes
Like

Posted 12 February 2012 - 05:08 AM

Thank you




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.