From 914ee14327f54b8ec88b861e8dc08090d7041acf Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 18 Apr 2021 15:07:51 +0200 Subject: Fix rendering issue by hiding the sprites on initialization --- src/main.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main.c b/src/main.c index 07c809e..a6385b3 100644 --- a/src/main.c +++ b/src/main.c @@ -429,11 +429,21 @@ int main(void) { // Create two 4bpp tiles, one filled with color 1 and another with color 2. Tile *tile_mem = &TILE_MEM[4][0]; - for (size_t i = 0; i < 8; ++i) { - tile_mem->data[i] = 0x11111111; - } - for (size_t i = 8; i < 16; ++i) { - tile_mem->data[i] = 0x22222222; + size_t n_tiles = 8; + u32 colors[] = { + 0x11111111, + 0x22222222, + 0x33333333, + 0x44444444, + 0x55555555, + 0x66666666, + 0x77777777, + 0x88888888, + }; + for (size_t j = 0; j < n_tiles; ++j) { + for (size_t i = j * 8; i < 8 + 8 * j; ++i) { + tile_mem->data[i] = colors[j]; + } } // Add colors to the sprite color palette. Tiles with color number 0 are @@ -443,7 +453,7 @@ int main(void) { PAL_BUFFER_SPRITES[3] = COLOR_CYAN; PAL_BUFFER_SPRITES[4] = COLOR_GREY; PAL_BUFFER_SPRITES[5] = COLOR_BLACK; - PAL_BUFFER_SPRITES[15] = COLOR_RED; + PAL_BUFFER_SPRITES[6] = COLOR_RED; int x_a = 100; int y_a = 100; @@ -452,6 +462,12 @@ int main(void) { int y_b = 50; int tile_id_b = 1; + // Initialize all attributes by disabling rendering. If we don't do this, + // glitches may appear. + for (size_t i = 0; i < 128; ++i) { + OBJ_ATTR_0(i) = (1 << 9); + } + OBJ_ATTR_0(0) = y_a; OBJ_ATTR_1(0) = x_a; OBJ_ATTR_2(0) = tile_id_a; @@ -460,16 +476,6 @@ int main(void) { OBJ_ATTR_1(1) = x_b; OBJ_ATTR_2(1) = tile_id_b; - // for (size_t i = 0; i < 16; ++i) { - // PAL_BUFFER_SPRITES[i] = COLOR_RED; - // } - // PAL_BUFFER_SPRITES[0] = COLOR_RED; - // PAL_BUFFER_BG[0] = COLOR_WHITE; - - // for (size_t i = 0; i < sizeof(tile_mem->data); ++i) { - // tile_mem->data[i] = COLOR_WHITE; - // } - int frame_counter = 0; int active_sprite = 0; while(true) { -- cgit v1.2.1