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

  • Thread starter Thread starter xerpi
  • Start date Start date
  • Views Views 97,168
  • Replies Replies 501
  • Likes Likes 32
@Rinnegatamante thanks for the quick answer.
Asteroid 3D works on both CPU & GPU. If it didn't support GPU would crash right ?
I noticed it has a lot of flickering in both CPU & GPU on top and bottom screen.

Strange that flickering issues anyway yes, it should crash when you switch to GPU.
 
When loading an image with sfil lib , there is a parameter of where to place the texture, ram or vram.
I read online that VRAM is around 6MB but Ram is 128MB(-32MB for OS).

If I place my textures in RAM and then move each texture to VRAM before calling sf2d_draw_texture
will it improve performance ?
If textures are not in VRAM, they will be rendered by CPU ?

I'm a little confused as I have only worked with SDL before.
 
When loading an image with sfil lib , there is a parameter of where to place the texture, ram or vram.
I read online that VRAM is around 6MB but Ram is 128MB(-32MB for OS).

If I place my textures in RAM and then move each texture to VRAM before calling sf2d_draw_texture
will it improve performance ?
If textures are not in VRAM, they will be rendered by CPU ?

I'm a little confused as I have only worked with SDL before.

No, you still use GPU if you puth them on RAM but if you need more RAM for some other function (like audio streaming) it's better to use VRAM for images.
 
Is there a way to do the actual rendering in a function instead of the main loop?

eg.
void render(){
sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
sf2d_draw_texture(tex1,0,0);
sf2d_end_frame();
}

int main(){
//init all stuff (sf2d, textures etc.)
while (aptMainLoop()) {
//Game
render();
sf2d_swapbuffers();
}
}

When I try something like this it will give me this error:
error: 'tex1' undeclared (first use in this function)

I've been trying all kinds of things to attempt to make it work, but nothing worked. Does anyone know how to do this?
 
Is there a way to do the actual rendering in a function instead of the main loop?

I've been trying all kinds of things to attempt to make it work, but nothing worked. Does anyone know how to do this?

The problem is that tex1 is not in the scope of render function, since you have declared it inside main. You'll have to pass it to the function, or make the texture global (which i don't recommend). For example:

Code:
void render(sfd2_texture *tex1){
//your code
}

int main(){
  //bla blah
  render(tex1); //now tex1 is a parameter of render, so you can access it in your function
}

Note that if you want to pass a lot of textures you can pass a double pointer or a pointer vector and an int as the number of textures you have.
 
  • Like
Reactions: MRJPGames
The problem is that tex1 is not in the scope of render function, since you have declared it inside main. You'll have to pass it to the function, or make the texture global (which i don't recommend). For example:

Code:
void render(sfd2_texture *tex1){
//your code
}

int main(){
  //bla blah
  render(tex1); //now tex1 is a parameter of render, so you can access it in your function
}

Note that if you want to pass a lot of textures you can pass a double pointer or a pointer vector and an int as the number of textures you have.
Thanks!
I have the following render code:
sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
sf2d_draw_texture(tex1, 0, 0);
for (x=0; x<8; x++){
for (y=0; y<8; y++){
if (board[x][y] == 1){
sf2d_draw_texture_part(tex2, 9+28*x, 9+28*y, 0, 0, 26, 26);
}else if (board[x][y] == 2){
sf2d_draw_texture_part(tex2, 9+28*x, 9+28*y, 26, 0, 26, 26);
}
}
}
sf2d_end_frame();

sf2d_swapbuffers();

But when running I see the 2 (of the 4 there should be) small textures (tex2) on the board (tex1) but they only appear for a brief moment before disappearing again... Would you happen to know what I'm doing wrong here?
 
Thanks!
I have the following render code:
Code:
sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
            sf2d_draw_texture(tex1, 0, 0);
            for (x=0; x<8; x++){
                for (y=0; y<8; y++){
                    if (board[x][y] == 1){
                        sf2d_draw_texture_part(tex2, 9+28*x, 9+28*y, 0, 0, 26, 26);
                    }else if (board[x][y] == 2){
                        sf2d_draw_texture_part(tex2, 9+28*x, 9+28*y, 26, 0, 26, 26);
                    }
                }
            }
        sf2d_end_frame();

        sf2d_swapbuffers();

But when running I see the 2 (of the 4 there should be) small textures (tex2) on the board (tex1) but they only appear for a brief moment before disappearing again... Would you happen to know what I'm doing wrong here?


Here everything is fine, the problem lies elsewhere...
 
Here everything is fine, the problem lies elsewhere...
http://pastebin.com/FTb5SxWq
This is my main.c, it handles all gfx stuff. board[x][y] aren't really changed unless the user touches the screen (and it worked with Software Rendering so the board array shouldn't be the problem...)
Apparently the problem did lie somewhere in the board code... strange.
 
Last edited by MRJPGames,
http://pastebin.com/FTb5SxWq
This is my main.c, it handles all gfx stuff. board[x][y] aren't really changed unless the user touches the screen (and it worked with Software Rendering so the board array shouldn't be the problem...)


