Last active
April 30, 2024 15:45
-
-
Save cstrachan88/d81a7d1f337b45f8548d2fe541f0e2d8 to your computer and use it in GitHub Desktop.
Procedure to flip raylib Y-Axis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rl "vendor:raylib" | |
// NOTE this only works for simple shapes. Texts and Textures will be rendered upside-down | |
// Sets the origin to the bottom left corner with up = Y+ | |
rl_flip_y_axis :: proc() { | |
// Swap which face is culled - https://github.com/raysan5/raylib/issues/3786 | |
rl.rlSetCullFace(.FRONT) | |
// // Option 1 - create projection matrix | |
// rl.rlMatrixMode(rl.RL_PROJECTION) | |
// rl.rlLoadIdentity() | |
// rl.rlOrtho(0, SCREEN_WIDTH, -SCREEN_HEIGHT, 0, 0, 1) // default has SCREEN_HEIGHT as positive | |
// rl.rlTranslatef(0, -SCREEN_HEIGHT, 0) // default has no translation | |
// rl.rlMatrixMode(rl.RL_MODELVIEW) | |
// rl.rlLoadIdentity() | |
// Option 2 - create transformation matrix and use to adjust projection matrix | |
transform_matrix := rl.Matrix{1, 0, 0, 0, 0, -1, -SCREEN_HEIGHT, 0, 0, 0, 1, 0, 0, 0, 0, 1} | |
proj_matrix := rl.rlGetMatrixProjection() | |
rl.rlSetMatrixProjection(proj_matrix * transform_matrix) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment