I’m using SDL2 version 2.0.10, with a Direct3D 11 renderer.
I’m simply trying to rotate a SDL_Texture, so I’m calling SDL_RenderCopyEx
. For example, if I want to rotate 90 degrees, I call it like so :
float rotationAngle = 90.0f; // 90 degree clock-wise, I assumed
SDL_RenderCopyEx(renderer, texture, NULL, &destRect, rotationAngle , NULL, SDL_FLIP_NONE);
When I did that, I realized that the texture seems to rotate counter-clockwise (it was rotating to the left, instead of the right, like I thought it would do).
I found nothing online or in the documentation specifically explaining how the angles are supposed to work, but all tutorials I’ve found about rotation in SDL2 seemed to assume a rotation to the right, from 0.0f
to 360.0f
.
After lots of tests, I finally came up with a working (albeit very patchy) solution :
float rotationAngle = 90.0f; // The real rotation angle I want to apply
float rotationAngleFixed = rotationAngle + 180.0f;
// 360 is interpreted as 0, so we need to change it slightly if we want a 180-ish degree rotation
if(rotationAngleFixed == 360.0f)
rotationAngleFixed -= 0.01f;
SDL_RenderCopyEx(renderer, texture, NULL, &destRect, rotationAngleFixed, NULL, SDL_FLIP_NONE);
This works all the time. And I very much dislike the fact that I’m about to push this to otehr developers.
Why do I need to do that? Is that a bug, or an undocumented feature?