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

Davideesk

Well-Known Member
Newcomer
Joined
Aug 19, 2015
Messages
67
Trophies
0
Age
27
XP
395
Country
United States
Can someone tell me how to use sf2d_set_pixel()? It's producing some weird results for me.

...

I've used sf2d_get_pixel() on textures and it works perfectly fine. I don't know if I am doing something wrong or if it is a bug with this function.

Alright, so playing around a bit I found out the issue. It seems you can't use sf2d_set_pixel function with a blank texture that was created with the sf2d_create_texture function. I am now importing a blank PNG image and now the function works perfectly.
 

MRJPGames

Pretty great guy
Member
Joined
Aug 17, 2013
Messages
1,199
Trophies
1
Location
The Netherlands
Website
fizazy.com
XP
1,676
Country
Netherlands
Alright, so playing around a bit I found out the issue. It seems you can't use sf2d_set_pixel function with a blank texture that was created with sf2d_create_texture function. I am now importing a blank PNG image and now the function works perfectly.
Ok, sounds like something that should be fixed though.
 

dfsa3fdvc1

Well-Known Member
Member
Joined
Jan 3, 2015
Messages
226
Trophies
0
XP
214
Country
Albania
for sf2dlib ty a "make clean" before the make!

Alright so I gave this yet another shot using everything I've learned so far. All the things I said before apply. Long list detailing every single thing I did is in the quote below and screenshot of everything including errors is in the attached image

So yeah, if anyone can show me how to install sf2dlib on a fresh copy of Windows I'd love you.

