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

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,825
Trophies
2
Location
home
XP
9,376
Country
Hungary

Sage_of_Mirrors

Member
Newcomer
Joined
Jul 30, 2016
Messages
6
Trophies
0
Age
27
XP
53
Country
United States
That's your problem! Since most recent ctrulib versions got rid of "old" GPU functions, it's incompatible with sf2dlib.

Also, if Citro3D requires sf2dlib, then switch the library order: -lcitro3d -lsf2d -lctru -lm

Use this ctrulib for building: https://github.com/smealum/ctrulib/tree/5725ec2dedfffb2ee721dd8cddb3d24c288f452f

Thanks for the quick response, but it seems like that's not the issue. I've replaced my version of ctrulib with the one you gave me, but I still get the same error.

I'm on Windows. I grab the zip from Github, cd Msys to the directory with the makefile, run make, then make install. After this Windows shows that the library files were changed, so they're getting updated. Is there any information I can provide that would help to diagnose the issue?
 

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,825
Trophies
2
Location
home
XP
9,376
Country
Hungary
Thanks for the quick response, but it seems like that's not the issue. I've replaced my version of ctrulib with the one you gave me, but I still get the same error.

I'm on Windows. I grab the zip from Github, cd Msys to the directory with the makefile, run make, then make install. After this Windows shows that the library files were changed, so they're getting updated. Is there any information I can provide that would help to diagnose the issue?

Can you please post the full output of `make`? In a spoiler or a log file? You could redirect the output of make with
Code:
make >stdout.log 2>stderr.log
 

Sage_of_Mirrors

Member
Newcomer
Joined
Jul 30, 2016
Messages
6
Trophies
0
Age
27
XP
53
Country
United States
Can you please post the full output of `make`? In a spoiler or a log file? You could redirect the output of make with
Code:
make >stdout.log 2>stderr.log

Here it is:

c:/devkitPro/libctru/lib\libsf2d.a(sf2d_texture.o): In function `sf2d_texture_tile32_hardware':
c:/Users/[name]/Downloads/sf2dlib-master/sf2dlib-master/libsf2d/source/sf2d_texture.c:95: undefined reference to `C3D_SafeDisplayTransfer'
collect2.exe: error: ld returned 1 exit status
make[1]: *** [/c/Users/[name]/Downloads/sf2dlib-master/sf2dlib-master/sample/sf2d_sample.elf] Error 1
make: *** [build] Error 2
 

Sage_of_Mirrors

Member
Newcomer
Joined
Jul 30, 2016
Messages
6
Trophies
0
Age
27
XP
53
Country
United States
Hmm... then the first time your library order was correct (-lsf2d -lcitro3d -lctru -lm)...

Did you set the include path in your Makefile to include the header files of Citro3D and sf2dlib?

Somehow, at some point, my libcitro3d.a got renamed to libcitro3d-master.a. For some reason, the version that had the correct name wasn't right. Taking off -master from the weird one works! I have no idea how that happened.

In any case, thanks for your help! Are there any plans to update libsf2d to work with the newer versions of libctru?
 

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,825
Trophies
2
Location
home
XP
9,376
Country
Hungary
In any case, thanks for your help! Are there any plans to update libsf2d to work with the newer versions of libctru?

I think there are plans, to try to get it working, but I don't know if it's gonna be successful or not :/

nevermind, it already uses Citro3D :P Then you should be able to use the latest ctruilb :P
 
Last edited by Sono,

Urbanshadow

Well-Known Member
Member
Joined
Oct 16, 2015
Messages
1,578
Trophies
0
Age
33
XP
1,723
Country
I can assure to things to the current topic:
-sf2dlib doesn't need citro3d.h at all
-3ds.h (libctru) and citro3d.h have quite an amount of changes from the one provided by devkitpro

I had to update both to latest commit version just to get signatures of a pair of functions needed by some code of mine.
 

Sage_of_Mirrors

Member
Newcomer
Joined
Jul 30, 2016
Messages
6
Trophies
0
Age
27
XP
53
Country
United States
I can assure to things to the current topic:
-sf2dlib doesn't need citro3d.h at all
-3ds.h (libctru) and citro3d.h have quite an amount of changes from the one provided by devkitpro

I had to update both to latest commit version just to get signatures of a pair of functions needed by some code of mine.


Thanks! I will update my libraries to be safe.

Unfortunately, in my attempts to make a simple game as practice, I've run across an interesting issue. In my program there is this line of code:

Code:
snake->headImage = sf2d_create_texture_mem_RGBA8(snake_head_img.pixel_data, snake_head_img.width, snake_head_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM);

If the program is compiled, built, and run on Citra it will run as intended, but if it's run on actual hardware, it hangs and needs to be manually powered off. I'm just not familiar enough with how sf2d works to know why this is. It's especially weird since Citra will run it, but not the hardware.

