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

josamilu

Well-Known Member
Member
Joined
Feb 1, 2015
Messages
383
Trophies
0
Location
Saturn is better than Jupiter :P
XP
319
Country
Gambia, The
Try changing the init and fini commands on their place, like this:

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <3ds.h>
#include <sf2d.h>
#include <sfil.h>
#include <sftd.h>

#include "FreeSans_ttf.h"

#include "citra_jpeg.h"
#include "3dbrew_png.h"

int main()
{
    // Set the random seed based on the time
    srand(time(NULL));

    sf2d_init();
    sftd_init();
    sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));

    sf2d_texture *tex1 = sfil_load_JPEG_buffer(citra_jpeg, citra_jpeg_size, SF2D_PLACE_RAM);
    sf2d_texture *tex2 = sfil_load_PNG_buffer(_3dbrew_png, SF2D_PLACE_RAM);

    sftd_font *font = sftd_load_font_mem(FreeSans_ttf, FreeSans_ttf_size);

    u32 held;

    while (aptMainLoop()) {

        hidScanInput();
        held = hidKeysHeld();

        if (held & KEY_START) {
            break;
        }

        sf2d_start_frame(GFX_TOP, GFX_LEFT);
       
            sftd_draw_textf(font, 10, 10, RGBA8(0, 255, 0, 255), 20, "FPS %f", sf2d_get_fps());
            sf2d_draw_texture(tex1, 400/2 - tex1->width/2, 240/2 - tex1->height/2);
        sf2d_end_frame();

        sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
            sf2d_draw_texture(tex2, 320/2 - tex2->width/2, 240/2 - tex2->height/2);
        sf2d_end_frame();

        sf2d_swapbuffers();
    }

    sf2d_free_texture(tex1);
    sf2d_free_texture(tex2);
    sftd_free_font(font);

    sf2d_fini();
    sftd_fini();

    return 0;
}
You are my hero, it actually worked. Thanks :D
 
  • Like
Reactions: lolzvid

randomdev

Well-Known Member
Member
Joined
Jun 7, 2015
Messages
155
Trophies
0
XP
236
Country
Brazil
hey, I just installed devkitarm r45, and i can't compile sf2d...
I have a lot of errors.

Edit: compile is successful with libctru 0.6. Looks like it doesn't works with 1.0.
 
Last edited by randomdev,

xerpi

Well-Known Member
OP
Member
Joined
Dec 25, 2011
Messages
212
Trophies
1
Age
28
Location
Barcelona
XP
1,330
Country
Yes I'm sorry guys, but the great-refactor branch of ctrulib has been merged into the master, so sf2dlib no longer builds. I'll try to fix it ASAP but I'll be really busy this next week. If you could do it and send a pull request I'd be very grateful.
 

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
Yes I'm sorry guys, but the great-refactor branch of ctrulib has been merged into the master, so sf2dlib no longer builds. I'll try to fix it ASAP but I'll be really busy this next week. If you could do it and send a pull request I'd be very grateful.