EDIT: So the make error in 'libsf2d' says something about GPU_SetStencilOP(GPU_KEEP.... That wouldn't possible be related to the latest ctrulib commit about GPU_KEEP would it? I'm just think out loud. IDK, it's probably something I'm doing.

HOST Computer: Windows 7 Ultimate x64 SP1
VM Software: VMware Workstation 10.0.1 build-1379776
VM OS: Windows: Windows 7 Ultimate x64 SP1
Windows ISO MD5: c9f7ecb768acb82daacf5030e14b271e

Navigate to Python.org
Download: Python 3.4.3 Windows x86-64 MSI Installer
https://www.python.org/ftp/python/3.4.3/python-3.4.3.amd64.msi

Install Python 3.4.3.

Download: CTRULIB v0.5.0
https://github.com/smealum/ctrulib/releases/tag/v0.5.0

Download: devkitProUpdater-1.5.4
http://sourceforge.net/projects/devkitpro/files/Automated Installer/

Install devkitProUpdater-1.5.4

Copy libctru from ctrulib-master.zip to newly created C:\3DS folder. (notice the directory tree on left)

Download: sf2dlib-master.zip
https://github.com/xerpi/sf2dlib

Copy libsf2d from from sf2dlib-master.zip into C:\3DS

Download aemstro-master.zip
https://github.com/smealum/aemstro

Copy 'aemstro.py' and 'aemstro_as.py' from aemstro-master.zip into newly created C:\devkitPro\aemstro

create System Variable 'AEMSTRO' pointing to C:\devkitPro\aemstro

'make' C:\3DS\libctru then 'make install' that same directory

create System Variable 'CTRULIB' pointing to C:\devkitPro\libctru

attempt and fail to make C:\3DS\libsf2d

-------

PS:
Here's a copy of my VM's SYSTEM PATH if that's relevant
c:\devkitPro\msys\bin;C:\Python34\;C:\Python34\Scripts;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
 

Attachments

  • Steps.png
    Steps.png
    586 KB · Views: 205
Last edited by dfsa3fdvc1,

yirgacheffe

New Member
Newbie
Joined
Aug 23, 2015
Messages
3
Trophies
0
Age
54
XP
74
Country
United States
EDIT: So the make error in 'libsf2d' says something about GPU_SetStencilOP(GPU_KEEP.... That wouldn't possible be related to the latest ctrulib commit about GPU_KEEP would it? I'm just think out loud. IDK, it's probably something I'm doing.

You actually found the problem you just had one more step to fix it.

Open the file libsf2d/source/sf2d.c in a text editor and search for "GPU_KEEP" and change it to "GPU_STENCIL_KEEP" three times, same as in that link you found:

- GPU_SetStencilOp(GPU_KEEP, GPU_KEEP, GPU_KEEP);
+ GPU_SetStencilOp(GPU_STENCIL_KEEP, GPU_STENCIL_KEEP, GPU_STENCIL_KEEP);

The compile error will go away after you save this fix.
 

Davideesk

Well-Known Member
Newcomer
Joined
Aug 19, 2015
Messages
67
Trophies
0
Age
27
XP
395
Country
United States
Ok, sounds like something that should be fixed though.
That is true. Hopefully it will be a quick fix for the author. I have not had any other problems so far.

This is an awesome 2D library xerpi. I will definitely be using this in the future. My first project with it will be a port of one of my favorite Ludum dare games Minicraft. (It was created by the same guy who made Minecraft).

5FEy2mP.jpg
 

dfsa3fdvc1

Well-Known Member
Member
Joined
Jan 3, 2015
Messages
226
Trophies
0
XP
214
Country
Albania
So, now that I got the sf2dlib working anyone got some protips on how to get the load_images library working with it? Screen of successful compilations of the sf2dlib and the error I'm getting with the load images.
Again, I have 0 idea what I'm doing. I just dragged the images library with the other stuff and wrote 'make'.

EDIT: THe error is about a missing file "jpeglib.h. Where can I find that file?
 

Attachments

  • VM.png
    VM.png
    77.2 KB · Views: 138
Last edited by dfsa3fdvc1,

nop90

Well-Known Member
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
You have to make and install the Portilbs.

Xerpy on his github has a make file that downloads, compiles and install everything for the 3DS toolchain, but it needs wget (or you can download the packages by hand an puth them in the right place).

The packages versions in the script aren't the latest, but work fine. If you want the latest you have to edit the script.

Good luck.
 
  • Like
Reactions: dfsa3fdvc1

xerpi

Well-Known Member
OP
Member
Joined
Dec 25, 2011
Messages
212
Trophies
1
Age
28
Location
Barcelona
XP
1,330
Country
Can someone tell me how to use sf2d_set_pixel()? It's producing some weird results for me.

Here is the current code that I am using:
Code:
int main()
{
    sf2d_init();
    sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));
  
    sf2d_texture *tex2 = sf2d_create_texture(200,120,TEXFMT_RGBA8,SF2D_PLACE_RAM);

    sf2d_set_pixel (tex2, 1, 1, 0xFFFF0000); // Blue
    sf2d_set_pixel (tex2, 0, 1, 0xFF7F0000);
    sf2d_set_pixel (tex2, 2, 2, 0xFF00FF00); // Green
    sf2d_set_pixel (tex2, 0, 2, 0xFF007F00);
    sf2d_set_pixel (tex2, 3, 3, 0xFF0000FF); // Red
    sf2d_set_pixel (tex2, 0, 3, 0xFF00007F);
    sf2d_set_pixel (tex2, 4, 4, 0xFFFFFFFF); // White
    sf2d_set_pixel (tex2, 0, 4, 0xFF7F7F7F);
    // Using RGBA8() does not change anything.
  
    consoleInit(GFX_BOTTOM, NULL); // Console on the bottom screen
    printf("Press 'Start' to exit.");

    while (aptMainLoop()) {

        hidScanInput();

        if (hidKeysHeld() & KEY_START) {
            break;
        }

        sf2d_start_frame(GFX_TOP, GFX_LEFT);  
           sf2d_draw_texture_scale(tex2, 0, 0, 2.0, 2.0);
        sf2d_end_frame();

        sf2d_swapbuffers();
    }

    sf2d_free_texture(tex2);

    sf2d_fini();
    return 0;
}

The pixels seem to be coming from the top-right of my 3ds screen. (I apologize for the sub-potato quality):
SNIro4f.jpg


I've used sf2d_get_pixel() on textures and it works perfectly fine. I don't know if I am doing something wrong or if it is a bug with this function.

Try calling sf2d_texture_tile32 at some point before rendering, for example just after sf2d_texture *tex2 = sf2d_create_texture(200,120,TEXFMT_RGBA8,SF2D_PLACE_RAM);.
 
  • Like
Reactions: Davideesk

