Sign in to follow this  
phalaris

Returning clipped SDL_Surface*

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this