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

  • Thread starter Thread starter xerpi
  • Start date Start date
  • Views Views 97,176
  • Replies Replies 501
  • Likes Likes 32
Update: zlib seems to install properly, but freetype gives me a "missing C compiler" sort of message, even with MinGW, GCC and devkitPro/ARM installed.
 
I'm encountering a problem: i succesfully compile and run the sample of SFTDLIB on Citra but on my 3ds it gets stuck on a yellow bottom screen and white top screen. The 3ds doesn't get stuck when it reaches sftd_init(), the program just doesn't start at all if any function of sftd is called into the code. Nothing is wrong with my enviroment and with my sf2dlib installation because i can succesfully compile and run sf2dlib samples on my 3ds. i just don't know where to start.

o3ds with ninjhax 2.5 launched through themehax2, latest ctrulib, sf2dlib and sftdlib from the master branch. It happens indifferently with pre-compiled and compiled portlib. Note that i compiled my code on two different enviroments (windows and linux) and it happened in any case. Any idea?
 
Last edited by Slashcash,
I'm encountering a problem: i succesfully compile and run the sample of SFTDLIB on Citra but on my 3ds it gets stuck on a yellow bottom screen and white top screen. The 3ds doesn't get stuck when it reaches sftd_init(), the program just doesn't start at all if any function of sftd is called into the code. Nothing is wrong with my enviroment and with my sf2dlib installation because i can succesfully compile and run sf2dlib samples on my 3ds. i just don't know where to start.

o3ds with ninjhax 2.5 launched through themehax2, latest ctrulib, sf2dlib and sftdlib from the master branch. It happens indifferently with pre-compiled and compiled portlib. Note that i compiled my code on two different enviroments (windows and linux) and it happened in any case. Any idea?

Can you try this: https://gbatemp.net/threads/release...ary-using-the-gpu.384796/page-15#post-5814887
And then recompile sf2dlib and the sample?
 
i will try but i'm not confident it will work as the problem occurs with sftdlib and not with sf2dlib.

I mean: the program starts and runs normally if i draw a regular texture
 
Last edited by Slashcash,
These are the binaries generated by compiling the sample. I even edited the struct accordingly to the post and makeinstalled sf2dlib and sftdlib all over again. No results.
 

Attachments

These are the binaries generated by compiling the sample. I even edited the struct accordingly to the post and makeinstalled sf2dlib and sftdlib all over again. No results.
It's working here (I've tried with 3dslink). Try updating the Homebrew Launcher version to the latest.
 
Are there any tricks or online resources for improving draw speeds?
I'm trying to draw a large quantity of circles/squares/textures but it it's killing the performance. I think I might be going about this wrong, but I'm just not sure where to look for more information.

I made an example program for testing this with 1500 circles/squares.
https://github.com/Fittings/CircleRenderTest3DS#circlerendertest3ds
This is just calling draw_fill_circle on each circle on each cycle.

Cheers.
 
Are there any tricks or online resources for improving draw speeds?
I'm trying to draw a large quantity of circles/squares/textures but it it's killing the performance. I think I might be going about this wrong, but I'm just not sure where to look for more information.

I made an example program for testing this with 1500 circles/squares.
https://github.com/Fittings/CircleRenderTest3DS#circlerendertest3ds
This is just calling draw_fill_circle on each circle on each cycle.

Cheers.
Does it looks like that running on hardware too?
 
Well, there are ways to improve speed, but none currently compatible with sf2dlib afaik.

Easy way: You could make your own vertex array and include all objects, making only one draw call. Still requires a lot of CPU to generate the array and calculate positioning, but less time and less redundant calls.

Hard way: If everything drawn is relatively identical, using a geometry shader would probably be best. Instead of passing all vertices calculated yourself, you can essentially pass one "vertex" per object and have the shader generate the object vertices around it. You could even pass color or partial texcoords with the position to get variation. I haven't tested, but you can probably be sure that the shader/GPU will process this stuff faster than CPU. But shader scripts aren't the easiest thing to write, I probably wouldn't bother if you're using trig functions, maybe just use predefined trig values in shader constants or something.
 
  • Like
Reactions: Fittings
Well, there are ways to improve speed, but none currently compatible with sf2dlib afaik.

Easy way: You could make your own vertex array and include all objects, making only one draw call. Still requires a lot of CPU to generate the array and calculate positioning, but less time and less redundant calls.

Hard way: If everything drawn is relatively identical, using a geometry shader would probably be best. Instead of passingwill process this stuff faster than CPU. But shader scripts aren't the easiest thing to write, I probably all vertices calculated yourself, you can essentially pass one "vertex" per object and have the shader generate the object vertices around it. You could even pass color or partial texcoords with the position to get variation. I haven't tested, but you can probably be sure that the shader/GPU wouldn't bother if you're using trig functions, maybe just use predefined trig values in shader constants or something.