Davideesk

Well-Known Member
Newcomer
Joined
Aug 19, 2015
Messages
67
Trophies
0
Age
27
XP
395
Country
United States
Is there an easy way to achieve a 'minus' effect on a square/texture? Like render a square with a circle section cut out of it. I'm aware of the scissor test, but that seems limited in functionality. I'm asking this because the project I'm porting uses it for underground lighting. I can just use the functions used by the game, but they are relatively intensive on the cpu. I don't want to worry about frame drops, so I was wondering if there is a better way of doing it.

FM7m7g7.png
 

machinamentum

Well-Known Member
Member
Joined
Jul 5, 2015
Messages
163
Trophies
0
XP
549
Country
United States
Is there an easy way to achieve a 'minus' effect on a square/texture? Like render a square with a circle section cut out of it. I'm aware of the scissor test, but that seems limited in functionality. I'm asking this because the project I'm porting uses it for underground lighting. I can just use the functions used by the game, but they are relatively intensive on the cpu. I don't want to worry about frame drops, so I was wondering if there is a better way of doing it.

FM7m7g7.png
There's several ways to accomplish this. The approach I've used in the past is to render just the alpha channel of the square with blending disabled, then render the alpha channel of the circle over it (presumably your circle would be a quad with a circle textured onto it), then render the square again with bending and all color channels enabled with the blending mode set to DST_ALPHA, ONE_MINUS_DST_ALPHA. This has the advantage of "cutting out" while retaining the effect of gradients due to alpha blending. Stencils are slightly easier to use IMO.

EDIT: here's some GL code to illustrate the technique better, I'm not sure how to use sf2dlib so porting this to work with it is an exercise to the reader.
Code:
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glColor4f(1, 1, 1, 1);
bind_texture();
//draw main object's alpha
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(X, Y);
glTexCoord2f(1, 0);
glVertex2f(X + Width, Y);
glTexCoord2f(1, 1);
glVertex2f(X + Width, Y + Height);
glTexCoord2f(0, 1);
glVertex2f(X, Y + Height);
glEnd();

glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//draw cut out (i used some baked text here)
ui_label::Draw();

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
bind_texture();
glColor4f(1, 1, 1, 1);

//draw main object again...
 
Last edited by machinamentum,

tj_cool

Site dev
Supervisor
Joined
Jan 7, 2009
Messages
10,064
Trophies
2
Location
This planet
XP
3,109
Country
Belgium
Seems more like there is a superfluous ) in that line, it should be:
Code:
@C:\Python34\python.exe C:\Users\Admin\Desktop\sf2dlib-master\libsf2d\aemstro_as.py $< ../$(notdir $<).shbin

Not
Code:
@C:\Python34\python.exe C:\Users\Admin\Desktop\sf2dlib-master\libsf2d\aemstro_as.py $< ../$(notdir $<).shbin)
 
  • Like
Reactions: randomdev

randomdev

Well-Known Member
Member
Joined
Jun 7, 2015
Messages
155
Trophies
0
XP
236
Country
Brazil
Seems more like there is a superfluous ) in that line, it should be:
Code:
@C:\Python34\python.exe C:\Users\Admin\Desktop\sf2dlib-master\libsf2d\aemstro_as.py $< ../$(notdir $<).shbin

Not
Code:
@C:\Python34\python.exe C:\Users\Admin\Desktop\sf2dlib-master\libsf2d\aemstro_as.py $< ../$(notdir $<).shbin)
thanks man
 

Suikoden77

Member
Newcomer
Joined
Feb 5, 2010
Messages
22
Trophies
1
XP
167
Country
Well I'm a bit noobish compiling the libraries.. I'm having troubles loading textures since I think I'm using too much memory and right now my game is running on citra but not in my O3DS, so I am thinking on using sfillib which seems to make things easier but I've downloaded the binaries and I don't know where to put things to make it compile :( . This is my mess of devkitPro folder:
v7uo39.jpg

I should clean it a bit since there are duplicates but it's working and really don't know how haha
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    K3Nv2 @ K3Nv2: https://youtu.be/LM0Y6RWvcr8?si=RjMLNrx1TEX301g1 Already has cfw lol +1