Same, I see no problem here. try comment the line 38 to 81 and test, you will see that the display good works, then uncomment out gradually...for find problem.
 
Hi, I'm pretty new at this whole thing, but when running my make file I'm running into some errors.

sf2d.o: In function 'sf2d_init_advanced':
undefined reference to 'shader_vsh_shbin_size'
undefined reference to 'shader_vsh_shbin'
collect2.exe: error: ld returned 1 exit status

Any help would be appreciated because I don't really have any idea what I'm doing.
 
Hi, I'm pretty new at this whole thing, but when running my make file I'm running into some errors.

sf2d.o: In function 'sf2d_init_advanced':
undefined reference to 'shader_vsh_shbin_size'
undefined reference to 'shader_vsh_shbin'
collect2.exe: error: ld returned 1 exit status

Any help would be appreciated because I don't really have any idea what I'm doing.
If you don't know what you're doing it might be wise to use sf2d_init(); instead of sf2d_init_advanced(int gpucmd_size, int temppool_size); unless you need sf2d_init_advanced for it to work for your homebrew.
 
If you don't know what you're doing it might be wise to use sf2d_init(); instead of sf2d_init_advanced(int gpucmd_size, int temppool_size); unless you need sf2d_init_advanced for it to work for your homebrew.

Yep, that will probably fix it. Alright, I'll look into this. Thank you!
 
Thanks so much for this, I'll have to redo my game using this instead of just using ascii art.
 
Hey, so I'm having trouble getting this working (user error I'm sure, lol)

So what I've done is setup a fresh windows install and screenshot every single thing I've done while trying to get this run and detailed it all in the quote below. If someone could take a look at it and tell me what I'm doing wrong I'd appreciate it.
Note: In the attached image, the bottom row is the most relavant but I wanted to capture everything. Please check it out.

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

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

Install Python 2.7.10 and 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

Run DevKitPro's MSYS.BAT to generate a Windows Username folder, "VMTake2" in devkitpro\msys\home

Copy ctrulib-0.5.0 from its compressed zip and into the devkitpro\msys\home\VMTake2 folder

use MSYS.bat to successfully "make" ctrulib\examples\graphics\printing\hello-world
OK, so that works...

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

Extract to sf2dlib-master.zip devkitpro\msys\home\VMTake2 folder
attempt to "make install" in "C:\devkitPro\msys\home\VMTake2\sf2dlib-master\libsf2d" and fail due to "can't open file C:\devkitPro\msys\aemstro_as.py"

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

extract aemstro.py, aemstro_as.py, and test.vsh from aemstro-master.zip into C:\devkitPro\msys
reattempt "make install" in "C:\devkitPro\msys\home\VMTake2\sf2dlib-master\libsf2d" and get a ton of errors.... (check attached image)

in last-ditch effort to get this to work I copied aemstro.py, aemstro_as.py, and test.vsh from aemstro-master.zip into every single directory of libsf2d
Attempted "make install" one last time and got error
>No rule to make target 'aemstro.py.o, needed by 'home/VMTake2/sf2dlib-master/libsf2d/lib/libsf2d.a'. Stop


-------

PS:
If relevant, here's a copy of my System PATH after doing all of the stuff up above
c:\devkitPro\msys\bin;C:\Python34\;C:\Python34\Scripts;C:\Python27\;C:\Python27\Scripts;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
 

Attachments

  • steps.jpg
    steps.jpg
    1.5 MB · Views: 269
My recipe:

- make a folder inside c:/devkitpro named aemstro and put the two aemstro py file inside
- create a system variable named AEMSTRO with value C:\devkitPro\aemstro
- download the latest version of ctrulib from smea github, decompress it where you like (I use c:/3DS/ctrulib), 'make' it then 'make install' it
- create (if not present) a system variable named CTRULIB with value C:\devkitPro\libctru
- download sf2dlib and decompress it where you like (I use c:/3DS/sf2dlib, 'make' it then 'make install' it

And you need to have only python34 in your path variable, if you have Python27 (as I can see in you post), modify the path variable before making sf2dlib (or rename the python27 folder adding a final underscore). After compiling the lib undo the change to your path variable or pyton27 folder name.

This should be enough.
 
Last edited by nop90,
Hey, so I'm having trouble getting this working (user error I'm sure, lol)

So what I've done is setup a fresh windows install and screenshot every single thing I've done while trying to get this run and detailed it all in the quote below. If someone could take a look at it and tell me what I'm doing wrong I'd appreciate it.
Note: In the attached image, the bottom row is the most relavant but I wanted to capture everything. Please check it out.

Had this same issue until I updated to the latest ctrulib commit.

Also I had an issue with python34 until I updated my makefile's line from @python to @py.
 
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.
 
My recipe:

I gave it a shot but I'm still getting an error when making sf2dlib. Here's a screen shot of every step of the way along with notes on what I did. Progress is being made! Almost there!

I had an issue with python34 until I updated my makefile's line from @python to @py.

Gave that a shot but I'm still getting the error.
 

Attachments

  • steps.png
    steps.png
    435.6 KB · Views: 218
Last edited by dfsa3fdvc1,

Site & Scene News

Popular threads in this forum