• Advertisement
Sign in to follow this  

Returning clipped SDL_Surface*

This topic is 3710 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

This is really annoying me.. I know how to apply an SDL_Surface* using a given SDL_Rect to specify only a small part of it. But I need my function to take an SDL_Surface*, clip it down specified by a rect and return the surface WITHOUT blitting it. So it should look like this: SDL_Surface* ClipSurface (SDL_Surface* pSurface, SDL_Rect* pClip) { SDL_Surface* pResizedSurf; // cut out a pClip from pSurface and apply it for pResizedSurf return pResizedSurf; } .. thanks a million! I'm just too tired at this stage... :(

Share this post


Link to post
Share on other sites
Advertisement
Without blitting the surface to the screen, or without using SDL_Blit entirely?

Why not just create a empty surface of the dimensions 'pClip->w' and 'pClip->h', and blit pSurface over that, using '-pClip->x' and '-pClip->y'? SDL takes care of making sure you don't go out of bounds, so it should be safe. [smile]

You can use SDL_CreateRGBSurface to make the empty surface.


If you are not wanting to do that, you can use SDL_CreateRGBSurfaceFrom to do what you are wanting, it'll just take a bit more math by modifying the pixel data pointer passed(void *pixels), and changing the pitch, but it also should work. It might be slower than a fast blit, though, and certainly more dangerous, since it now relies on you to make sure you don't go out of bounds, instead of SDL bubblewrapping it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Servant of the Lord
Without blitting the surface to the screen, or without using SDL_Blit entirely?


Without blitting to the screen..

Quote:
Original post by Servant of the Lord

Why not just create a empty surface of the dimensions 'pClip->w' and 'pClip->h', and blit pSurface over that, using '-pClip->x' and '-pClip->y'? SDL takes care of making sure you don't go out of bounds, so it should be safe. [smile]

You can use SDL_CreateRGBSurface to make the empty surface.


If you are not wanting to do that, you can use SDL_CreateRGBSurfaceFrom to do what you are wanting, it'll just take a bit more math by modifying the pixel data pointer passed(void *pixels), and changing the pitch, but it also should work. It might be slower than a fast blit, though, and certainly more dangerous, since it now relies on you to make sure you don't go out of bounds, instead of SDL bubblewrapping it.


Thanks a million, exactly what I wanted! :D
I can finally get some sleep now..

Share this post


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

  • Advertisement