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

Urbanshadow

Well-Known Member
Member
Joined
Oct 16, 2015
Messages
1,578
Trophies
0
Age
33
XP
1,723
Country
I'm not getting very definited borders in 3d mode with images loaded with libsfil. It's a known issue or it's my fault?
The X displacement for my stereo pair ranges from 0 to 10 pixels (increasing on the GFX_LEFT) depending on the 3d slider state.
I am seeing ghostly edges in the x axis for an alpha enabled png loaded with libsfil.
Sorry but I'm getting my post again, I need to nail the 3d for a project I'm working on.
 

xerpi

Well-Known Member
OP
Member
Joined
Dec 25, 2011
Messages
212
Trophies
1
Age
28
Location
Barcelona
XP
1,329
Country
Probably H flip and V flip to mirror the texture.

Compiles made by this commit are crashing but d9147df works fine. It seems to be the new "int tex_filters" in the struct, I had to move it to the end of the struct to get anything to run. I converted it to u32 for good measure too.

Edit: is it just me or are the filters pretty useless? There's not much difference between them that I can notice.

Edit 2: Forget that, I see what elhobbs was saying now. You need to send the other params along with the min mag filters.

eg.
rename to params
changed from int to u32

sf2d_texture_set_tex_filters(sf2d_texture *texture, u32 filters)
texture->tex_filters =

so you use it like this:

sf2d_texture_set_tex_params(tex,GPU_TEXTURE_MAG_FILTER(GPU_LINEAR)| GPU_TEXTURE_MIN_FILTER(GPU_LINEAR)|GPU_TEXTURE_WRAP_S(GPU_REPEAT)|GPU_TEXTURE_WRAP_T(GPU_REPEAT))

It's MUCH nicer for scaling old DS games up from 256*192 but I now need to render to a temp buffer as the alignment goes out a bit when I scale. I think it's because you convert from a float for scale into sizes then back into a float so it's losing data. I'd actually prefer if we could send width and height in px instead of a float as they tend to add decimals randomly.

You are right I was missing the texture wrapping bits. I've just corrected it.
I've also changed the default wrapping to clamp to border.

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

You can use the scaling function and pass negative values to it (this will mirror the image), or you can use the sf2d_draw_quad_uv function to have more control about how the image will be drawn.

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

Sorry but I'm getting my post again, I need to nail the 3d for a project I'm working on.
Try now, I've changed the default texture wrapping to GPU_CLAMP_TO_BORDER.
 
Last edited by xerpi,

xerpi

Well-Known Member
OP
Member
Joined
Dec 25, 2011
Messages
212
Trophies
1
Age
28
Location
Barcelona
XP
1,329
Country
Still the same.

Attached test code.
That's weird, your PNG crashed, but I've tried with another PNG and it works. Try resaving your png with GIMP or something similar.

Also, sf2d_swapbuffers() already does the vblank wait (so you can remove the gspWaitForVBlank(); call) unless you disable it with sf2d_set_vblank_wait(0);
 
Last edited by xerpi,

retrohead

Well-Known Member
Member
Joined
May 2, 2003
Messages
278
Trophies
0
Location
Manchester
Website
www.ds-scene.net
XP
593
Country
So I updated and I can't run my compiled binaries again. I've had to move the u32 params to the end of the struct else my 3DS and citra both freeze up. Citra throws unmapped memory errors.

I've seen this a before but it seemed to rectify itself when I tested updating my libs 2 days ago. Any ideas why it's doing this? I'd rather not change stuff like this all the time.

Code:
typedef struct {
    sf2d_place place;          /**< Where the texture data resides, RAM or VRAM */
    int tiled;                 /**< Whether the tetxure is tiled or not */
    sf2d_texfmt pixel_format;  /**< Pixel format */
    int width;                 /**< Texture width */
    int height;                /**< Texture height */
    int pow2_w;                /**< Nearest power of 2 >= width */
    int pow2_h;                /**< Nearest power of 2 >= height */
    int data_size;             /**< Size of the raw texture data */
    void *data;                /**< Pointer to the data */
    u32 params;                /**< Texture filters and wrapping */ <<< ---- HAVE TO MOVE IT HERE ELSE CRASHES
} sf2d_texture;
 

machinamentum

Well-Known Member
Member
Joined
Jul 5, 2015
Messages
163
Trophies
0
XP
549
Country
United States
So I updated and I can't run my compiled binaries again. I've had to move the u32 params to the end of the struct else my 3DS and citra both freeze up. Citra throws unmapped memory errors.

I've seen this a before but it seemed to rectify itself when I tested updating my libs 2 days ago. Any ideas why it's doing this? I'd rather not change stuff like this all the time.

Code:
typedef struct {
    sf2d_place place;          /**< Where the texture data resides, RAM or VRAM */
    int tiled;                 /**< Whether the tetxure is tiled or not */
    sf2d_texfmt pixel_format;  /**< Pixel format */
    int width;                 /**< Texture width */
    int height;                /**< Texture height */
    int pow2_w;                /**< Nearest power of 2 >= width */
    int pow2_h;                /**< Nearest power of 2 >= height */
    int data_size;             /**< Size of the raw texture data */
    void *data;                /**< Pointer to the data */
    u32 params;                /**< Texture filters and wrapping */ <<< ---- HAVE TO MOVE IT HERE ELSE CRASHES
} sf2d_texture;
Are you recompiling sf2dlib as well? When ever you change a struct, you should recompile and re-install sf2dlib. If your code tries to access a different version of the struct that sf2dlib is compiled with, you'll get segmentation faults from values being modified in the wrong places in memory (like overwriting void*data with an arbitrary value).
 

Urbanshadow

Well-Known Member
Member
Joined
Oct 16, 2015
Messages
1,578
Trophies
0
Age
33
XP
1,723
Country
That's weird, your PNG crashed, but I've tried with another PNG and it works. Try resaving your png with GIMP or something similar.

Also, sf2d_swapbuffers() already does the vblank wait (so you can remove the gspWaitForVBlank(); call) unless you disable it with sf2d_set_vblank_wait(0);

I changed the image and it's working perfectly as you say. That's definetly weird. Thanks for the vblank hint!

Q: How comes theres not sf2d_draw_texture_rotate_scale() but there's a sf2d_draw_texture_part_rotate_scale() ? (Not complaining, just curious)
 
Last edited by Urbanshadow,

retrohead

Well-Known Member
Member
Joined
May 2, 2003
Messages
278
Trophies
0
Location
Manchester
Website
www.ds-scene.net
XP
593
Country
Are you recompiling sf2dlib as well? When ever you change a struct, you should recompile and re-install sf2dlib. If your code tries to access a different version of the struct that sf2dlib is compiled with, you'll get segmentation faults from values being modified in the wrong places in memory (like overwriting void*data with an arbitrary value).
Yes I recompiled with a make clean first. It works when I change the struct which is really odd. I'll try deleting my sf2d folder and start fresh from the latest commit.

Thanks
 

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,032
Country
United States
Yes I recompiled with a make clean first. It works when I change the struct which is really odd. I'll try deleting my sf2d folder and start fresh from the latest commit.

Thanks
You would need to make sf2d before compiling you project. And possibly install it too.
 

retrohead

Well-Known Member
Member
Joined
May 2, 2003
Messages
278
Trophies
0
Location
Manchester
Website
www.ds-scene.net
XP
593
Country
You would need to make sf2d before compiling you project. And possibly install it too.
Not possibly install it, definitely install it!

I deleted my sf2d folder and re-downloaded the latest commit (a8fb32a) but it still fails in citra and on my 3ds. I attached from screenshot of citra but I'm not sure if it will help much. The error goes on forever.

upload_2015-11-19_20-35-9.png

Like I said before, if I change the position of the params to the end of the texture struct and recompile, everything works again. I tested the pointer to the data and I moved it to the start of the struct after moving the params to the end and that has the same issue. Is there a bug with the data pointer in texture struct maybe?

I also had the same problem when I first set up the dev environment on the previous page of this thread so I was using an old version of sf2d to get by. It resolved itself with d9147df
 
Last edited by retrohead,

xerpi

Well-Known Member
OP
Member
Joined
Dec 25, 2011
Messages
212
Trophies
1
Age
28
Location
Barcelona
XP
1,329
Country
Not possibly install it, definitely install it!

I deleted my sf2d folder and re-downloaded the latest commit (a8fb32a) but it still fails in citra and on my 3ds. I attached from screenshot of citra but I'm not sure if it will help much. The error goes on forever.

View attachment 30042

Like I said before, if I change the position of the params to the end of the texture struct and recompile, everything works again. I tested the pointer to the data and I moved it to the start of the struct after moving the params to the end and that has the same issue. Is there a bug with the data pointer in texture struct maybe?

I also had the same problem when I first set up the dev environment on the previous page of this thread so I was using an old version of sf2d to get by. It resolved itself with d9147df

Weird, it's working here :/ Can you upload the code you are trying?
 

lolzvid

Well-Known Member
Member
Joined
Dec 26, 2014
Messages
148
Trophies
0
Age
22
XP
278
Country
Brazil
I'm currently having some difficulties with libsftd, since I can't install portlibs nor zlib (all info that I've found about installing them is for Linux, and I'm currently running Windows 10)...

Any other way to display text with sf2d without any problems on Windows?
 

retrohead

Well-Known Member
Member
Joined
May 2, 2003
Messages
278
Trophies
0
Location
Manchester
Website
www.ds-scene.net
XP
593
Country
Weird, it's working here :/ Can you upload the code you are trying?

It does it with the sample too for me. About all I can do is to send you the compiled binary that doesn't work which would need reverse engineering against one that does work to see what is different.

I'm currently having some difficulties with libsftd, since I can't install portlibs nor zlib (all info that I've found about installing them is for Linux, and I'm currently running Windows 10)...

Any other way to display text with sf2d without any problems on Windows?

I'm using win7 and managed to install the portlibs. It took a while to find something that worked properly and it took a few attempts to do it. Maybe this is my problem and something in the portlibs didn't install properly.

Try messing about with these, it eventually worked for me:

https://gbatemp.net/threads/can-someone-zip-the-3ds-portlibs-for-me.392966/#post-5577623
https://github.com/xerpi/3ds_portlibs
 
  • Like
Reactions: lolzvid

lolzvid

Well-Known Member
Member
Joined
Dec 26, 2014
Messages
148
Trophies
0
Age
22
XP
278
Country
Brazil
It does it with the sample too for me. About all I can do is to send you the compiled binary that doesn't work which would need reverse engineering against one that does work to see what is different.



I'm using win7 and managed to install the portlibs. It took a while to find something that worked properly and it took a few attempts to do it. Maybe this is my problem and something in the portlibs didn't install properly.

Try messing about with these, it eventually worked for me:

https://gbatemp.net/threads/can-someone-zip-the-3ds-portlibs-for-me.392966/#post-5577623
https://github.com/xerpi/3ds_portlibs
After three hours of installing...

0jXT3Z9.png


Did it installed correctly? It created all the folders from the portlibs.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    SylverReZ @ SylverReZ: Or Genesis.