a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit 2bd00f7d6b7ea8aec085fd8950fa0d57719be9da
parent 7cefbbfaaf9a00f366afce85b9f7d3d9e65ed015
Author: amin <dev@aminmesbah.com>
Date:   Fri,  5 Jul 2019 01:52:07 +0000

Flip the image right side up

FossilOrigin-Name: 1af3e4af40a97017d3adf07506f73e253b2f11b7c3dc1a3ea29238bbcdc36985
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; }