Thanks, this is a great response.
At the moment I'm at square one with understanding how shaders work. This is a bit over my head at the moment, but it gives me a good starting point for things to read up on.,

Is this similar enough to openGL that I should be checking for info on openGL topics?
 
Thanks, this is a great response.
At the moment I'm at square one with understanding how shaders work. This is a bit over my head at the moment, but it gives me a good starting point for things to read up on.,

Is this similar enough to openGL that I should be checking for info on openGL topics?
The concepts are the same if you want to learn about geometry shaders or shaders in general. And the concepts around vertices are the same too. The scripting languages are obviously different.

Here's a geometry shader example: https://github.com/smealum/ctrulib/blob/master/examples/graphics/gpu/geoshader/source/gshader.pica

It passes just 3 vertices (position & color): https://github.com/smealum/ctrulib/blob/master/examples/graphics/gpu/geoshader/source/main.c#L17

And it makes 3 triangles with those vertices (a triforce in this case). Making circles could be a pain in the ass, like I said because of the trigs functions, but you can precompute those as constants.

Unless all the circles are important, I wouldn't bother. But if you're making some sort of particle effect, it would be useful. The GPU on the 3ds has a special particle feature (or "gaseous" objects) but it's not completely known how to use it yet.
 
Last edited by TheCruel,
  • Like
Reactions: Fittings
I have a problem with sftdlib.
When i try to draw an image or something other, into the same frame, i want to draw text in, it will compile correctly, but if i start the homebrew, i get just black screen. But if i draw only text to the top screen, and an image to the bottom one, it works flawlessly. Any help?

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <3ds.h>
#include <sf2d.h>
#include <sfil.h>
#include <sftd.h>

#include "FreeSans_ttf.h"

#include "citra_jpeg.h"
#include "3dbrew_png.h"

int main()
{
    // Set the random seed based on the time
    srand(time(NULL));

    sf2d_init();
    sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));
   
    sf2d_texture *tex1 = sfil_load_JPEG_buffer(citra_jpeg, citra_jpeg_size, SF2D_PLACE_RAM);
    sf2d_texture *tex2 = sfil_load_PNG_buffer(_3dbrew_png, SF2D_PLACE_RAM);
   
    sftd_init();
    sftd_font *font = sftd_load_font_mem(FreeSans_ttf, FreeSans_ttf_size);

    u32 held;

    while (aptMainLoop()) {

        hidScanInput();
        held = hidKeysHeld();

        if (held & KEY_START) {
            break;
        }

        sf2d_start_frame(GFX_TOP, GFX_LEFT);
           
            sftd_draw_textf(font, 10, 10, RGBA8(0, 255, 0, 255), 20, "FPS %f", sf2d_get_fps());
            sf2d_draw_texture(tex1, 400/2 - tex1->width/2, 240/2 - tex1->height/2);
        sf2d_end_frame();

        sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
            sf2d_draw_texture(tex2, 320/2 - tex2->width/2, 240/2 - tex2->height/2);
        sf2d_end_frame();

        sf2d_swapbuffers();
    }
   
    sftd_free_font(font);
    sftd_fini();

    sf2d_free_texture(tex1);
    sf2d_free_texture(tex2);

    sf2d_fini();
    return 0;
}
 
I have a problem with sftdlib.
When i try to draw an image or something other, into the same frame, i want to draw text in, it will compile correctly, but if i start the homebrew, i get just black screen. But if i draw only text to the top screen, and an image to the bottom one, it works flawlessly. Any help?

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <3ds.h>
#include <sf2d.h>
#include <sfil.h>
#include <sftd.h>

#include "FreeSans_ttf.h"

#include "citra_jpeg.h"
#include "3dbrew_png.h"

int main()
{
    // Set the random seed based on the time
    srand(time(NULL));

    sf2d_init();
    sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));
  
    sf2d_texture *tex1 = sfil_load_JPEG_buffer(citra_jpeg, citra_jpeg_size, SF2D_PLACE_RAM);
    sf2d_texture *tex2 = sfil_load_PNG_buffer(_3dbrew_png, SF2D_PLACE_RAM);
  
    sftd_init();
    sftd_font *font = sftd_load_font_mem(FreeSans_ttf, FreeSans_ttf_size);

    u32 held;

    while (aptMainLoop()) {

        hidScanInput();
        held = hidKeysHeld();

        if (held & KEY_START) {
            break;
        }

        sf2d_start_frame(GFX_TOP, GFX_LEFT);
          
            sftd_draw_textf(font, 10, 10, RGBA8(0, 255, 0, 255), 20, "FPS %f", sf2d_get_fps());
            sf2d_draw_texture(tex1, 400/2 - tex1->width/2, 240/2 - tex1->height/2);
        sf2d_end_frame();

        sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
            sf2d_draw_texture(tex2, 320/2 - tex2->width/2, 240/2 - tex2->height/2);
        sf2d_end_frame();

        sf2d_swapbuffers();
    }
  
    sftd_free_font(font);
    sftd_fini();

    sf2d_free_texture(tex1);
    sf2d_free_texture(tex2);

    sf2d_fini();
    return 0;
}

