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

EventAssistant

Well-Known Member
Member
Joined
Jul 20, 2016
Messages
572
Trophies
0
XP
1,436
Country
Italy
Sometimes I get a flickering while reloading both screens, I don't know yet why it does it. I'm only swap buffers after I close both topscreen and bottomscreen frames.

Edit: I fixed the issue giving 1 to wait_for_vblank instead of 0. The last issue I have is that sometimes text appears to be glitched.
 
Last edited by EventAssistant,

nop90

Well-Known Member
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,023
Country
Italy
Has anyone tried using "part_scale" functions? On citra I get nothing rendered instead of the texture and on hardware I get this beautiful crash

Code:
sf2d_draw_texture_part_scale(botBg, 30, 10, 40, 0, 40, 20, 16 / 40, 23 / 20);
    sf2d_draw_texture_part_rotate_scale(botBg, 30, 10, 0, 40, 0, 40, 20, 16 / 40, 23 / 20);

try this way

Code:
sf2d_draw_texture_part_scale(botBg,30,10,40,0,40,20,16.0/40.0,23.0/20.0);
sf2d_draw_texture_part_rotate_scale(botBg,30,10,0,40,0,40,20,16.0/40.0,23.0/20.0);
 
  • Like
Reactions: cearp

GoodraIsBae9

Member
Newcomer
Joined
Oct 19, 2016
Messages
14
Trophies
0
Location
Lurking through the ceiling hole
XP
33
Country
try this way

Code:
sf2d_draw_texture_part_scale(botBg,30,10,40,0,40,20,16.0/40.0,23.0/20.0);
sf2d_draw_texture_part_rotate_scale(botBg,30,10,0,40,0,40,20,16.0/40.0,23.0/20.0);
Can't believe I spent 3 hours trying to figure out what was the issue and the fix being so simple... Thanks!

Isn't the compiler supposed to be smart enough to convert numerics on function calls or am I missing something here?
 

nop90

Well-Known Member
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,023
Country
Italy
Can't believe I spent 3 hours trying to figure out what was the issue and the fix being so simple... Thanks!

Isn't the compiler supposed to be smart enough to convert numerics on function calls or am I missing something here?

The copiler rounds to an int a division by two int values, and a constant numeral without a decimal point is an int.

But don't worry too much, I knew the solution because I spent a lot of time debugging the some issue too. :rofl2:
 

RocketRobz

Stylish TWiLight Hero
Developer
Joined
Oct 1, 2010
Messages
15,852
Trophies
3
Age
23
XP
19,510
Country
United States
For some reason, this line of code is stopping my app (in TWLoader, but music still plays).
Code:
sf2d_create_texture_mem_RGBA8(&textureData, 32, 32, TEXFMT_RGBA8, SF2D_PLACE_RAM);
Why is that?
 

xerpi

Well-Known Member
OP
Member
Joined
Dec 25, 2011
Messages
212
Trophies
1
Age
27
Location
Barcelona
XP
1,283
Country
For some reason, this line of code is stopping my app (in TWLoader, but music still plays).
Code:
sf2d_create_texture_mem_RGBA8(&textureData, 32, 32, TEXFMT_RGBA8, SF2D_PLACE_RAM);
Why is that?
This create a sf2d_texture from your already existing data, so the first parameter must be a valid pointer to raw RGBA8 image data.
 

RocketRobz

Stylish TWiLight Hero
Developer
Joined
Oct 1, 2010
Messages
15,852
Trophies
3
Age
23
XP
19,510
Country
United States
This create a sf2d_texture from your already existing data, so the first parameter must be a valid pointer to raw RGBA8 image data.
textureData is already valid. It's declared as
Code:
u32 textureData[1024];
if that matters.

Here's the code. The line that stops the app is commented "Stops TWLoader for some reason".
 
Last edited by RocketRobz,

catlover007

Developer
Developer
Joined
Oct 23, 2015
Messages
711
Trophies
1
XP
3,547
Country
Germany
textureData is allocated on the stack, the address gets invalid when textureData goes out of scope(when the function returns) and 4kb is alot of memory, maybe it just doesn't fit on the stack

EDIT: of course gets textureData copied to a new texture, forget the first answer
EDIT 2: After looking into the source code of sf2d I found what's very likely the error. The hardware tiling doesn't work with small textures(like 32*32). Try to generate a larger picture and use a subset of it
 
