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

  • Thread starter Thread starter xerpi
  • Start date Start date
  • Views Views 97,178
  • Replies Replies 501
  • Likes Likes 32
By "2D library", do you just mean 2D as opposed to 3D scene rendering, or do you mean it doesn't support 3D depth (as in the 3D top screen) either?
 
It draws flat textures and shapes. It has a function to enable/disable stereoscopic mode, so you can use 3D depth on the top screen, I've been doing this manually by offsetting the x positions. There's one texture drawing function that has a depth argument, but I'm not sure what that will do as you draw one side at a time, and I haven't tried it yet as I'm using the function that also has rotation.
 
If i want to compile a programm with this library i got this message

shader.vsh
make[1]: python: Command not found
make[1]: *** [shader.vsh.o] Error 127
make: *** [build] Error 2

can someone help me
 
With the function "sf2d_get_pixel ( sf2d_texture texture * , int x , int y) Gets a pixel of the texture."
What exactly is the color back ? I get the value 35 for transparent. Other values for colors, order it seems that different colors return the same value ...
 
2.png xerpi have resolve my problem on irc, problem came from my code... you can find here a good use of sf2d_get_pixel...

Code:
#include <stdio.h>
#include <3ds.h>
#include <sf2d.h>

touchPosition Stylus;

u32 kDown;
u32 kHeld;

extern const struct {
  unsigned int      width;
  unsigned int      height;
  unsigned int      bytes_per_pixel;
  unsigned char     pixel_data[];
} number_img, colorzone_img;

typedef struct
{
    sf2d_texture * texture;
}
images;
images numbers, colorzone;

int base10_length(u32 number)
{
    int length = 1;
    while (number > 9) {
        length++;
        number /= 10;
    }
    return length;
}

void draw_number_base10(u32 number, u16 posx, u16 posy)
{
    int num_len = base10_length(number);
    u16 cur_posx = posx + (num_len - 1) * 12;

    while (number > 0) {
        u8 digit = number % 10;
        sf2d_draw_texture_part(numbers.texture, cur_posx, posy, digit*8, 0, 8, 10);
        cur_posx -= 12;
        number /= 10;
    }
}


int main()
{
    sf2d_init();
    //sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));

    numbers.texture = sf2d_create_texture(number_img.width, number_img.height, GPU_RGBA8, SF2D_PLACE_RAM);
    sf2d_fill_texture_from_RGBA8(numbers.texture, number_img.pixel_data, number_img.width, number_img.height);
    sf2d_texture_tile32(numbers.texture);

    colorzone.texture = sf2d_create_texture(colorzone_img.width, colorzone_img.height, GPU_RGBA8, SF2D_PLACE_RAM);
    sf2d_fill_texture_from_RGBA8(colorzone.texture, colorzone_img.pixel_data, colorzone_img.width, colorzone_img.height);
    sf2d_texture_tile32(colorzone.texture);

    u32 color = 0;

    while (aptMainLoop()) {

        hidScanInput();
        u32 held = hidKeysHeld();
        if (held & KEY_TOUCH) {
            hidTouchRead(&Stylus);
            color = sf2d_get_pixel(colorzone.texture, Stylus.px, Stylus.py);
        }

        if (held & KEY_START) break;

        sf2d_start_frame(GFX_TOP, GFX_LEFT);
            sf2d_draw_rectangle(0, 0, 400, 240, __builtin_bswap32(color));
        sf2d_end_frame();


        sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
            sf2d_draw_texture(colorzone.texture, 0, 0);
            draw_number_base10(color, 10, 10);
        sf2d_end_frame();


        sf2d_swapbuffers();
    }

    sf2d_free_texture(numbers.texture);
    sf2d_free_texture(colorzone.texture);

    sf2d_fini();
    return 0;
}
 

Attachments

  • Like
Reactions: cearp
Hi,
I have a problem. I wanted to compile the libary + sample. Compiling the libary with "make install" works fine, but when I try to make the sample i get this error.
Code:
linking sf2d_sample.elf
d:/devkitPro/libctru/lib\libsf2d.a(sf2d.o): In function `sf2d_init_advanced':
d:/devkitPro/ctrulib/sf2dlib-master/libsf2d/source/sf2d.c:88: undefined reference to `shader_vsh_shbin_size'
d:/devkitPro/ctrulib/sf2dlib-master/libsf2d/source/sf2d.c:88: undefined reference to `shader_vsh_shbin'
collect2.exe: error: ld returned 1 exit status
make[1]: *** [/d/devkitPro/ctrulib/sf2dlib-master/sample/sf2d_sample.elf] Error
1
make: *** [build] Error 2
Thanks for any help,
-josamilu
 
Can't immediately see where that's from, but is your ctrulib up to date?
Code:
D:\devkitPro\ctrulib\libctru>make install
make[1]: `/d/devkitPro/ctrulib/libctru/lib/libctru.a' is up to date.
mkdir -p /D/devkitPro/libctru
bzip2 -cd libctru-0.5.0.tar.bz2 | tar -x -C /D/devkitPro/libctru
As you can see my ctrulib is up to date, but I still get the error :/

Do I have to compile it on Linux? Because there is this, when I compile the lib :
Code:
shader.vsh
/bin/sh: bin2s: command not found
sf2d.c
(But I still get out the .a file ... :/)
 
Last edited by josamilu,
bin2s is a devkitPro program, so your environment path variables probably aren't set up right. Look at a devkitARM installation guide again.
 
bin2s is a devkitPro program, so your environment path variables probably aren't set up right. Look at a devkitARM installation guide again.

Exactly, his PATH environment variable isn't pointing to the devkitARM/bin folder.
 
Exactly, his PATH environment variable isn't pointing to the devkitARM/bin folder.
My PATH variable was always pointing to the devitARM/bin folder, but in there are a lot of exe s, but no bin2s.exe ?! I tried to update my devkitPro, but there is no aviable update. What can I do? :/
 

Site & Scene News

Popular threads in this forum