I'm dynamically drawing textures onto a rendertexture but I need to perform a rotation when drawing. I've been scouring the forums to understand this but no luck yet. Here's a bit of code that I use to draw on my rendertexture. My problem is that I can't figure out a way yet to draw at varying angles. I'd like to draw with a rotation of x degrees around the center of the texture. Code (csharp): RenderTexture.active = myRenderTexture; #if UNITY_EDITOR myRenderTexture.DiscardContents(); #endif GL.PushMatrix(); GL.LoadPixelMatrix(0, textureSize.x, textureSize.y, 0); // HOW TO ROTATE AS NEEDED Graphics.DrawTexture(screenRect, myTexture, myMaterial); GL.PopMatrix (); RenderTexture.active = null; I've played with modifying the shader to see if I can perform rotations in the vertex shader with no luck. I'm wondering if I can apply the rotation in GL, but I'm very GL challenged (and shader challenged for that matter). Any suggestions? TIA.
Have you tried something like this? Code (csharp): private Vector2 pivotPoint; private float fRot = 0.0f; ... Matrix4x4 origMatrix = GUI.matrix; pivotPoint = new Vector2( position.width / 2, position.height / 2 ); //GUIUtility.ScaleAroundPivot( scale, pivotPoint ); GUIUtility.RotateAroundPivot( fRot, pivotPoint ); if (GUI.Button(new Rect(position.width / 2 - 20, position.height / 2 - 20, 50, 50), "Big!")) { //scale += new Vector2(0.5F, 0.5F); fRot += 22.5f; } GUI.matrix = origMatrix;
Thanks IzzySoft. I tried a few different calls using RotateAroundPivot without any luck; I assume the matrix only affects GUI operations and not the Graphics operations. Wondering if there is a more preferred method for quickly performing dynamic modifications to rendertextures.