Jump to content
  • Advertisement
Sign in to follow this  
martin_bfg10k

[SDL Problem] Mirrored sprite blitting

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

Advertisement
There's no such function in current SDL API, and it's not even planned in the future versions, as David Olofson explains:

Quote:
The problem is that anything added to the SDL API must also be
supported on all other backends - not just the glSDL-on-steroids of
the future SDL 1.3. That means software fallbacks, that are either
too slow for any form of real time use, or that use shortcuts that
make some artwork look horrible, or both. Adding just a few of these
features means opening up a gigantic can of worms with quality/speed
conflicts, countless special cases to optimize - and still, all you
get is a slow and/or horrible looking fallback for users who don't
have accelerated OpenGL or Direct3D/DirectGraphics.

Viable or not? Well, it's going to be more work than adding native s/w
rendering to a single game... (Can't cut any corners, since we have
no idea what kind of data people will throw at us.) It would be a
cool thing to have, but who will hack, debug and optimize all that
s/w blitter code? :-)


So, if you want to have mirrored sprites:

1. Do what Ekim_Gram suggested, or
2. Use OpenGL

If you must mirror those sprites in realtime... than, AFAIK, OpenGL is the only way.

Share this post


Link to post
Share on other sites
Instead of blitting, you could always reverse a surface and then blit it.

SDL_Surface contains:
SDL_PixelFormat *format; /* Read-only */
int w, h; /* Read-only */
void *pixels; /* Read-write */

It would be simple to access *pixel, reverse each line and then blit the reversed surface. swap() is already built into the stl and pretty fast. If speed is a concern, you should probably load two of the same image during loadtime and the mirrored one.

The only way I know to do this in realtime is to set *srcrect in SDL_Blit() one pixel wide and your entire surface high and move the *srcrect in along the x axis in a positive direction while moving *dstrect in the negitive direction along the x axis. If you rarely mirror a sprite, this might be work out for you, although I'd prefer the my first suggestion.

Share this post


Link to post
Share on other sites
I'm making an asteroid/trader game with LOTS of spinning objects. I tried the library SGE, which might suit your purposes, but it is kind of difficult to use, I found, and relatively slow. I wound up using OpenGL/SDL, which allows me to utilize hardware rotations. It wound up being a faster, more elegant solution that allows me to do more with my game. That's my suggestion.

Share this post


Link to post
Share on other sites
If you want to mirror an image, take a look at my post here. I'm in the process of updating my webpages, so that image no longer exists, but you should be able to test it out yourself and see if it's what you are after. Note that you will not want to mirror in real time, rather mirror once, and store that image and just use that thoughout. Note that you will need to SDL_FreeSurface the surface returned by those functions.

Share this post


Link to post
Share on other sites
If you want to use OpenGL, but don't feel like totaly destroying your codebase, take a look at my library, hxRender. It uses OpenGL ontop of an SDL Context, so you can keep all your input and sound code. Check it out.

All you would have to do for a mirrored sprite is define a negitive width and height for the w and h parameters of the destination rectangle.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!