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

D

Deleted User

Guest
  • Like
Reactions: MRJPGames

xerpi

Well-Known Member
OP
Member
Joined
Dec 25, 2011
Messages
212
Trophies
1
Age
28
Location
Barcelona
XP
1,330
Country
I'm updating some code (Handy3ds) from the lib versions of september 2015 to the last commits on github, but now using sftd, printing with size bigger than 10 results in a blurred string.

I tested it with the font of my last release (Hack.ttf) and with roboto-normal.ttf.

Before
View attachment 41179

After
View attachment 41178

The font ins't the same, but I hope the problem i clear. Don' mind for the wrong text positio, it's easy to fix.

Hints?
I think I know what's happening, are you first drawing with a small size, and then drawing another text with the same font but a (much) bigger font size?
 

nop90

Well-Known Member
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
I think I know what's happening, are you first drawing with a small size, and then drawing another text with the same font but a (much) bigger font size?

Yes. Every frame I first draw FPS info on left top corner with size 10, and then I draw the bigger text.


Edit: following your hint, I loaded th font twice (in two distinct variables) and used the first for printing in size 10 and the second to print in size 16. With this workaround I fixed the problem.
 
Last edited by nop90,

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
Yes. Every frame I first draw FPS info on left top corner with size 10, and then I draw the bigger text.


Edit: following your hint, I loaded th font twice (in two distinct variables) and used the first for printing in size 10 and the second to print in size 16. With this workaround I fixed the problem.
But that should not be needed, as I'm also using sftdlib I would like to see this fixed! But good to know about a temporary workaround for the time being (haven't had this issue before but good to know anyways).
 

YugamiSekai

Mr. Picross
Member
Joined
Dec 24, 2014
Messages
2,015
Trophies
1
Age
22
XP
2,386
Country
United States
I'm having a little problem compiling the code at the OP. Whenever I try to compile I get "undefined reference for sf2d_init" and all the other sf2d functions but I can compile the example program in the library folder. Am I doing something wrong?
 

nop90

Well-Known Member
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
But that should not be needed, as I'm also using sftdlib I would like to see this fixed! But good to know about a temporary workaround for the time being (haven't had this issue before but good to know anyways).

Did you add the option lo link the sf2d library in the makefile LIB variable?

It should be like the following line:

Code:
LIBS := -lsf2d -lctru -lm
 

Spaqin

Well-Known Member
Member
Joined
Feb 17, 2015
Messages
123
Trophies
0
Age
29
XP
199
Country
Poland
I'm having a little problem compiling the code at the OP. Whenever I try to compile I get "undefined reference for sf2d_init" and all the other sf2d functions but I can compile the example program in the library folder. Am I doing something wrong?

Probably you're not using -lsf2d in your makefile, or it can't find the path to the compiled lib (forgot to include it in the make?).
 

nop90

Well-Known Member
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
if you added -lsf2d, then another cause could be the order of the libs. -sf2d have to be before -lctru as in my example.

If this doesn't solve, then please post your makefile.
 

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
if you added -lsf2d, then another cause could be the order of the libs. -sf2d have to be before -lctru as in my example.

If this doesn't solve, then please post your makefile.
Uhm... I don't have ANY problem with any of my libs, if you are not talking to me, why did you quote my post? I think you should be talking to @kprovost7314 because he DOES have an issue with his sf2dlib XD
 

MOHRCORE

Well-Known Member
Newcomer
Joined
Nov 1, 2013
Messages
70
Trophies
0
XP
170
Country
Poland
Great library! Finally I've made some progress with learning homebrew development (citro3d with it's poor documentation was the reason why I couldn't understand anything) :D

Is there an implemented way to create transparecy mask from a color (eg. I want to turn every pink pixel from a texture to a transparent one)? Or I just have to do it manualy by scanning trough every pixel and changing it into a transparent one if the color mathes?
 

nop90

Well-Known Member
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
Is there an implemented way to create transparecy mask from a color (eg. I want to turn every pink pixel from a texture to a transparent one)? Or I just have to do it manualy by scanning trough every pixel and changing it into a transparent one if the color mathes?

It's simpler to use an image with an alpha channel (RGBA8) instead of an image in RGB8 with color mask. You can easily convert your images with GIMP.
 

