Question by
Riderfan · Nov 07, 2015 at 07:51 PM ·
uv coordinates
DrawTextureWithCoords UV from top to bottom
hi there.
I've created a little helper function that renders a portion of a texture to the screen at a given location. This allows me to send it rectangles that are in texture pixel coords rather than trying to figuring out the percentages each time I need to make the call.
The issue is that, as wel know, the UV's for Unity are upside down (due to the way OpenGL decided to do things years ago). What I want to try and solve is the math required to flip the coords around so that I can pass in a top to bottom, left to right portion of the source texture, and have it properly render. Here is my function
//Simple routine that draws only part of a loaded texture
public void DrawPartTexture(Texture2D _texture, Rect _drawrect, Rect _partoftexture)
{
//Rectangles and the screen have the top left at the top left of the screen.
//however this function uses UV coords of the texture, which for some reason start at the bottom left of the image.
//So we need to flip this around so that the paramater used makes sense to most people and starts at the top left of the image.
Rect partoftexture = new Rect((_partoftexture.xMin / _texture.width), (_partoftexture.yMin / _texture.height), (_partoftexture.width / _texture.width) , (_partoftexture.height / _texture.height));
GUI.DrawTextureWithTexCoords(_drawrect, _texture, partoftexture);
}
Any help on getting the Y coord flipped around would be appreicated.
thanks David
Comment