snake_head_img is 16x16 and is stored as a .c file. I used GIMP for it. My Snake struct is laid out like this:

Code:
#pragma once
#include <sf2d.h>
#include "snake_segment.h"

typedef struct
{
    unsigned int xPos;
    unsigned int yPos;
    unsigned int facing_dir;
    sf2d_texture *headImage;
} Snake;

void snake_init(Snake* snake);
void snake_tick(Snake* snake);

Code:
#include "snake.h"
#include "images.h"
#include <3ds.h>
#include <sf2d.h>

void snake_init(Snake* snake)
{
    snake->headImage = sf2d_create_texture_mem_RGBA8(snake_head_img.pixel_data, snake_head_img.width, snake_head_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM);
    snake->xPos = 200;
    snake->yPos = 120;
    snake->facing_dir = 1;
}

void snake_tick(Snake* snake)
{
    switch (snake->facing_dir)
    {
    case 0:
        snake->yPos -= 1;
        break;
    case 1:
        snake->xPos += 1;
        break;
    case 2:
        snake->yPos += 1;
        break;
    case 3:
        snake->xPos -= 1;
        break;
    }

    u32 kDown = hidKeysDown();
    if (kDown & KEY_DUP) snake->facing_dir = 0;
    if (kDown & KEY_DRIGHT) snake->facing_dir = 1;
    if (kDown & KEY_DDOWN) snake->facing_dir = 2;
    if (kDown & KEY_DLEFT) snake->facing_dir = 3;

    sf2d_draw_texture(snake->headImage, snake->xPos, snake->yPos);
}

I instantiate a Snake right before I go into snake_init with the statement

Code:
Snake snake;
snake_init(&snake);
 
Last edited by Sage_of_Mirrors,

Urbanshadow

Well-Known Member
Member
Joined
Oct 16, 2015
Messages
1,578
Trophies
0
Age
33
XP
1,723
Country
Thanks so much! That worked.

Why is that? Seems like upping TEX_MIN_SIZE would make things below 64 not work. Why does it make 16x16 textures work?

From experience: 3ds's don't like textures in another sizes rather than powers of 2. It may be critical to remember this since citra displays them perfectly, but in the real system it can show bugged and even crash the system. This is not library dependant.

Squared, power of 2 textures work perfectly on both.
Rectangular, power of 2 textures work on citra, but may not in 3ds (haven't tested).
Arbitrary sized textures work in citra but not on 3ds.

I place my bet on the tiled texture transform for the really strange pica texture buffer.
From what I RE'd on said transform (it's managed by svc right now!) it may be impossible to perform on anything that is not a power of 2.

Edit: Please be aware 16 and 64 are both powers of 2. As is 32 and 8. I'm sure a 32x32 texture will work and is in fact between 16x16 and 64x64.
 
Last edited by Urbanshadow,

xerpi

Well-Known Member
OP
Member
Joined
Dec 25, 2011
Messages
212
Trophies
1
Age
28
Location
Barcelona
XP
1,329
Country
Hey, I'm having some trouble compiling applications that use SF2D.

I have updated Citro3D and libctru to their most recent versions, and it appears that everything should be fine. However, when I try to compile an app, say, the sample included with libsf2d, I get one error:

"Undefined reference to C3D_SafeDisplayTransfer."

My LIBS section of the makefile looks like this:

LIBS := -lsf2d -lcitro3d -lctru -lm​

If I get rid of-lcitro3d, the issue gets worse, with everything having to do with Citro3D giving the undefined error. I'm just at a loss as to what to do, since the chain of #includes should mean that the compiler can find C3D_SafeDisplayTransfer. It can find everything else.

Does anyone have any suggestions?
Are you using the latest citro3d from github https://github.com/fincs/citro3d.git ?
 
  • Like
Reactions: Joel16
D

Deleted User

Guest
Is anyone else getting this error when trying to compile using sfillib?

-------------------------------------------------------------------------------------
/opt/devkitpro/libctru/lib/libsf2d.a(sf2d.o): In function `sf2d_fini':
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:95: undefined reference to `C3D_Fini'
/opt/devkitpro/libctru/lib/libsf2d.a(sf2d.o): In function `sf2d_start_frame_target':
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:140: undefined reference to `C3D_FrameDrawOn'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:136: undefined reference to `C3D_FrameBegin'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:137: undefined reference to `C3D_FVUnifDirty'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:137: undefined reference to `C3D_FVUnif'
/opt/devkitpro/libctru/lib/libsf2d.a(sf2d.o): In function `sf2d_swapbuffers':
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:154: undefined reference to `C3D_FrameEnd'
/opt/devkitpro/libctru/lib/libsf2d.a(sf2d.o): In function `sf2d_init_advanced':
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:45: undefined reference to `C3D_Init'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:52: undefined reference to `C3D_RenderTargetSetOutput'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:53: undefined reference to `C3D_RenderTargetSetOutput'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:54: undefined reference to `C3D_RenderTargetSetOutput'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:70: undefined reference to `C3D_BindProgram'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:71: undefined reference to `C3D_CullFace'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:72: undefined reference to `C3D_DepthTest'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:85: undefined reference to `C3D_BoolUnifs'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d.c:85: undefined reference to `C3D_BoolUnifsDirty'
/opt/devkitpro/libctru/lib/libsf2d.a(sf2d_texture.o): In function `sf2d_create_texture':
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:34: undefined reference to `C3D_TexInit'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:44: undefined reference to `C3D_TexSetWrap'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:36: undefined reference to `C3D_TexInitVRAM'
/opt/devkitpro/libctru/lib/libsf2d.a(sf2d_texture.o): In function `sf2d_create_rendertarget':
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:53: undefined reference to `C3D_RenderTargetCreate'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:60: undefined reference to `Mtx_OrthoTilt'
/opt/devkitpro/libctru/lib/libsf2d.a(sf2d_texture.o): In function `sf2d_free_texture':
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:67: undefined reference to `C3D_TexDelete'
/opt/devkitpro/libctru/lib/libsf2d.a(sf2d_texture.o): In function `sf2d_clear_target':
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:81: undefined reference to `C3D_RenderTargetSetClear'
/opt/devkitpro/libctru/lib/libsf2d.a(sf2d_texture.o): In function `sf2d_bind_texture':
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:143: undefined reference to `C3D_TexBind'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:145: undefined reference to `C3D_GetTexEnv'
/opt/devkitpro/libctru/lib/libsf2d.a(sf2d_texture.o): In function `sf2d_draw_texture_part_scale_generic':
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:476: undefined reference to `C3D_GetAttrInfo'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:477: undefined reference to `AttrInfo_Init'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:478: undefined reference to `AttrInfo_AddLoader'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:479: undefined reference to `AttrInfo_AddLoader'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:481: undefined reference to `C3D_GetBufInfo'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:482: undefined reference to `BufInfo_Init'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:483: undefined reference to `BufInfo_Add'
/home/fluffy/Documents/3ds_homebrew/lib/sf2dlib/libsf2d/source/sf2d_texture.c:485: undefined reference to `C3D_DrawArrays'
collect2: error: ld returned 1 exit status
-------------------------------------------------------------------------------------

My Makefile contains these libs:

LIBS := -lcitro3d -lsfil -lpng -ljpeg -lz -lsf2d -lctru -lm

How would one go about solving this? Does this have anything to do with sf2dlib switching over to citro3d?
 
Last edited by ,

sLevin

New Member
Newbie
Joined
Aug 13, 2016
Messages
4
Trophies
0
Age
31
XP
41
Country
Gambia, The
Hi, great library. Nevertheless I am stuck at a problem with rendering a map. My question is: Is it possible to render textures on something like a canvas? I looked at the documentation and could not really find anything. Am I missing something here?
 

machinamentum

Well-Known Member
Member
Joined
Jul 5, 2015
Messages
163
Trophies
0
XP
549
Country
United States
Hi, great library. Nevertheless I am stuck at a problem with rendering a map. My question is: Is it possible to render textures on something like a canvas? I looked at the documentation and could not really find anything. Am I missing something here?
What do you mean like a canvas? You can render a texture onto any geometry so long as your coordinates are correct. Or are you trying to render to a texture? In which case, you can just reuse the framebuffer as a texture when you're done rendering to it.
 

sLevin

New Member
Newbie
Joined
Aug 13, 2016
Messages
4
Trophies
0
Age
31
XP
41
Country
Gambia, The
What do you mean like a canvas? You can render a texture onto any geometry so long as your coordinates are correct. Or are you trying to render to a texture? In which case, you can just reuse the framebuffer as a texture when you're done rendering to it.
Basicly I want to render my map on a texture so that I get a texture e.g. the size of 600*600 and then tell sf2d show me the map starting at (200, 240) to (600, 480).
 

Urbanshadow

Well-Known Member
Member
Joined
Oct 16, 2015
Messages
1,578
Trophies
0
Age
33
XP
1,723
Country
Basicly I want to render my map on a texture so that I get a texture e.g. the size of 600*600 and then tell sf2d show me the map starting at (200, 240) to (600, 480).

You may want to set the viewport to native resolution (400x240) load the texture in native resolution (512x512), draw it into a 600x600 quad, and move the view to (200,240) or whatever position the player is. If you plan making bigger map sizes I suggest you to think about an occlusion algorithm (to load just the part the player can view).
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    K3Nv2 @ K3Nv2: I really don't want to buy this fap tab...