MOHRCORE

Well-Known Member
Newcomer
Joined
Nov 1, 2013
Messages
70
Trophies
0
XP
170
Country
Poland
It's simpler to use an image with an alpha channel (RGBA8) instead of an image in RGB8 with color mask. You can easily convert your images with GIMP.
Thanks! I know I can, I just wanted to port some stuff from my PC project where I'm using bitmaps with color masks.
 

nop90

Well-Known Member
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
Thanks! I know I can, I just wanted to port some stuff from my PC project where I'm using bitmaps with color masks.

I was thinking that writing a shader that sets an alpha value of 0 to a given RGB value is very easy.

This way you could have a custom bmpDraw funcion that does what you want. I knoe only a little of shaders coding, you could find such an task on some tutorial on line.

I'll try to implement it as an exercise when I have time, but now I'm working on too many things.
 

TheCruel

Developer
Banned
Joined
Dec 6, 2013
Messages
1,350
Trophies
2
XP
3,131
Country
United States
Unfortunately, PICA has no support for fragment shaders, only vertex and geometry shaders. So you can you only output vertex colors and not texture colors. You'd have to get more creative, I don't know.

If I were you, I'd just use imagemagick or something to quickly convert all your images to have the transparency. But maybe there is some solution I'm not thinking about.

EDIT: the command is something like: convert input.bmp -transparent <color> output.png
 
Last edited by TheCruel,
  • Like
Reactions: MRJPGames

machinamentum

Well-Known Member
Member
Joined
Jul 5, 2015
Messages
163
Trophies
0
XP
549
Country
United States
Unfortunately, PICA has no support for fragment shaders, only vertex and geometry shaders. So you can you only output vertex colors and not texture colors. You'd have to get more creative, I don't know.

If I were you, I'd just use imagemagick or something to quickly convert all your images to have the transparency. But maybe there is some solution I'm not thinking about.

EDIT: the command is something like: convert input.bmp -transparent <color> output.png
Alternatively, instead of converting the image offline, the image could very easily be converted in memory to RBGA format during the loading process (as the asker has noted). This way different versions of the same game dont have to ship with an entirely different set of images.

Example:
Code:
u8 *inputBuffer; // Assume buffer has already been loaded and is RGB (24 bpp) format
u8 *outputBuffer = linearAlloc(width * height * 4); // allocate enough space for 32 bpp
for (int y = 0; y < height; ++y) {
  for (int x = 0; x < width; ++x) {
    u32 inputIndex  = (x + y * height) * 3;
    u32 outputIndex = (x + y * height) * 4;
    u8 r = inputBuffer[inputIndex + 0]; // Note: reverse order if buffer is BGR
    u8 g = inputBuffer[inputIndex + 1];
    u8 b = inputBuffer[inputIndex + 2];
    outputBuffer[outputIndex + 0] = r;
    outputBuffer[outputIndex + 1] = g;
    outputBuffer[outputIndex + 2] = b;
    if (r == 255 && g == 255 && b == 255) outputBuffer[outputIndex + 3] = 0; // write complete transparency for magenta pixels
    else outputBuffer[outputIndex + 3] = 255; // write complete opacity for other pixels
  }
}
 
Last edited by machinamentum,
  • Like
Reactions: MOHRCORE

MOHRCORE

Well-Known Member
Newcomer
Joined
Nov 1, 2013
Messages
70
Trophies
0
XP
170
Country
Poland
I was thinking that writing a shader that sets an alpha value of 0 to a given RGB value is very easy.

This way you could have a custom bmpDraw funcion that does what you want. I knoe only a little of shaders coding, you could find such an task on some tutorial on line.

I'll try to implement it as an exercise when I have time, but now I'm working on too many things.

EDIT: Sorry, machinamentum already said what I wrote. But I still can add, that it would be easier to do it with sf2d_get_pixel (sf2d_texture *texture, int x, int y) and sf2d_set_pixel (sf2d_texture *texture, int x, int y, u32 new_color).

However in this case, you'll need sf2d_texture, but that's probably what you need an image for.

Example code:

