Merge pull request #85 from antonskwr/texture-flip-patch
Fixed issue with texture flip on X axis (patch taken from main repo)
This commit is contained in:
commit
3eef0d896c
1 changed files with 12 additions and 6 deletions
|
@ -2401,7 +2401,7 @@ void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float sc
|
||||||
// Draw a part of a texture (defined by a rectangle)
|
// Draw a part of a texture (defined by a rectangle)
|
||||||
void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint)
|
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 };
|
Vector2 origin = { 0.0f, 0.0f };
|
||||||
|
|
||||||
DrawTexturePro(texture, sourceRec, destRec, origin, 0.0f, tint);
|
DrawTexturePro(texture, sourceRec, destRec, origin, 0.0f, tint);
|
||||||
|
@ -2417,7 +2417,9 @@ void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, V
|
||||||
float width = (float)texture.width;
|
float width = (float)texture.width;
|
||||||
float height = (float)texture.height;
|
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;
|
if (sourceRec.height < 0) sourceRec.y -= sourceRec.height;
|
||||||
|
|
||||||
rlEnableTexture(texture.id);
|
rlEnableTexture(texture.id);
|
||||||
|
@ -2432,19 +2434,23 @@ void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, V
|
||||||
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer
|
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer
|
||||||
|
|
||||||
// Bottom-left corner for texture and quad
|
// 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);
|
rlVertex2f(0.0f, 0.0f);
|
||||||
|
|
||||||
// Bottom-right corner for texture and quad
|
// 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);
|
rlVertex2f(0.0f, destRec.height);
|
||||||
|
|
||||||
// Top-right corner for texture and quad
|
// 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);
|
rlVertex2f(destRec.width, destRec.height);
|
||||||
|
|
||||||
// Top-left corner for texture and quad
|
// 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);
|
rlVertex2f(destRec.width, 0.0f);
|
||||||
rlEnd();
|
rlEnd();
|
||||||
rlPopMatrix();
|
rlPopMatrix();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue