diff options
author | Bad Diode <bd@badd10de.dev> | 2021-04-18 15:07:51 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-04-18 15:07:51 +0200 |
commit | 914ee14327f54b8ec88b861e8dc08090d7041acf (patch) | |
tree | f95d1ad50282cc0bad1d9c0dc2684d6a9a122680 | |
parent | 344d070dfbfe4bbde93708a0c14436b57f487007 (diff) | |
download | gba-experiments-914ee14327f54b8ec88b861e8dc08090d7041acf.tar.gz gba-experiments-914ee14327f54b8ec88b861e8dc08090d7041acf.zip |
Fix rendering issue by hiding the sprites on initialization
-rw-r--r-- | src/main.c | 38 |
1 files changed, 22 insertions, 16 deletions
@@ -429,11 +429,21 @@ int main(void) { | |||
429 | 429 | ||
430 | // Create two 4bpp tiles, one filled with color 1 and another with color 2. | 430 | // Create two 4bpp tiles, one filled with color 1 and another with color 2. |
431 | Tile *tile_mem = &TILE_MEM[4][0]; | 431 | Tile *tile_mem = &TILE_MEM[4][0]; |
432 | for (size_t i = 0; i < 8; ++i) { | 432 | size_t n_tiles = 8; |
433 | tile_mem->data[i] = 0x11111111; | 433 | u32 colors[] = { |
434 | } | 434 | 0x11111111, |
435 | for (size_t i = 8; i < 16; ++i) { | 435 | 0x22222222, |
436 | tile_mem->data[i] = 0x22222222; | 436 | 0x33333333, |
437 | 0x44444444, | ||
438 | 0x55555555, | ||
439 | 0x66666666, | ||
440 | 0x77777777, | ||
441 | 0x88888888, | ||
442 | }; | ||
443 | for (size_t j = 0; j < n_tiles; ++j) { | ||
444 | for (size_t i = j * 8; i < 8 + 8 * j; ++i) { | ||
445 | tile_mem->data[i] = colors[j]; | ||
446 | } | ||
437 | } | 447 | } |
438 | 448 | ||
439 | // Add colors to the sprite color palette. Tiles with color number 0 are | 449 | // Add colors to the sprite color palette. Tiles with color number 0 are |
@@ -443,7 +453,7 @@ int main(void) { | |||
443 | PAL_BUFFER_SPRITES[3] = COLOR_CYAN; | 453 | PAL_BUFFER_SPRITES[3] = COLOR_CYAN; |
444 | PAL_BUFFER_SPRITES[4] = COLOR_GREY; | 454 | PAL_BUFFER_SPRITES[4] = COLOR_GREY; |
445 | PAL_BUFFER_SPRITES[5] = COLOR_BLACK; | 455 | PAL_BUFFER_SPRITES[5] = COLOR_BLACK; |
446 | PAL_BUFFER_SPRITES[15] = COLOR_RED; | 456 | PAL_BUFFER_SPRITES[6] = COLOR_RED; |
447 | 457 | ||
448 | int x_a = 100; | 458 | int x_a = 100; |
449 | int y_a = 100; | 459 | int y_a = 100; |
@@ -452,6 +462,12 @@ int main(void) { | |||
452 | int y_b = 50; | 462 | int y_b = 50; |
453 | int tile_id_b = 1; | 463 | int tile_id_b = 1; |
454 | 464 | ||
465 | // Initialize all attributes by disabling rendering. If we don't do this, | ||
466 | // glitches may appear. | ||
467 | for (size_t i = 0; i < 128; ++i) { | ||
468 | OBJ_ATTR_0(i) = (1 << 9); | ||
469 | } | ||
470 | |||
455 | OBJ_ATTR_0(0) = y_a; | 471 | OBJ_ATTR_0(0) = y_a; |
456 | OBJ_ATTR_1(0) = x_a; | 472 | OBJ_ATTR_1(0) = x_a; |
457 | OBJ_ATTR_2(0) = tile_id_a; | 473 | OBJ_ATTR_2(0) = tile_id_a; |
@@ -460,16 +476,6 @@ int main(void) { | |||
460 | OBJ_ATTR_1(1) = x_b; | 476 | OBJ_ATTR_1(1) = x_b; |
461 | OBJ_ATTR_2(1) = tile_id_b; | 477 | OBJ_ATTR_2(1) = tile_id_b; |
462 | 478 | ||
463 | // for (size_t i = 0; i < 16; ++i) { | ||
464 | // PAL_BUFFER_SPRITES[i] = COLOR_RED; | ||
465 | // } | ||
466 | // PAL_BUFFER_SPRITES[0] = COLOR_RED; | ||
467 | // PAL_BUFFER_BG[0] = COLOR_WHITE; | ||
468 | |||
469 | // for (size_t i = 0; i < sizeof(tile_mem->data); ++i) { | ||
470 | // tile_mem->data[i] = COLOR_WHITE; | ||
471 | // } | ||
472 | |||
473 | int frame_counter = 0; | 479 | int frame_counter = 0; |
474 | int active_sprite = 0; | 480 | int active_sprite = 0; |
475 | while(true) { | 481 | while(true) { |