Code:
void applyColorMask(sf2d_texture & tex, const u32 color, const u32 replace)
{
    for(int i1 = 0; i1 < tex.width; i1++)
    {
        for(int i2 = 0; i2 < tex.height; i2++)
        {
            if(sf2d_get_pixel(&tex, i1, i2) == color)
                sf2d_set_pixel(&tex, i1, i2, replace);
        }
    }
}
 
Last edited by MOHRCORE,

MOHRCORE

Well-Known Member
Newcomer
Joined
Nov 1, 2013
Messages
70
Trophies
0
XP
170
Country
Poland
Sorry for double post, but it's another (noob?) question this time, so I wanted to separate it from my reply.

How do I create a texture on VRAM? When I use sf2d_create_texture_mem_RGBA8 I can set the place of allocation to SF2D_PLACE_VRAM instead of SF2D_PLACE_RAM, but it freezes/crashes the program.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • Quincy @ Quincy:
    Usually when such a big title leaks the Temp will be the first to report about it (going off of historical reports here, Pokemon SV being the latest one I can recall seeing pop up here)
  • K3Nv2 @ K3Nv2:
    I still like how a freaking mp3 file hacks webos all that security defeated by text yet again
  • BigOnYa @ BigOnYa:
    They have simulators for everything nowdays, cray cray. How about a sim that shows you playing the Switch.
  • K3Nv2 @ K3Nv2:
    That's called yuzu
    +1
  • BigOnYa @ BigOnYa:
    I want a 120hz 4k tv but crazy how more expensive the 120hz over the 60hz are. Or even more crazy is the price of 8k's.
  • K3Nv2 @ K3Nv2:
    No real point since movies are 30fps
  • BigOnYa @ BigOnYa:
    Not a big movie buff, more of a gamer tbh. And Series X is 120hz 8k ready, but yea only 120hz 4k games out right now, but thinking of in the future.
  • K3Nv2 @ K3Nv2:
    Mostly why you never see TV manufacturers going post 60hz
  • BigOnYa @ BigOnYa:
    I only watch tv when i goto bed, it puts me to sleep, and I have a nas drive filled w my fav shows so i can watch them in order, commercial free. I usually watch Married w Children, or South Park
  • K3Nv2 @ K3Nv2:
    Stremio ruined my need for nas
  • BigOnYa @ BigOnYa:
    I stream from Nas to firestick, one on every tv, and use Kodi. I'm happy w it, plays everything. (I pirate/torrent shows/movies on pc, and put on nas)
  • K3Nv2 @ K3Nv2:
    Kodi repost are still pretty popular
  • BigOnYa @ BigOnYa:
    What the hell is Kodi reposts? what do you mean, or "Wut?" -xdqwerty
  • K3Nv2 @ K3Nv2:
    Google them basically web crawlers to movie sites
  • BigOnYa @ BigOnYa:
    oh you mean the 3rd party apps on Kodi, yea i know what you mean, yea there are still a few cool ones, in fact watched the new planet of the apes movie other night w wifey thru one, was good pic surprisingly, not a cam
  • BigOnYa @ BigOnYa:
    Damn, only $2.06 and free shipping. Gotta cost more for them to ship than $2.06
    +1
  • BigOnYa @ BigOnYa:
    I got my Dad a firestick for Xmas and showed him those 3rd party sites on Kodi, he loves it, all he watches anymore. He said he has got 3 letters from AT&T already about pirating, but he says f them, let them shut my internet off (He wants out of his AT&T contract anyways)
  • K3Nv2 @ K3Nv2:
    That's where stremio comes to play never got a letter about it
  • BigOnYa @ BigOnYa:
    I just use a VPN, even give him my login and password so can use it also, and he refuses, he's funny.
  • BigOnYa @ BigOnYa:
    I had to find and get him an old style flip phone even without text, cause thats what he wanted. No text, no internet, only phone calls. Old, old school.
  • Psionic Roshambo @ Psionic Roshambo:
    @BigOnYa, Lol I bought a new USB card reader thing on AliExpress last month for I think like 87 cents. Free shipping from China... It arrived it works and honestly I don't understand how it was so cheap.
    +1
    Psionic Roshambo @ Psionic Roshambo: @BigOnYa, Lol I bought a new USB card reader thing on AliExpress last month for I think like 87... +1