6

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?

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

Do you have an example?
5

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);

Comments

1

One way would be to pass a rotation matrix to your shader and multiply your texcoords by that before calling the texture sampler.

I'm not sure if XNA/DirectX has the same concept as OpenGL's texture matrix.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.