Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hannahbunny opened this issue Mar 4, 2024 · 2 comments
Closed

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

hannahbunny opened this issue Mar 4, 2024 · 2 comments

Comments

@hannahbunny
Copy link

hannahbunny commented Mar 4, 2024

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 added a commit to rasky/libdragon that referenced this issue Mar 9, 2024
The new rdp shim was missing calls to __sprite_upgrade(), that are
necessary to be able to use the new sprite APIs like sprite_get_format
on old sprite files (generated by the old mksprite) and manually
loaded from ROM.

Fixes DragonMinded#503
@rasky
Copy link
Collaborator

rasky commented Mar 9, 2024

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 rasky closed this as completed Mar 9, 2024
@rasky
Copy link
Collaborator

rasky commented Mar 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants