Homebrew [Release] {beta} sf2dlib - Simple and Fast 2D library (using the GPU)

  • Thread starter Thread starter xerpi
  • Start date Start date
  • Views Views 97,216
  • Replies Replies 501
  • Likes Likes 32
The only problem with that is that I have <0% knowledge with the GPU and 3D (my programs are mostly console-based because of this), so I don't know what to edit :blush:
If you could, could you please point me in the right direction?
this
Code:
matrix_init_orthographic(ortho_matrix_top, 0.0f, 400.0f, 0.0f, 240.0f, 0.0f, 1.0f);
Has to be change to this
Code:
matrix_init_orthographic(ortho_matrix_top, 0.0f, 400.0f, 240.0f, 0.0f, 0.0f, 1.0f);
You might have to change the texture coordinates too
 
  • Like
Reactions: cearp
this
Code:
matrix_init_orthographic(ortho_matrix_top, 0.0f, 400.0f, 0.0f, 240.0f, 0.0f, 1.0f);
Has to be change to this
Code:
matrix_init_orthographic(ortho_matrix_top, 0.0f, 400.0f, 240.0f, 0.0f, 0.0f, 1.0f);
You might have to change the texture coordinates too

Oooh, I'm a stoopid person :P I could just write a wrapper function that does 240 - (y + texheight) :P

But I'll try out your edit at least :P Thanks for helping :D
 
Hmm... it looks like I can't draw large (1200x900) images. It just won't draw at all. Other images (16x16 and 14x30) work well, but this one doesn't.
 
Why can't you rescale it beforehand?
Also, the max. texture resolution for GPU is (probably) 1024x1024px, so you could be better off using a software method for that particular texture.
 
Why can't you rescale it beforehand?
Also, the max. texture resolution for GPU is (probably) 1024x1024px, so you could be better off using a software method for that particular texture.

No, I can't rescale it, it has to be this exact big. Yes, I used framebuffer rendering before, but it's sooo slow, that I switched to sf2dlib. I don't know how well does sf2dlib co-operate with framebuffer rendering, but I'll try it again.

--------------------- MERGED ---------------------------

No, framebuffer rendering outputs grabage, then freezes.
 
No, I can't rescale it, it has to be this exact big. Yes, I used framebuffer rendering before, but it's sooo slow, that I switched to sf2dlib. I don't know how well does sf2dlib co-operate with framebuffer rendering, but I'll try it again.

--------------------- MERGED ---------------------------

No, framebuffer rendering outputs grabage, then freezes.
You can try splitting your huge texture in 4 quadrants, and draw them all separately (as 4 different textures).
 
You can try splitting your huge texture in 4 quadrants, and draw them all separately (as 4 different textures).

I was thinking the same, but I waited instead if there's a workaround, but it looks like there isn't :( Okay, thanks anyways!

Would it be possible to make this a built-in function? I was using framebuffer rendering (crazy mathematical memcpy to fbLeft) that automatically cropped the image for me, but it looks like the stoopid GPU just can't cut it.
 
Last edited by Sono,
I was thinking the same, but I waited instead if there's a workaround, but it looks like there isn't :( Okay, thanks anyways!

Would it be possible to make this a built-in function? I was using framebuffer rendering that automatically cropped the image for me, but it looks like the stoopid GPU just can't cut it.
Well, it should be very easy to do a wrapper function that does the "collage" drawing and cropping by using sf2d_draw_texture_part.
 
Well, it should be very easy to do a wrapper function that does the "collage" drawing and cropping by using sf2d_draw_texture_part.

No, sf2d_draw_texture_part(icn.img, 200, 120, 200, 120, 400, 240); is still not working.
 
Question. Is there a function in libsf2d to find and render an image from a RomFS? All methods that I've known about just require converting specific images in a folder into .bin and .h files, which is all cramming into the ExeFS code files.
 
Question. Is there a function in libsf2d to find and render an image from a RomFS? All methods that I've known about just require converting specific images in a folder into .bin and .h files, which is all cramming into the ExeFS code files.

I have never worked with RomFS, but I guess you could read the image in the ram, convert it to an RGBA array if needed, then give that to sf2d_create_texture_mem_RGBA8

C:
int loadicon(const char* path, IIcon *icon)
{
  size_t bufptr;
  u64 size = 0;
   
  printf("[DRAWER] Loading icon file:\n> %s \n", path);
   
  int res;
   
  res = sdfs_read2buf(path, &size, &bufptr);
   
  if(res)
  {
  printf("[DRAWER] Can't load icon file: %08X \n", res);
  return res;
  }
   
  u8* buf = (u8*)bufptr;
   
  icon->h = buf[0] | buf[1] << 8;
  icon->w = buf[2] | buf[3] << 8;
   
  icon->img = sf2d_create_texture_mem_RGBA8(buf + 4, icon->w, icon->h, TEXFMT_RGBA8, SF2D_PLACE_RAM);
  if(!icon->img)
  {
  printf("[DRAWER] Can't load image, out of memory");
  return -1;
  }
   
  printf("[DRAWER] Image size: %d x %d | %llu \n", icon->w, icon->h, size);
   
  return 0;
}
 
Last edited by Sono,
  • Like
Reactions: Deleted User
I have never worked with RomFS, but I guess you could read the image in the ram, convert it to an RGBA array if needed, then give that to sf2d_create_texture_mem_RGBA8
Thanks. Could you possibly give a sample code? Not that I'm lazy or anything, I just usually get tied up with how to use library functions. ;)
 
Thanks. Could you possibly give a sample code? Not that I'm lazy or anything, I just usually get tied up with how to use library functions. ;)

Declaration:
https://github.com/MarcuzD/MM/tree/gpurender/soos/grafx

Usage:
https://github.com/MarcuzD/MM/blob/gpurender/soos/game/game.c#L211
and
https://github.com/MarcuzD/MM/blob/gpurender/soos/game/game.c#L445

the level_utick function is here: https://github.com/MarcuzD/MM/blob/gpurender/soos/game/level.c#L162

Note: I was using a bottom-up co-ordinate system (x=0 is bottom, x=239 is top), so if you want to use my code, then I recommend to do y = 240 - (y + icn->h);
 
Last edited by Sono,
  • Like
Reactions: Deleted User
I guess https://github.com/xerpi/sfillib can also load images from RomFS.
Hmm.. this is the method I've been actually using. The sample demo looks as if it doesn't load an image from an SD card. It just creates some .h files and links them with the code.

Basically, I'd like to achieve loading images from a folder like this:

SD:
----\PNG_files
--------\1.png
--------\2.png
--------\3.png

or this:

RomFS:
----\PNG_files
--------\1.png
--------\2.png
--------\3.png

(Obviously, it's almost the same thing, but...)
 
Really stupid thing, but when I use sfillib with my PNG images, I get "libpng warning: iCCP: known incorrect sRGB profile" thing... obviously, I'd rather have that not display.
So, Internet magicians told me to use "mogrify *.png" which sure removes the error, but some of the textures (not all though!) are all green and squished horizontally in half.
Any workaround?

/edit/
w/ pngcrush, even if I remove just the sRGB profile, well, it still happens.
 
Last edited by Spaqin,
Really stupid thing, but when I use sfillib with my PNG images, I get "libpng warning: iCCP: known incorrect sRGB profile" thing... obviously, I'd rather have that not display.
So, Internet magicians told me to use "mogrify *.png" which sure removes the error, but some of the textures (not all though!) are all green and squished horizontally in half.
Any workaround?

/edit/
w/ pngcrush, even if I remove just the sRGB profile, well, it still happens.
Update sf2d (make install it again), in theory one of the most recent commits I did should fix that "green and squished horizontally in half" bug.
 
  • Like
Reactions: Spaqin
How does depth rendering funcs work?

I mean, if a smaller object is rendered with a z value bigger then a bigger object, does it get rendered or not in final scene?
depth.png
 
I'm updating some code (Handy3ds) from the lib versions of september 2015 to the last commits on github, but now using sftd, printing with size bigger than 10 results in a blurred string.

I tested it with the font of my last release (Hack.ttf) and with roboto-normal.ttf.

Before
Handy3DS_2.png


After
After.png


The font ins't the same, but I hope the problem i clear. Don' mind for the wrong text positio, it's easy to fix.

Hints?
 
Last edited by nop90,
Hmm.. this is the method I've been actually using. The sample demo looks as if it doesn't load an image from an SD card. It just creates some .h files and links them with the code.

Basically, I'd like to achieve loading images from a folder like this:

SD:
----\PNG_files
--------\1.png
--------\2.png
--------\3.png

or this:

RomFS:
----\PNG_files
--------\1.png
--------\2.png
--------\3.png

(Obviously, it's almost the same thing, but...)
https://github.com/MrJPGames/Othello-3DS/blob/master/source/main.c
It's really messy code, but the part to load textures from ROMFS is just fine.
It's pretty simple really. Just add romfsInit(); (and ofc romfsExit();). Then load the texture like this: sfil_load_PNG_file("romfs:/image.png", SF2D_PLACE_RAM);
 
  • Like
Reactions: cearp

Site & Scene News

Popular threads in this forum