DrawTexturePro draws nothing when destRec.width is negative #3128
Answered
by
Peter0x44
SpaceSoarer90
asked this question in
Q&A
-
#include <raylib.h>
#include <raymath.h>
int main() {
InitWindow(800, 600, "the c version");
SetTargetFPS(60);
Rectangle stencil = {0, 0, 16, 16};
Rectangle destRec = {0, 0, -64, 64};
Texture2D image = LoadTexture("mario.png");
const char *instructions[] = {
"WASD to move the texture around",
"UDLR to stretch the image",
"H to flip horizontally (change sign of stencil.width)",
"V to flip vertically (change sign of stencil.height)"
};
while (!WindowShouldClose()) {
if (IsKeyDown(KEY_W))
destRec.y--;
else if (IsKeyDown(KEY_S))
destRec.y++;
if (IsKeyDown(KEY_A))
destRec.x--;
else if (IsKeyDown(KEY_D))
destRec.x++;
if (IsKeyDown(KEY_UP))
destRec.height--;
else if (IsKeyDown(KEY_DOWN))
destRec.height++;
if (IsKeyDown(KEY_LEFT))
destRec.width--;
else if (IsKeyDown(KEY_RIGHT))
destRec.width++;
if (IsKeyPressed(KEY_H))
destRec.width = -destRec.width;
if (IsKeyPressed(KEY_V))
destRec.height = -destRec.height;
BeginDrawing();
ClearBackground(RAYWHITE);
for (int i = 0; i < sizeof(instructions) / sizeof(instructions[0]); i++) {
int textsize = 20;
DrawText(instructions[i], 0, textsize * i, textsize, BLUE);
}
DrawTexturePro(image, stencil, destRec, Vector2Zero(), 0.0, WHITE);
EndDrawing();
}
CloseWindow();
} whenever i press the H key that should just flip the image right? i just instead see this |
Beta Was this translation helpful? Give feedback.
Answered by
Peter0x44
Jun 23, 2023
Replies: 1 comment 1 reply
-
To flip a texture, you should pass a source rectangle with a negative width, not the dest rectangle. See: https://github.com/raysan5/raylib/wiki/Frequently-Asked-Questions#how-can-i-draw-a-texture-flipped for how to do it properly
This is the correct thing to do, so I'm not sure why you aren't doing it. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
SpaceSoarer90
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To flip a texture, you should pass a source rectangle with a negative width, not the dest rectangle.
See: https://github.com/raysan5/raylib/wiki/Frequently-Asked-Questions#how-can-i-draw-a-texture-flipped for how to do it properly
That is API misuse.
This is the correct thing to do, so I'm not sure why you aren't doing it.