a-game

2D platformer written from scratch.
Log | Files | Refs | README | LICENSE

commit 49da3252faeb1e5d9497604c6ce1153295abcbfd
parent 6566a9dcf2f15f4b1965db677de28409fa720d27
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Thu,  4 Jul 2019 18:52:08 -0700

Flip the image right side up

Diffstat:
Msrc/game.c | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -72,6 +72,21 @@ internal u8 *img_load_from_memory(u8 *buffer, size_t len, i32 *out_width, i32 *o pixels[i] = *buffer++; } + u32 bytes_per_row = h.width * bytes_per_pixel; + // NOTE(amin): Intentional truncating division. If height is odd, we want + // our last row offset to be 1 less than the middle row. + u32 half_height = h.height / 2; + for (size_t row_offset = 0; row_offset < half_height; row_offset++) + { + u8 *top_row = &pixels[row_offset * bytes_per_row]; + u8 *bot_row = &pixels[(h.height - row_offset - 1) * bytes_per_row]; + for (size_t i = 0; i < bytes_per_row; i++) + { + u8 temp = top_row[i]; + top_row[i] = bot_row[i]; + bot_row[i] = temp; + } + } return pixels; }