Add small code example for drawing a flipped texture

master
Peter0x44 3 年之前
父節點
當前提交
822e5ef46e
共有 1 個檔案被更改,包括 11 行新增3 行删除
  1. +11
    -3
      Frequently-asked-Questions--Common-Questions.md

+ 11
- 3
Frequently-asked-Questions--Common-Questions.md

@ -97,9 +97,17 @@ DrawText(text, textStartX, textStartY, fontSize, LIGHTGRAY);
Drawing a texture flipped requires the use of either `DrawTextureRec`, or `DrawTexturePro` functions.
Every single texture drawing function calls `DrawTexturePro` to do its work, but only these two expose the parameters necessary to flip a texture (the source rectangle).
To flip the texture, simply pass a source rectangle with a negative width and height.
To flip the texture, simply pass a source rectangle with a negative width or height.
```c
Rectangle source = (Rectangle) { 0, 0, -texture.width, texture.height };
DrawTextureRec(texture, source, (Vector2) { 0, 0 }, WHITE);
```
The above code will draw a texture flipped in the X axis.
# Why is my render texture upside down?
All textures in OpenGL by default have the origin in the lower-left corner. When you load a normal texture, raylib flips the image data for you, however this cannot be done with a render texture.
The solution is to flip your texture when drawing, see the above paragraph for how to do this.
All textures in OpenGL by default have the origin in the lower-left corner, while the screen origin is in the upper left. When you load a normal texture, raylib flips the image data for you, however this cannot be done with a render texture.
The solution is to flip your texture vertically when drawing, see the above paragraph for how to do this.

Loading…
取消
儲存