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.
  • BigOnYa @ BigOnYa:
    I'd rather spend like $150 more for a surround receiver.
  • K3Nv2 @ K3Nv2:
    I bought the game at launch never fucked with it until recently
  • BigOnYa @ BigOnYa:
    Its fun, I like it, even tho I'm not a big harry potter fan. Like a wizard rpg. Flying around on a broomstick is cool.
  • K3Nv2 @ K3Nv2:
    Flying sucks ass on it
  • BigOnYa @ BigOnYa:
    Nuh just takes a min to get used to. I think you can upgrade or buy new broomstick also that are better.
    +1
  • K3Nv2 @ K3Nv2:
    I weirdly like inverted controls on all flying type games
  • BigOnYa @ BigOnYa:
    Prob can change it, inverted flying controls.
  • K3Nv2 @ K3Nv2:
    Only thing that annoys me is trying to find wtf to do in it
    +1
  • BigOnYa @ BigOnYa:
    Alright off to the store, later gators.
    +1
  • K3Nv2 @ K3Nv2:
    Some places amaze me were not in network with your insurance would you still like an appointment
    +1
  • AncientBoi @ AncientBoi:
    uhhh, I think I'll just stick with my PSP 3001
  • AncientBoi @ AncientBoi:
    lol, Now I gotta go to the store for more Coffee Mate n other stuff.
  • Xdqwerty @ Xdqwerty:
    i downloaded final fantasy vii into my tv stick
  • Xdqwerty @ Xdqwerty:
    i mean, the game was already there but its the japanese version
  • Xdqwerty @ Xdqwerty:
    and i only downloaded disc 1 so far bc of storage stuff
  • Psionic Roshambo @ Psionic Roshambo:
    @BigOnYa, yeah the patty on McDs burger is 1/10th of a pound now and I think that's the pre cooked weight lol
  • Psionic Roshambo @ Psionic Roshambo:
    I use the app for the 20% off coupon and it's still over priced
  • Xdqwerty @ Xdqwerty:
    @Psionic Roshambo, why is mcdonalds overpriced if their food is bad?
  • Xdqwerty @ Xdqwerty:
    i mean why is mcdonalds food overpriced
  • Psionic Roshambo @ Psionic Roshambo:
    Inflation and greed
    +1
  • ZeroT21 @ ZeroT21:
    it's just fries, make 'em at home
    +2
  • Psionic Roshambo @ Psionic Roshambo:
    I make potato wedges at home with spices and stuff lol
    Psionic Roshambo @ Psionic Roshambo: I make potato wedges at home with spices and stuff lol