SDL 1.2 or 1.3: How to do Flip Sprites Vertically/Horizontal

Not really. To flip image, you would need to rotate it around Y axis, while “rotation API” that is often discussed here is about rotating a sprite around Z axis.

To flip image you need to scale it using negative scaling factors, for example scaling with [1, -1] (values of scaling matrix diagonal) will flip image vertically.

This in theory means that to flip with SDL 1.3 you need to pass a negative destination rect paramater w or h to SDL_RenderCopy(). I never tried that but I guess it is worth a shot :wink:

Mason Wheeler wrote:> You can’t. For that we’d need a rotation API, with the ability to manipulate vertices as they’re being drawn. We don’t have one yet.

From: delete12345 <tom_mai78101 at yahoo.com.tw>
Subject: [SDL] SDL 1.2 or 1.3: How to do Flip Sprites Vertically/Horizontally?

Like the title, how do I do it?

Did a search, but nothing came up.

Thanks in advance.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I just checked, negative destination width or height does not work. I think it should. SDL 1.3 already does scaling and IMHO this would be a very nice feature, especially because I need it :wink: To clarify: using a negative scaling factor in OGL or D3D (usually -1) flips vertices around corresponding perpendicular axis. Therefore I think that SDL 1.3 should not check dst rect for invalid values (negative) but simply use them to calculate scaling. Correct me if I am wrong but this will also be simple for software renderer - just blitting in reverse row/column order?

hardcoder wrote:> Not really. To flip image, you would need to rotate it around Y axis, while “rotation API” that is often discussed here is about rotating a sprite around Z axis.

To flip image you need to scale it using negative scaling factors, for example scaling with [1, -1] (values of scaling matrix diagonal) will flip image vertically.

This in theory means that to flip with SDL 1.3 you need to pass a negative destination rect paramater w or h to SDL_RenderCopy(). I never tried that but I guess it is worth a shot :wink:

Mason Wheeler wrote:

You can’t. For that we’d need a rotation API, with the ability to manipulate vertices as they’re being drawn. We don’t have one yet.

From: delete12345 <tom_mai78101 at yahoo.com.tw>
Subject: [SDL] SDL 1.2 or 1.3: How to do Flip Sprites Vertically/Horizontally?

Like the title, how do I do it?

Did a search, but nothing came up.

Thanks in advance.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org