Discussion:
Copying clipped image to a new surface
Armond Sarkisian
2008-08-03 17:53:48 UTC
Permalink
After you clip a surface, is there any way you can "copy" that clipped portion
onto its own brand new surface?
Mason Wheeler
2008-08-03 18:05:23 UTC
Permalink
That's simple enough. Use the new cliprect as a source-rect and blit it onto the new surface.
----- Original Message ----
Subject: [SDL] Copying clipped image to a new surface
After you clip a surface, is there any way you can "copy" that clipped portion
onto its own brand new surface?
Armond Sarkisian
2008-08-03 19:05:04 UTC
Permalink
THanks. sorry i'm still an extreme newb hehe so still have to get used to
things
Post by Mason Wheeler
That's simple enough. Use the new cliprect as a source-rect and blit it
onto the new surface.
----- Original Message ----
Subject: [SDL] Copying clipped image to a new surface
After you clip a surface, is there any way you can "copy" that clipped
portion
onto its own brand new surface?
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Armond Sarkisian
2008-08-03 19:29:40 UTC
Permalink
surprisingly i'm still having problems..

SDL_Surface* final = ( NULL );

// copy the clipped image onto the new surface final
_sdl.blitSurface( 0, 0, preImage, final, &clip[0] );


// copy the final image back onto the screen
_sdl.blitSurface( 0, 0, final, screen, NULL );

// update the screen
SDL_UpdateRect( the_screen, 0, 0, 0, 0 );
SDL_FreeSurface( final );

Does this look correct? The image after is not being displayed on the main
screen. I'm sure i'm missing something
Post by Mason Wheeler
That's simple enough. Use the new cliprect as a source-rect and blit it
onto the new surface.
----- Original Message ----
Subject: [SDL] Copying clipped image to a new surface
After you clip a surface, is there any way you can "copy" that clipped
portion
onto its own brand new surface?
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Jonathan Dearborn
2008-08-03 21:35:32 UTC
Permalink
It looks like you have to create a destination surface first. Your 'final' variable is just an empty pointer.



Try using SDL_CreateRGBSurface:



#if SDL_BYTEORDER == SDL_BIG_ENDIAN

SDL_Surface* final =
SDL_CreateRGBSurface(SDL_SWSURFACE,width,height,32, 0xFF000000,
0x00FF0000, 0x0000FF00, 0x000000FF);

#else

SDL_Surface* final =
SDL_CreateRGBSurface(SDL_SWSURFACE,width,height,32, 0x000000FF,
0x0000FF00, 0x00FF0000, 0xFF000000);

#endif





Jonny D



Date: Sun, 3 Aug 2008 12:29:40 -0700
From: ***@gmail.com
To: ***@lists.libsdl.org
Subject: Re: [SDL] Copying clipped image to a new surface

surprisingly i'm still having problems..

SDL_Surface* final = ( NULL );

// copy the clipped image onto the new surface final
_sdl.blitSurface( 0, 0, preImage, final, &clip[0] );



// copy the final image back onto the screen
_sdl.blitSurface( 0, 0, final, screen, NULL );

// update the screen
SDL_UpdateRect( the_screen, 0, 0, 0, 0 );
SDL_FreeSurface( final );


Does this look correct? The image after is not being displayed on the main screen. I'm sure i'm missing something

On Sun, Aug 3, 2008 at 11:05 AM, Mason Wheeler <***@yahoo.com> wrote:

That's simple enough. Use the new cliprect as a source-rect and blit it onto the new surface.
----- Original Message ----
Subject: [SDL] Copying clipped image to a new surface
After you clip a surface, is there any way you can "copy" that clipped portion
onto its own brand new surface?
_______________________________________________

SDL mailing list

***@lists.libsdl.org

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Andre Botelho
2008-08-04 14:30:41 UTC
Permalink
Send SDL mailing list submissions to
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
or, via email, send a message with subject or body 'help' to
You can reach the person managing the list at
When replying, please edit your Subject line so it is more specific
than "Re: Contents of SDL digest..."
1. Re: Copying clipped image to a new surface (Armond Sarkisian)
----------------------------------------------------------------------
Message: 1
Date: Sun, 3 Aug 2008 12:29:40 -0700
Subject: Re: [SDL] Copying clipped image to a new surface
To: "A list for developers using the SDL library. (includes
Content-Type: text/plain; charset="iso-8859-1"
surprisingly i'm still having problems..
SDL_Surface* final = ( NULL );
// copy the clipped image onto the new surface final
_sdl.blitSurface( 0, 0, preImage, final, &clip[0] );
// copy the final image back onto the screen
_sdl.blitSurface( 0, 0, final, screen, NULL );
// update the screen
SDL_UpdateRect( the_screen, 0, 0, 0, 0 );
SDL_FreeSurface( final );
Does this look correct? The image after is not being displayed on the main
screen. I'm sure i'm missing something
Post by Mason Wheeler
That's simple enough. Use the new cliprect as a source-rect and blit it
onto the new surface.
----- Original Message ----
Subject: [SDL] Copying clipped image to a new surface
After you clip a surface, is there any way you can "copy" that clipped
portion
onto its own brand new surface?
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <
http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080803/79265a53/attachment.html
------------------------------
I' dont know this: _sdl.blitSurface( 0, 0, preImage, final, &clip[0] );
on the docs is like this:

SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
SDL_Rect *dstrect);

so iyou should write

SDL_BlitSurface(preImage, &clip[0], final, NULL);

to clip the preimage.

Continue reading on narkive:
Loading...