You are calling sf2d_init(); two times here, try removing the second sf2d_init(); call.
 
No, i call sf2d_init(); once and then i call sftd_init(); like in the sftd sample. If i remove sftd_init(); it doesn't work anymore (obviously). But still thanks for your help.
True, sorry I misread it. Can you better explain the problem or link a zip of the code?
 
I have a problem with sftdlib.
When i try to draw an image or something other, into the same frame, i want to draw text in, it will compile correctly, but if i start the homebrew, i get just black screen. But if i draw only text to the top screen, and an image to the bottom one, it works flawlessly. Any help?

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <3ds.h>
#include <sf2d.h>
#include <sfil.h>
#include <sftd.h>

#include "FreeSans_ttf.h"

#include "citra_jpeg.h"
#include "3dbrew_png.h"

int main()
{
    // Set the random seed based on the time
    srand(time(NULL));

    sf2d_init();
    sf2d_set_vblank_wait(0);
    sftd_init();
    sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));

    sf2d_texture *tex1 = sfil_load_JPEG_buffer(citra_jpeg, citra_jpeg_size, SF2D_PLACE_RAM);
    sf2d_texture *tex2 = sfil_load_PNG_buffer(_3dbrew_png, SF2D_PLACE_RAM);

    sftd_font *font = sftd_load_font_mem(FreeSans_ttf, FreeSans_ttf_size);

    u32 held;

    while (aptMainLoop()) {

        hidScanInput();
        held = hidKeysHeld();

        if (held & KEY_START) {
            break;
        }

        sf2d_start_frame(GFX_TOP, GFX_LEFT);
        
            sftd_draw_textf(font, 10, 10, RGBA8(0, 255, 0, 255), 20, "FPS %f", sf2d_get_fps());
            sf2d_draw_texture(tex1, 400/2 - tex1->width/2, 240/2 - tex1->height/2);
        sf2d_end_frame();

        sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
            sf2d_draw_texture(tex2, 320/2 - tex2->width/2, 240/2 - tex2->height/2);
        sf2d_end_frame();

        sf2d_swapbuffers();
    }

    sftd_free_font(font);
    sftd_fini();

    sf2d_free_texture(tex1);
    sf2d_free_texture(tex2);

    sf2d_fini();
    return 0;
}
Try changing the init and fini commands on their place, like this:

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <3ds.h>
#include <sf2d.h>
#include <sfil.h>
#include <sftd.h>

#include "FreeSans_ttf.h"

#include "citra_jpeg.h"
#include "3dbrew_png.h"

int main()
{
    // Set the random seed based on the time
    srand(time(NULL));

    sf2d_init();
    sftd_init();
    sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));

    sf2d_texture *tex1 = sfil_load_JPEG_buffer(citra_jpeg, citra_jpeg_size, SF2D_PLACE_RAM);
    sf2d_texture *tex2 = sfil_load_PNG_buffer(_3dbrew_png, SF2D_PLACE_RAM);

    sftd_font *font = sftd_load_font_mem(FreeSans_ttf, FreeSans_ttf_size);

    u32 held;

    while (aptMainLoop()) {

        hidScanInput();
        held = hidKeysHeld();

        if (held & KEY_START) {
            break;
        }

        sf2d_start_frame(GFX_TOP, GFX_LEFT);
        
            sftd_draw_textf(font, 10, 10, RGBA8(0, 255, 0, 255), 20, "FPS %f", sf2d_get_fps());
            sf2d_draw_texture(tex1, 400/2 - tex1->width/2, 240/2 - tex1->height/2);
        sf2d_end_frame();

        sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
            sf2d_draw_texture(tex2, 320/2 - tex2->width/2, 240/2 - tex2->height/2);
        sf2d_end_frame();

        sf2d_swapbuffers();
    }

    sf2d_free_texture(tex1);
    sf2d_free_texture(tex2);
    sftd_free_font(font);

    sf2d_fini();
    sftd_fini();

    return 0;
}
 
Last edited by lolzvid,
  • Like
Reactions: josamilu

Site & Scene News

Popular threads in this forum