Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XNA Rotate Texture 2D

Tags:

c#

xna

I'd like to rotate a Texture in XNA. I know I can rotate it when it is drawn, but I would like the Texture2D variable to be the rotated texture. Is there any way to do this?

like image 551
CommunistPancake Avatar asked Sep 19 '11 04:09

CommunistPancake


2 Answers

Use RenderTarget, draw your texture rotated into the RenderTarget, take the texture and save it.

like image 178
icaptan Avatar answered Oct 04 '22 18:10

icaptan


You should provide a new shader that manage texture coords rotation. As the HLSL code of the basiceffect is public, it should be pretty easy to add this behaviour.

Basic Effect HLSL code

Passing an angle parameter to the shader, the transform should be:

 newU = U*cos(alfa) - V*sin(alfa);
 newV = U*sin(alfa) + V*cos(alfa);
like image 30
Blau Avatar answered Oct 04 '22 18:10

Blau