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,329
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,286
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
  • BakerMan
    I rather enjoy a life of taking it easy. I haven't reached that life yet though.
  • BigOnYa @ BigOnYa:
    I don't trust the free ones, but ipvanish I've used for couple years now, n like
  • Psionic Roshambo @ Psionic Roshambo:
    I wonder if they could get CPUs to run that hot then use the heat to power a steam turbine to power the CPUs....
  • BigOnYa @ BigOnYa:
    Good idea, or at least power the GPU
  • Psionic Roshambo @ Psionic Roshambo:
    It's not the movies or games downloads that I would worry about, like breaking into networks, downloading encrypted things, spying on network traffic. I have seen so many "Top Secret" seals on files when I was a kid
  • Psionic Roshambo @ Psionic Roshambo:
    I was obsessed with finding UFOs, a surprising amount of US files where stashed on computers in other countries, China back in the early 90s omg sooo much
  • BigOnYa @ BigOnYa:
    Yea that crazy, I've never tried hack into anything, I just pirate, and my ISP have send me 3-4 letters, so had to VPN it
  • Psionic Roshambo @ Psionic Roshambo:
    Ship to ship communication software for the Navy although without access to the encrypting chips it was mostly useless
  • Psionic Roshambo @ Psionic Roshambo:
    I bet now a 4090 could probably crack it? Hmmm maybe not even back then I'm pretty sure they where using like 1024 bit encryption
  • Psionic Roshambo @ Psionic Roshambo:
    Yayyy the one set finished 324GBs lol
  • Psionic Roshambo @ Psionic Roshambo:
    Compressed....
  • Psionic Roshambo @ Psionic Roshambo:
    I wonder how many years that would have taken on a 56K modem lol
  • Psionic Roshambo @ Psionic Roshambo:
    18000 hours lol
  • Psionic Roshambo @ Psionic Roshambo:
    750 days lol
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    So Internet is very much faster now lol
  • BigOnYa @ BigOnYa:
    "Time Remaining- 2 years, 9 girlfriends, 6 hairstyles, please standby..."
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    I remember one time I downloaded like a 500MB ISO file on 56K and that literally took like 2 days
  • Psionic Roshambo @ Psionic Roshambo:
    I had some sort of resume thing, I remember the software had chains
  • Psionic Roshambo @ Psionic Roshambo:
    Damned if I can't remember.the name though
  • Psionic Roshambo @ Psionic Roshambo:
    Some sort of download management app
  • BigOnYa @ BigOnYa:
    Ok good chatting, I'm off to the bar, to shoot some pool, nighty night.
    +1
  • BakerMan @ BakerMan:
    hey psi
  • BakerMan @ BakerMan:
    i call your girl lyndon the way she b on my johnson
    BakerMan @ BakerMan: i call your girl lyndon the way she b on my johnson