summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2019-05-15 12:22:29 +0200
committerRay <[email protected]>2019-05-15 12:22:29 +0200
commit0eece03205b04f57f3a93a61c70eb1d69ac32977 (patch)
tree1da3fc196fa9841677cbe734270f87b1dc135573 /src
parent4d8b9e595a62e094b840a15efc1d7710128aa1f4 (diff)
downloadraylib-0eece03205b04f57f3a93a61c70eb1d69ac32977.tar.gz
raylib-0eece03205b04f57f3a93a61c70eb1d69ac32977.zip
Corrected issue with texture flip X
Diffstat (limited to 'src')
-rw-r--r--src/textures.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/textures.c b/src/textures.c
index a405f78b..73deed22 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -2573,7 +2573,7 @@ void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float sc
// Draw a part of a texture (defined by a rectangle)
void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint)
{
- Rectangle destRec = { position.x, position.y, sourceRec.width, (float)fabs(sourceRec.height) };
+ Rectangle destRec = { position.x, position.y, (float)fabs(sourceRec.width), (float)fabs(sourceRec.height) };
Vector2 origin = { 0.0f, 0.0f };
DrawTexturePro(texture, sourceRec, destRec, origin, 0.0f, tint);
@@ -2599,8 +2599,10 @@ void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, V
{
float width = (float)texture.width;
float height = (float)texture.height;
-
- if (sourceRec.width < 0) sourceRec.x -= sourceRec.width;
+
+ bool flipX = false;
+
+ if (sourceRec.width < 0) { flipX = true; sourceRec.width *= -1; }
if (sourceRec.height < 0) sourceRec.y -= sourceRec.height;
rlEnableTexture(texture.id);
@@ -2615,19 +2617,23 @@ void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, V
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer
// Bottom-left corner for texture and quad
- rlTexCoord2f(sourceRec.x/width, sourceRec.y/height);
+ if (flipX) rlTexCoord2f((sourceRec.x + sourceRec.width)/width, sourceRec.y/height);
+ else rlTexCoord2f(sourceRec.x/width, sourceRec.y/height);
rlVertex2f(0.0f, 0.0f);
// Bottom-right corner for texture and quad
- rlTexCoord2f(sourceRec.x/width, (sourceRec.y + sourceRec.height)/height);
+ if (flipX) rlTexCoord2f((sourceRec.x + sourceRec.width)/width, (sourceRec.y + sourceRec.height)/height);
+ else rlTexCoord2f(sourceRec.x/width, (sourceRec.y + sourceRec.height)/height);
rlVertex2f(0.0f, destRec.height);
// Top-right corner for texture and quad
- rlTexCoord2f((sourceRec.x + sourceRec.width)/width, (sourceRec.y + sourceRec.height)/height);
+ if (flipX) rlTexCoord2f(sourceRec.x/width, (sourceRec.y + sourceRec.height)/height);
+ else rlTexCoord2f((sourceRec.x + sourceRec.width)/width, (sourceRec.y + sourceRec.height)/height);
rlVertex2f(destRec.width, destRec.height);
// Top-left corner for texture and quad
- rlTexCoord2f((sourceRec.x + sourceRec.width)/width, sourceRec.y/height);
+ if (flipX) rlTexCoord2f(sourceRec.x/width, sourceRec.y/height);
+ else rlTexCoord2f((sourceRec.x + sourceRec.width)/width, sourceRec.y/height);
rlVertex2f(destRec.width, 0.0f);
rlEnd();
rlPopMatrix();