@xerpi currently lpp-3ds uses a slight modified version of sf2dlib with floats instead of integer for coordinates and some syntax change to match new great-refactor syntax (with -DLIBCTRU_NO_DEPRECATION you'll not get any warning also).
If it can be useful, here's the link (i can also make a pull request): https://github.com/Rinnegatamante/lpp-3ds/tree/master/source/include/sf2d
 
  • Like
Reactions: xerpi

TheCruel

Developer
Banned
Joined
Dec 6, 2013
Messages
1,350
Trophies
2
XP
3,131
Country
United States
Yes I'm sorry guys, but the great-refactor branch of ctrulib has been merged into the master, so sf2dlib no longer builds. I'll try to fix it ASAP but I'll be really busy this next week. If you could do it and send a pull request I'd be very grateful.
Did it: https://github.com/xerpi/sf2dlib/pull/21

Worth mentioning for everyone: you need to update devkitARM in order to build latest ctrulib. Both were updated at the same time.
 
  • Like
Reactions: Joel16 and xerpi

andre111

Active Member
Newcomer
Joined
Dec 27, 2015
Messages
33
Trophies
0
Age
27
XP
184
Country
Germany
Just a quick heads up: I'm pretty new to C coding and completely new to 3DS Hombrew dev, so my problem might not be related to this lib but it would be my first guess.

So, I'm currently trying to compile some allready existing homebrew before I start working on my own ideas.
I started with Minicraft and got it to compile and run under the newest libs.

But for some reason most colors are completely wrong. Colors from images loaded with sfillib appear to be correct but most others appear mostly red. For example the titlescreen bg is red instead of black and the grass is a wiered purple/pink/gray combination color instead of green. And the list goes on.

What am I doing wrong as I cann't really find the cause of the problem.

edit: Did some "research". The problem probably lies with this commit
https://github.com/xerpi/sf2dlib/commit/8b4646c3d1ba872531de4a88c913d4f3e46288c5
which flipped RGBA8 from rgba to abgr and probably somewhere else it was forgotten to adapt the code to the new format.
So right now the alpha value gets used as the red value, which causes the red textures.

edit 2: Sorry, the problem lies in the code of Minicraft, which defines most colors simply by using number values. I guess I need to "flip" them all for the new lib version
 
Last edited by andre111,

MasterFeizz

Well-Known Member
Member
Joined
Oct 15, 2015
Messages
1,098
Trophies
1
Age
29
XP
3,710
Country
United States
I meant more like letting the GPU draw to a texture rather than directly to the screen.
The GPU already draws to a texture(color buffer), it then gets transfered to the framebuffer with the function GX_DisplayTransfer inside sf2d_end_frame. You can modify the source a little to allow different color buffers as targets. And reuse them. You can also do a reverse display transfer to copy the framebuffer into a texture.
 
  • Like
Reactions: xerpi

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • K3Nv2
  • BakerMan
    I rather enjoy a life of taking it easy. I haven't reached that life yet though.
  • ZeroT21 @ ZeroT21:
    live service game for 40 bucks that sold 12 mil copies
  • K3Nv2 @ K3Nv2:
    Ever notice how games that sell millions get hated the worst
  • K3Nv2 @ K3Nv2:
    Cod and sports games are good examples but people still buy the shit
  • ZeroT21 @ ZeroT21:
    it happens quit often if not all the time
  • ZeroT21 @ ZeroT21:
    diablo 4 anyone?
  • K3Nv2 @ K3Nv2:
    Everyone just doesn't want to be an outcast and say they're decent games why do they make billions if it's so shit
  • ZeroT21 @ ZeroT21:
    just buy nintendo stuff and their games if you just want fun
  • K3Nv2 @ K3Nv2:
    I still can't name 12 fun current Nintendo games
  • ZeroT21 @ ZeroT21:
    i say get a pc and emulate that too

    :rofl2:
  • K3Nv2 @ K3Nv2:
    Or in today's age at least a SteamDeck
  • ZeroT21 @ ZeroT21:
    i gotta say, the steam deck isn't a bad deal, even if you get a used one, you have options to get it serviced and the parts are also available through ifixit
  • K3Nv2 @ K3Nv2:
    I remember a guy trying to call me a SteamDeck fanboy I'm like well give me a grand I'll buy a winmax
    +1
  • K3Nv2 @ K3Nv2:
    Or a win4 things still sexy
  • ZeroT21 @ ZeroT21:
    having money does not mean everyone will just fork it over
  • ZeroT21 @ ZeroT21:
    everyone perceives value diffrently
  • K3Nv2 @ K3Nv2:
    I buy cheap and whats useable
  • K3Nv2 @ K3Nv2:
    Twice out of the year I may get something that's $600
  • ZeroT21 @ ZeroT21:
    we all like nice things, sure, but I also want to keep money on the side
  • K3Nv2 @ K3Nv2:
    I'd have the same mentality if money wasn't an object
  • ZeroT21 @ ZeroT21:
    having a warped sense can happen
  • ZeroT21 @ ZeroT21:
    reason i question myself, but not constantly
  • K3Nv2 @ K3Nv2:
    If I had Elon money sure I'd have a 20 bedroom home
  • ZeroT21 @ ZeroT21:
    if only that alone could make me happy, but nope
    :D
  • ZeroT21 @ ZeroT21:
    you'll only feel more empty after most of your urges go away like that
  • K3Nv2 @ K3Nv2:
    Spam account tried getting $10 off me I'm like you didn't have it last week you'll be fine
    K3Nv2 @ K3Nv2: Spam account tried getting $10 off me I'm like you didn't have it last week you'll be fine