Last edited by catlover007,

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,654
Trophies
2
Location
rehabilitation center
XP
8,219
Country
Hungary
textureData is allocated on the stack, the address gets invalid when textureData goes out of scope(when the function returns) and 4kb is alot of memory, maybe it just doesn't fit on the stack

EDIT: of course gets textureData copied to a new texture, forget the first answer
EDIT 2: After looking into the source code of sf2d I found what's very likely the error. The hardware tiling doesn't work with small textures(like 32*32). Try to generate a larger picture and use a subset of it

that array consumes 0x1000 bytes from the stack while the normal stacksize is 0x8000, so it should fit just fine.
also, that should work with old sf2d, but as you said, the hardware-based tiler needs a texture with a minimum size of 64x
 

StuntHacks

Well-Known Member
Newcomer
Joined
Jan 19, 2017
Messages
46
Trophies
0
Age
23
Location
Vienna
XP
217
Country
Austria
So, I'm playing around with homebrew lately and then saw this library. It's awesome and everything works perfectly. But I have a weird problem with the stereoscopic 3D effect:
The effect works as intended but I can't only see the elevated image, I can also see both of the images the 3DS draws. So it's like, I see the 3D image but also the two non-3D images, even though I can only see them very weak but on both eyes. I don't know if you get what I mean but it's hard to explain.

Is there a way to fix that? Or can't we just make better 3D yet?

EDIT: Here is my code:
Code:
#include <3ds.h>
#include <sf2d.h>
#include <stdio.h>
#include <string.h>

#define CONFIG_3D_SLIDERSTATE (*(volatile float*)0x1FF81080)

#define WIDTH 400
#define HEIGHT 240
#define SCREEN_SIZE WIDTH * HEIGHT * 2
#define BUF_SIZE SCREEN_SIZE * 2

extern const struct images
{
    unsigned int      width;
    unsigned int      height;
    unsigned int      bytes_per_pixel;
    unsigned char     pixel_data[];
} logo, background;

int main()
{
    sf2d_init();     
    sf2d_set_3D(true);
    sf2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0x00));

    float offset = 0;
    
    sf2d_texture *sfBackground  = sf2d_create_texture_mem_RGBA8(background.pixel_data, background.width, background.height, TEXFMT_RGBA8, SF2D_PLACE_RAM);
    sf2d_texture *sfShip  = sf2d_create_texture_mem_RGBA8(logo.pixel_data, logo.width, logo.height, TEXFMT_RGBA8, SF2D_PLACE_RAM);
    
    while (aptMainLoop()) {
        offset = CONFIG_3D_SLIDERSTATE * 10;
    
        hidScanInput();
        if (hidKeysDown() & KEY_START) break;
                
        sf2d_start_frame(GFX_TOP, GFX_LEFT); // render for left eye
                sf2d_draw_texture(sfBackground, 0, 0);
                sf2d_draw_texture(sfShip, 80, 30);
        sf2d_end_frame();
        
        sf2d_start_frame(GFX_TOP, GFX_RIGHT); // render for right eye
            sf2d_draw_texture(sfBackground, 0, 0);
            sf2d_draw_texture(sfShip, 80 - offset, 30);
        sf2d_end_frame();

        sf2d_swapbuffers();
    }

    sf2d_fini();
    return 0;
}
 
Last edited by StuntHacks,

Manurocker95

Game Developer & Pokémon Master
Member
Joined
May 29, 2016
Messages
1,515
Trophies
0
Age
28
Location
Madrid
Website
manuelrodriguezmatesanz.com
XP
2,602
Country
Spain
Yo! I'm messing with hb stuff recently and I got installed sf2d and sfil libs without problems (once i got the portlibs installed) but Sfil lib seems not to work when using sfil_load_PNG_file. I know that's the problem because whenever I comment that line, the hb compiles.

I get this error on Visual Studio:

c:/devkitPro/libctru/lib\libsfil.a(sfil_png.o): In function `_sfil_read_png_file_fn':
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:11: undefined reference to `png_get_io_ptr'
1> c:/devkitPro/libctru/lib\libsfil.a(sfil_png.o): In function `_sfil_load_PNG_generic':
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:24: undefined reference to `png_create_read_struct'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:29: undefined reference to `png_create_info_struct'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:36: undefined reference to `png_set_longjmp_fn'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:37: undefined reference to `png_destroy_read_struct'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:43: undefined reference to `png_set_read_fn'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:44: undefined reference to `png_set_sig_bytes'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:45: undefined reference to `png_read_info'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:50: undefined reference to `png_get_IHDR'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:57: undefined reference to `png_set_expand'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:79: undefined reference to `png_get_valid'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:85: undefined reference to `png_read_update_info'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:102: undefined reference to `png_read_image'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:104: undefined reference to `png_destroy_read_struct'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:113: undefined reference to `png_destroy_info_struct'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:115: undefined reference to `png_destroy_read_struct'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:83: undefined reference to `png_set_packing'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:55: undefined reference to `png_get_valid'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:77: undefined reference to `png_set_expand_gray_1_2_4_to_8'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:80: undefined reference to `png_set_tRNS_to_alpha'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:68: undefined reference to `png_set_gray_to_rgb'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:64: undefined reference to `png_set_filler'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:61: undefined reference to `png_set_scale_16'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:72: undefined reference to `png_set_palette_to_rgb'
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:73: undefined reference to `png_set_filler'
1> c:/devkitPro/libctru/lib\libsfil.a(sfil_png.o): In function `sfil_load_PNG_file':
1> c:/Users/Usuario/Desktop/3DS/sfillib-master/libsfil/source/sfil_png.c:134: undefined reference to `png_sig_cmp'
1>collect2.exe : error : ld returned 1 exit status

I have LibPng installed too. Do I need something else? :(
 

catlover007

Developer
Developer
Joined
Oct 23, 2015
Messages
711
Trophies
1
XP
3,547
Country
Germany
You forgot to tell the linker that it should link your project with libpng.

Add after -lsf2d(in the line which begins with LIBS := ) in your makefile
Code:
-lpng -lz

And double check if the line beginning with LIBDIRS is
Code:
LIBDIRS   := $(CTRULIB) $(PORTLIBS)
 

Manurocker95

Game Developer & Pokémon Master
Member
Joined
May 29, 2016
Messages
1,515
Trophies
0
Age
28
Location
Madrid
Website
manuelrodriguezmatesanz.com
XP
2,602
Country
Spain
You forgot to tell the linker that it should link your project with libpng.

Add after -lsf2d(in the line which begins with LIBS := ) in your makefile
Code:
-lpng -lz

And double check if the line beginning with LIBDIRS is
Code:
LIBDIRS   := $(CTRULIB) $(PORTLIBS)

I was missing that. Thanks!
 

Manurocker95

Game Developer & Pokémon Master
Member
Joined
May 29, 2016
Messages
1,515
Trophies
0
Age
28
Location
Madrid
Website
manuelrodriguezmatesanz.com
XP
2,602
Country
Spain
Okay, I got it to compile but whenever I try to draw the image, it keeps in black screen and i dunno what the heck i am doing wrong.

Can someone guide me on what happens, pls?

Code:
#if __INTELLISENSE__
typedef unsigned int __SIZE_TYPE__;
typedef unsigned long __PTRDIFF_TYPE__;
#define __attribute__(q)
#define __builtin_strcmp(a,b) 0
#define __builtin_strlen(a) 0
#define __builtin_memcpy(a,b) 0
#define __builtin_va_list void*
#define __builtin_va_start(a,b)
#define __extension__
#endif

#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif

#include <3ds.h>
#include <sf2d.h>
#include <sfil.h>

int main()
{
    // Apt
    aptInit();

    // SF2D
    sf2d_init();
    sf2d_set_clear_color(RGBA8(0, 0, 0, 0));
    sf2d_set_3D(false);

    sf2d_texture *texture = sfil_load_PNG_file("3ds/data/Project/Art/image.png",SF2D_PLACE_RAM);

    while (aptMainLoop())
    {
        hidScanInput();

       //Salimos pulsando Select
       if (hidKeysDown() & KEY_SELECT)
       {
           break;
       }

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

        sf2d_swapbuffers();
    }

    // Exit services
    aptExit();
    sf2d_fini();

    return 0;
}
 

catlover007

Developer
Developer
Joined
Oct 23, 2015
Messages
711
Trophies
1
XP
3,547
Country
Germany
Okay, I got it to compile but whenever I try to draw the image, it keeps in black screen and i dunno what the heck i am doing wrong.

Can someone guide me on what happens, pls?

Code:
#if __INTELLISENSE__
typedef unsigned int __SIZE_TYPE__;
typedef unsigned long __PTRDIFF_TYPE__;
#define __attribute__(q)
#define __builtin_strcmp(a,b) 0
#define __builtin_strlen(a) 0
#define __builtin_memcpy(a,b) 0
#define __builtin_va_list void*
#define __builtin_va_start(a,b)
#define __extension__
#endif

#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif

#include <3ds.h>
#include <sf2d.h>
#include <sfil.h>

int main()
{
    // Apt
    aptInit();

    // SF2D
    sf2d_init();
    sf2d_set_clear_color(RGBA8(0, 0, 0, 0));
    sf2d_set_3D(false);

    sf2d_texture *texture = sfil_load_PNG_file("3ds/data/Project/Art/image.png",SF2D_PLACE_RAM);

    while (aptMainLoop())
    {
        hidScanInput();

       //Salimos pulsando Select
       if (hidKeysDown() & KEY_SELECT)
       {
           break;
       }

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

        sf2d_swapbuffers();
    }

    // Exit services
    aptExit();
    sf2d_fini();

    return 0;
}
First of all calling aptInit isn't needed anymore. Ctrulib initializes the apt Services anyways. Try to put the alpha value of the clear color to 255, to make it opaque.

Does it crashes, or it is possible to exit the app?
 

Manurocker95

Game Developer & Pokémon Master
Member
Joined
May 29, 2016
Messages
1,515
Trophies
0
Age
28
Location
Madrid
Website
manuelrodriguezmatesanz.com
XP
2,602
Country
Spain
First of all calling aptInit isn't needed anymore. Ctrulib initializes the apt Services anyways. Try to put the alpha value of the clear color to 255, to make it opaque.

Does it crashes, or it is possible to exit the app?
Oh, i see.

It keeps on black screen, but i'm testing on citra. Gonna try on the console.

Edit: It crashes

Edit2: Drawing a rectangle (and not drawing the texture) works. I don't get what i am doing wrong.
 
Last edited by Manurocker95,

catlover007

Developer
Developer
Joined
Oct 23, 2015
Messages
711
Trophies
1
XP
3,547
Country
Germany
Oh, i see.

It keeps on black screen, but i'm testing on citra. Gonna try on the console.

Edit: It crashes

Edit2: Drawing a rectangle (and not drawing the texture) works. I don't get what i am doing wrong.
Try to change the path to sd://3ds/data/Project/Art/image.png
The current path assumes that image.png is located in path where your executable is/3ds/data/Project/Art
I don't think this is the place where have your image

EDIT: sdmc:/ not sd://
 
Last edited by catlover007,
General chit-chat
Help Users
  • No one is chatting at the moment.
  • SylverReZ @ SylverReZ:
    Hope they made lots of spaget
  • K3N1 @ K3N1:
    Chill dog
  • SylverReZ @ SylverReZ:
    Chilli dog
  • Skelletonike @ Skelletonike:
    Damn, I'm loving the new zelda.
  • xtremegamer @ xtremegamer:
    loving the new zelda, i started a game, it was so fucking good, so i
    am waiting on my friend to get home so we can start a new one together
  • Skelletonike @ Skelletonike:
    I just dislike that they don't let me choose the voices before the game starts. Happened with botw as well, had to change to japanese and restart.
  • K3N1 @ K3N1:
    But the important question is can you choose gender
  • Skelletonike @ Skelletonike:
    Same way you can choose Gerald's gender.
  • Skelletonike @ Skelletonike:
    *Geralt, damn autocorrect.
  • Psionic Roshambo @ Psionic Roshambo:
    But can he be trans? Lol
  • K3N1 @ K3N1:
    Zelda transforms into link
  • Psionic Roshambo @ Psionic Roshambo:
    Link I'm not the princess your looking for.... *Pulls a crying game*
  • K3N1 @ K3N1:
    *skirt up* it's exactly what I always wanted
  • Skelletonike @ Skelletonike:
    Just scanned all my zelda amiibos, took a while but didn't get anything that cool, did get the lon lon ranch hylian fabrics though.
  • Skelletonike @ Skelletonike:
    It was pretty funny when I scanned wolf link and got a shit load of meat.
  • K3N1 @ K3N1:
    @Skelletonike, btw I ran that custom for mgs4 on the deck I'm amazed it got that far in game
  • K3N1 @ K3N1:
    Plug in*
  • K3N1 @ K3N1:
    Your favorite activity
  • BentlyMods @ BentlyMods:
    My fav actvity is:

    mario-dancing.gif
  • Psionic Roshambo @ Psionic Roshambo:
    Do the Mario lol
  • K3N1 @ K3N1:
    🍑
  • K3N1 @ K3N1:
    Whoever developed Bramble was smoking that good shit fucking gnomes
    K3N1 @ K3N1: Whoever developed Bramble was smoking that good shit fucking gnomes