DragonMinded / libdragon

Open source library for N64 development.
https://libdragon.dev
The Unlicense
733 stars 108 forks source link

Can't draw sprite with rdp unless drawing in software first #503

Closed hannahbunny closed 8 months ago

hannahbunny commented 8 months ago

Hi all, I was experimenting a bit with some of the examples and found some strange behavior when messing around with the spritemap example. If commenting out the graphics_draw_sprite_trans line, running the example below in Ares produces an error saying "ASSERTION FAILED: only sprites in FMT_RGBA16 or FMT_RGBA32 are supported" despite the sprite being the mudkip sprite from the example. Am I missing something here? Tested on both preview and unstable branches.

#include <libdragon.h>

int main() {
  display_init(RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, FILTERS_RESAMPLE);
  dfs_init(DFS_DEFAULT_LOCATION);
  rdpq_init();

  surface_t *disp = display_get();

  int fp = dfs_open("/mudkip.sprite");
  sprite_t *mudkip = malloc(dfs_size(fp));
  dfs_read(mudkip, 1, dfs_size(fp), fp);
  dfs_close(fp);

  // without this line, rdp_load_texture will cause an error
  graphics_draw_sprite_trans(disp, 50, 50, mudkip);

  while (true) {
    display_show(disp);
    disp = display_get();
    graphics_fill_screen(disp, 0xFFFFFFFF);
    graphics_set_color(0x0, 0xFFFFFFFF);
    graphics_draw_text(disp, 20, 20, "Test!");
    rdpq_set_mode_copy(true);
    rdpq_attach(disp, NULL);

    // error will occur here
    rdp_load_texture(0, 0, MIRROR_DISABLED, mudkip);

    rdp_draw_sprite(0, 50, 50, MIRROR_DISABLED);
    rdpq_detach_wait();
  }
}
rasky commented 8 months ago

Thanks for the report, this seems like a bug in the preview branch. The APIs you're using (rdp_*) are deprecated in that branch and the implementation was rewritten to keep the same API and make it work above the new API (rdpq_*).

I've pushed a fix in the preview branch (6cf2fbc).

rasky commented 8 months ago

Also, we should probably rework or remove the spritemap example from the preview branch.