Okay but seriously how on earth do fonts work with libnx? (Please help, am dying inside here)

noneuclideanmotion

Member
OP
Newcomer
Joined
Nov 1, 2022
Messages
13
Trophies
0
Age
22
XP
72
Country
United Kingdom
I've been trying for days now to simple load a font other than the default. and have run into problem after problem, including bugs in the library itself.

Right now the problem I'm facing is three-headed, first, you need extra data to load the font, which is not given (I'm simply trying to load one of the fonts to that come with devkitpro, somethingsomething20.nxfont). The information required is: the character size, the first ASCII character (in the default font this is 0), and the number of characters (in the default font this is 256).

Firstly, when I just keep the default font values and load the new font with them, it's all messed up. That isn't surprising. The fonts say nothing about the other information so I guessed.

If I put 20 for the width and height of the characters (makes sense right? It's got 20 in the name!). And keep the other values at 0 and 256, because I have no idea what else they could be or how I could find out, I get a DataAbort error (2168-0002).

My theries to the problem are:

1.nxfiles cannot be loaded directly and need to be bin files for libnx to use them.

2. I am misunderstanding what 'title x' and 'title y' mean and they are in fact not the width and height of characters.

3. The characters are only size 20 in one axis

4. There are a different number of characters in these fonts compared to the default one.

Unfortunately all of these theories are either too niche to Google, or I have no idea how to determine a fix (because I just don't know the data for the font, I am just guessing, nor do I know how to find it out)

Any help would be much appreciated, this has really been hurting my head for a long time now.


p.s. How on earth does the makefile turn data into a header? I've never seen that done before, is that like just something you can do to compile data directly into a program!?!?!
 
Joined
Sep 9, 2019
Messages
904
Trophies
1
Location
Switch scene
Website
github.com
XP
2,663
Country
Korea, North
Use the PL service https://switchbrew.github.io/libnx/pl_8h.html

Here's what I did for my UI library but it's probably more complicated than you need it to be: https://github.com/CompSciOrBust/Arriba/blob/main/source/arribaGraphics.cpp#L47

tl;dr:

You probably know how to use FreeType if you're trying to load raw font files instead of relying on libnx's console but if not it's a common library on other systems. You can find lots of non-switch specific examples that will work on Switch, and my UI library uses it so you can look at how that works.
 

noneuclideanmotion

Member
OP
Newcomer
Joined
Nov 1, 2022
Messages
13
Trophies
0
Age
22
XP
72
Country
United Kingdom
Sorry I think you misunderstood, I'm trying to load the raw font file in order to use it with libnx's console! Though at this rate I think I'm going to end up making my own console system, or a whole new library haha.

Specifically this is all I'm trying to do:

C++:
PrintConsole temp = {
        //Font:
        {
           /* font data goes here, if I put in the default font bin it works fine, anything else it doesn't*/, //font gfx
            0, //first ascii character in the set
            256, //number of characters in the font set
            16, //tile width
            16, //tile height
        },
        NULL,   //renderer
        0,0,    //cursorX cursorY
        0,0,    //prevcursorX prevcursorY
        80,        //console width
        45,        //console height
        0,        //window x
        0,        //window y
        80,        //window width
        45,        //window height
        3,        //tab size
        2,        // foreground color
        4,        // background color
        0,        // flags
        false    //console initialized
    };

consoleInit(&temp);

It's not all that compicated.
 
Joined
Sep 9, 2019
Messages
904
Trophies
1
Location
Switch scene
Website
github.com
XP
2,663
Country
Korea, North
Sorry I think you misunderstood, I'm trying to load the raw font file in order to use it with libnx's console! Though at this rate I think I'm going to end up making my own console system, or a whole new library haha.

Specifically this is all I'm trying to do:

C++:
PrintConsole temp = {
        //Font:
        {
           /* font data goes here, if I put in the default font bin it works fine, anything else it doesn't*/, //font gfx
            0, //first ascii character in the set
            256, //number of characters in the font set
            16, //tile width
            16, //tile height
        },
        NULL,   //renderer
        0,0,    //cursorX cursorY
        0,0,    //prevcursorX prevcursorY
        80,        //console width
        45,        //console height
        0,        //window x
        0,        //window y
        80,        //window width
        45,        //window height
        3,        //tab size
        2,        // foreground color
        4,        // background color
        0,        // flags
        false    //console initialized
    };

consoleInit(&temp);

It's not all that compicated.
Ah ok yeah I think I misunderstood. Can you clarify what you're putting as the gfx field of ConsoleFont? (https://switchbrew.github.io/libnx/structConsoleFont.html) Like are you loading the font in to a buffer and setting the field to that address? Or are you processing it in some way first?

p.s. How on earth does the makefile turn data into a header? I've never seen that done before, is that like just something you can do to compile data directly into a program!?!?!
Also for this are you talking about RomFS?
 

noneuclideanmotion

Member
OP
Newcomer
Joined
Nov 1, 2022
Messages
13
Trophies
0
Age
22
XP
72
Country
United Kingdom
Ah ok yeah I think I misunderstood. Can you clarify what you're putting as the gfx field of ConsoleFont? (https://switchbrew.github.io/libnx/structConsoleFont.html) Like are you loading the font in to a buffer and setting the field to that address? Or are you processing it in some way first?


Also for this are you talking about RomFS?
Basically when I looked at how the library itself loads the default font, it uses some black magic makefile stuff. It has the file "default_font.bin" and the code includes "default_font_bin.h" and the makefile somehow makes that work using this code:
Code:
BINFILES    :=    $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

...

export OFILES_BIN    :=    $(addsuffix .o,$(BINFILES))
export OFILES_SRC    :=    $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES     :=    $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN    :=    $(addsuffix .h,$(subst .,_,$(BINFILES)))

edit: Looking at the files in notepad++, it looks like they might be different formats. The .nxfnt files have a "fFNT" identifier at the beginning, while the .bin font does not. Now I just need to figure out what the format of the .bin font and .nxfnt fonts are so I can convert between them...

Post automatically merged:


What is your final goal? libnx's console does not support unicode, so default font is enough.
the goal is in of itself to load another font, just the ability to do it.
 
Last edited by noneuclideanmotion,
  • Like
Reactions: CompSciOrBust

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    Veho @ Veho: Has he had seizures before?