Archived

This topic is now archived and is closed to further replies.

mirror_a_sprite

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

Im having the same problem right now...and Im using SDL too..I really need to know how can I mirror sprites...there must be an easy and fast way to do it..
Please?

"Those who follow the path of the warrior must be ready to die, to stand for their convictions, live for one´s convictions, die for one´s convictions"

Share this post


Link to post
Share on other sites
Here ya go, out of my kexen project:

SDL_Surface* FlipSurfaceH(SDL_Surface *bitmap){
if(!bitmap)return NULL;
SDL_Surface *temp=SDL_CreateRGBSurface(0,bitmap->w,bitmap->h,
bitmap->format->BitsPerPixel,bitmap->format->Rmask,bitmap->format->Gmask,
bitmap->format->Bmask,bitmap->format->Amask);
if(!temp)return NULL;
SDL_Rect src,dest;
src.w=1;
src.h=bitmap->h;
src.y=0;
dest.y=0;
int origw=bitmap->w;
for(int i=0;i<origw;i++){
src.x=i;
dest.x=(origw-1)-i;
SDL_BlitSurface(bitmap,&src,temp,&dest);
}
return temp;
}


SDL_Surface* FlipSurfaceV(SDL_Surface *bitmap){
if(!bitmap)return NULL;
SDL_Surface *temp=SDL_CreateRGBSurface(0,bitmap->w,bitmap->h,
bitmap->format->BitsPerPixel,bitmap->format->Rmask,bitmap->format->Gmask,
bitmap->format->Bmask,bitmap->format->Amask);
if(!temp)return NULL;
SDL_Rect src,dest;
src.w=bitmap->w;
src.h=1;
src.x=0;
dest.x=0;
int origh=bitmap->h;
for(int i=0;i<origh;i++){
src.y=i;
dest.y=(origh-1)-i;
SDL_BlitSurface(bitmap,&src,temp,&dest);
}
return temp;
}


FlipSurfaceH flips around the Y axis (mirrors), FlipSurfaceV flips around the X axis (err.. flips. Upside down you know.)

Note that these aren't in-place, they return a new SDL_Surface.

EDIT: Oh BTW, this is C++ code. If you need C it shouldn't be to hard to convert, just move around the varible defs, I think that'd do it.

EDIT EDIT: How it works:
It creates a new surface, same type as the old.
It blits a bunch of wide (or tall) 1 pixel wide/tall blits, in reverse order on the destination.

Seems to be a decently fast way to do it.
For extra speed, you could use SDL_LowerBlit instead (since you KNOW that the blits don't need to be clipped).

You could also probably turn the V flip into a bunch of memcpy's, direct pixel-level access.

The blitting method is probably(is?) much faster if your surface's are in video memory (and you have surface->surface HW blits).
(Although it doesn't ask for HW surfaces.
You can change the first argument of SDL_CreateRGBSurface to SDL_HWSURFACE to request HW surfaces.)


[edited by - TravisWells on June 3, 2003 12:32:53 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Jumpman
i''ve not used SDL but you could always try swapping the texture coordinates around.



SDL doesn''t use texture coords (at least the internal blitting functions don''t. If you use it with OpenGL, it''s normal OpenGL texturing.), it''s just a simple blitter.
You just give it SDL_Rects to copy from source to destination surfaces, no texture coords.

Share this post


Link to post
Share on other sites
Nope. That''s what my code does.

SDL takes the SIMPLE part of the name very seriously, it''s pretty much only what you need to make your game work on multiple platforms.

So if you want to do anything more than create windows, load BMPS, blit rectangles, and do some input processing, you have to use an add-on library or code your own stuff.

It''s still a great library in my opinion
Most of the time I use it for OpenGL, so extra blitting/flipping wouldn''t really be helpful.

Share this post


Link to post
Share on other sites