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
  • Xdqwerty @ Xdqwerty:
    nvm this video is clickbait
  • K3Nv2 @ K3Nv2:
    I got a dazzel capture card some place in storage
  • Noctosphere @ Noctosphere:
    Is TCK some kind of Clanchit follower?
    +1
  • K3Nv2 @ K3Nv2:
    Leo just follows Luke around with flowers
    +2
  • BigOnYa @ BigOnYa:
    Is funny, every week he cries bout something and says that's it, I'm leaving this site for good.
  • K3Nv2 @ K3Nv2:
    See I'm a good match maker I always knew he wouldnt leave over luke
    +2
  • BigOnYa @ BigOnYa:
    Had to break down and turn on my AC today. 89 degrees in May. Bet August/September is gonna be crazy hot.
  • Xdqwerty @ Xdqwerty:
    im back
  • K3Nv2 @ K3Nv2:
    @BigOnYa, when your wife kicks you out BOVONO Prefabricated Tiny Home, Mobile Prefab House with Lockable Door and Window, Outdoor Storage Shed with Restroom & Cabinet, Perfect for Hotel, Kiosk, Booth(19 x 20FT) https://a.co/d/ab1dd5t
    +2
  • BigOnYa @ BigOnYa:
    Pretty cool actually
  • Xdqwerty @ Xdqwerty:
    I feel pain on the left side of my stomach
  • ZeroT21 @ ZeroT21:
    @K3Nv2 looks neat, i would want one in the boonies
    +1
  • K3Nv2 @ K3Nv2:
    Read the reviews
  • ZeroT21 @ ZeroT21:
    honestly, seems like a great option for temporary housing, but the reviews seems iffy
  • ZeroT21 @ ZeroT21:
    I'm sure i could build one with the schematics if made available
  • ZeroT21 @ ZeroT21:
    the 2nd pic dun show much, just topdown view of the layout
  • Y @ yqw:
    someone has a cheat table for need for speed most wanted 2012?
  • K3Nv2 @ K3Nv2:
    The cheat codes 911 catch the crazy drivers
  • BigOnYa @ BigOnYa:
    I mean that game came out on every game system, so lets be a little more vague.
  • BigOnYa @ BigOnYa:
    I need cheats for GTA v, lol. And why ask here, go look for them yo self!
    +2
  • ZeroT21 @ ZeroT21:
    make 'em , they're not hard to do
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Fast and Furious Night Rider crossover !
    Psionic Roshambo @ Psionic Roshambo: Fast and Furious Night Rider crossover !