mirror of
https://github.com/AntonioND/architectds.git
synced 2025-06-19 09:05:43 -04:00
examples: Add example of rich text with Nitro Engine
This commit is contained in:
parent
04cdac1f2a
commit
d1e6ed38ef
8
examples/nitro_engine/font_from_nitrofs/.gitignore
vendored
Normal file
8
examples/nitro_engine/font_from_nitrofs/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
__pycache__/
|
||||
graph.png
|
||||
*.nds
|
||||
*.sav
|
||||
build/
|
||||
.ninja_deps
|
||||
.ninja_log
|
||||
*.ninja
|
1
examples/nitro_engine/font_from_nitrofs/architectds
Symbolic link
1
examples/nitro_engine/font_from_nitrofs/architectds
Symbolic link
@ -0,0 +1 @@
|
||||
../../../architectds
|
31
examples/nitro_engine/font_from_nitrofs/build.py
Normal file
31
examples/nitro_engine/font_from_nitrofs/build.py
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
# SPDX-FileContributor: Antonio Niño Díaz, 2024
|
||||
|
||||
from architectds import *
|
||||
|
||||
nitrofs = NitroFS()
|
||||
nitrofs.add_grit(['fonts'], out_dir='fonts')
|
||||
nitrofs.add_bmfont_fnt(['fonts'], out_dir='fonts')
|
||||
nitrofs.generate_image()
|
||||
|
||||
arm9 = Arm9Binary(
|
||||
sourcedirs=['source'],
|
||||
libs=['NE', 'dsf', 'nds9'],
|
||||
libdirs=[
|
||||
'${BLOCKSDS}/libs/libnds',
|
||||
'${BLOCKSDSEXT}/libdsf',
|
||||
'${BLOCKSDSEXT}/nitro-engine'
|
||||
]
|
||||
)
|
||||
arm9.generate_elf()
|
||||
|
||||
nds = NdsRom(
|
||||
binaries=[arm9, nitrofs],
|
||||
game_title='DSF: NE: BMFont for NDS',
|
||||
)
|
||||
nds.generate_nds()
|
||||
|
||||
nds.run_command_line_arguments()
|
59
examples/nitro_engine/font_from_nitrofs/fonts/font.bmfc
Normal file
59
examples/nitro_engine/font_from_nitrofs/fonts/font.bmfc
Normal file
@ -0,0 +1,59 @@
|
||||
# AngelCode Bitmap Font Generator configuration file
|
||||
fileVersion=1
|
||||
|
||||
# font settings
|
||||
fontName=DejaVu Sans
|
||||
fontFile=
|
||||
charSet=0
|
||||
fontSize=32
|
||||
aa=1
|
||||
scaleH=100
|
||||
useSmoothing=1
|
||||
isBold=0
|
||||
isItalic=0
|
||||
useUnicode=1
|
||||
disableBoxChars=1
|
||||
outputInvalidCharGlyph=0
|
||||
dontIncludeKerningPairs=0
|
||||
useHinting=1
|
||||
renderFromOutline=0
|
||||
useClearType=1
|
||||
autoFitNumPages=0
|
||||
autoFitFontSizeMin=0
|
||||
autoFitFontSizeMax=0
|
||||
|
||||
# character alignment
|
||||
paddingDown=0
|
||||
paddingUp=0
|
||||
paddingRight=0
|
||||
paddingLeft=0
|
||||
spacingHoriz=1
|
||||
spacingVert=1
|
||||
useFixedHeight=0
|
||||
forceZero=0
|
||||
widthPaddingFactor=0.00
|
||||
|
||||
# output file
|
||||
outWidth=256
|
||||
outHeight=256
|
||||
outBitDepth=8
|
||||
fontDescFormat=2
|
||||
fourChnlPacked=0
|
||||
textureFormat=png
|
||||
textureCompression=0
|
||||
alphaChnl=1
|
||||
redChnl=0
|
||||
greenChnl=0
|
||||
blueChnl=0
|
||||
invA=0
|
||||
invR=0
|
||||
invG=0
|
||||
invB=0
|
||||
|
||||
# outline
|
||||
outlineThickness=0
|
||||
|
||||
# selected chars
|
||||
chars=32-126,160-255,65529-65533
|
||||
|
||||
# imported icon images
|
BIN
examples/nitro_engine/font_from_nitrofs/fonts/font.fnt
Normal file
BIN
examples/nitro_engine/font_from_nitrofs/fonts/font.fnt
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
@ -0,0 +1,2 @@
|
||||
# 16-color texture, set black as transparent color
|
||||
-gx -gb -gB4 -gT000000
|
BIN
examples/nitro_engine/font_from_nitrofs/fonts/font_16.png
Normal file
BIN
examples/nitro_engine/font_from_nitrofs/fonts/font_16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@ -0,0 +1,2 @@
|
||||
# 256-color texture, set black as transparent color
|
||||
-gx -gb -gB8 -gT000000
|
BIN
examples/nitro_engine/font_from_nitrofs/fonts/font_256.png
Normal file
BIN
examples/nitro_engine/font_from_nitrofs/fonts/font_256.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
6
examples/nitro_engine/font_from_nitrofs/readme.md
Normal file
6
examples/nitro_engine/font_from_nitrofs/readme.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Rich text font from NitroFS
|
||||
|
||||
This example shows how to load BMFont fonts from Nitro FS. Check the official
|
||||
[website](https://www.angelcode.com/products/bmfont/) to see how to generate
|
||||
them. Remember that the output format must be binary for the font metadata, and
|
||||
PNG for the images.
|
114
examples/nitro_engine/font_from_nitrofs/source/main.c
Normal file
114
examples/nitro_engine/font_from_nitrofs/source/main.c
Normal file
@ -0,0 +1,114 @@
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
//
|
||||
// SPDX-FileContributor: Antonio Niño Díaz, 2024
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <filesystem.h>
|
||||
#include <nds.h>
|
||||
#include <NEMain.h>
|
||||
|
||||
NE_Sprite *TextSprite;
|
||||
|
||||
void Draw3DScene(void)
|
||||
{
|
||||
NE_ClearColorSet(RGB15(0, 7, 7), 31, 63);
|
||||
|
||||
NE_2DViewInit();
|
||||
|
||||
NE_RichTextRender3D(3, "VAWATa\ntajl", 0, 0);
|
||||
|
||||
NE_RichTextRender3DAlpha(2, "Text with alpha", 10, 80,
|
||||
POLY_ALPHA(20) | POLY_CULL_BACK, 30);
|
||||
}
|
||||
|
||||
void Draw3DScene2(void)
|
||||
{
|
||||
NE_ClearColorSet(RGB15(7, 0, 7), 31, 63);
|
||||
|
||||
NE_2DViewInit();
|
||||
|
||||
NE_SpriteSetPos(TextSprite, 16, 32);
|
||||
NE_SpriteDraw(TextSprite);
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) void WaitLoop(void)
|
||||
{
|
||||
printf("Press START to exit");
|
||||
while (1)
|
||||
{
|
||||
swiWaitForVBlank();
|
||||
scanKeys();
|
||||
if (keysHeld() & KEY_START)
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
irqEnable(IRQ_HBLANK);
|
||||
irqSet(IRQ_VBLANK, NE_VBLFunc);
|
||||
irqSet(IRQ_HBLANK, NE_HBLFunc);
|
||||
|
||||
// Init 3D mode
|
||||
NE_InitDual3D();
|
||||
NE_InitConsole();
|
||||
|
||||
if (!nitroFSInit(NULL))
|
||||
{
|
||||
printf("nitroFSInit failed.\n");
|
||||
WaitLoop();
|
||||
}
|
||||
|
||||
// Load a 256-color font to be used for rendering text as quads
|
||||
|
||||
NE_RichTextInit(2);
|
||||
NE_RichTextMetadataLoadFAT(2, "fonts/font.fnt");
|
||||
NE_RichTextMaterialLoadGRF(2, "fonts/font_16_png.grf");
|
||||
|
||||
// Load a 16-color font to be used for rendering text as quads
|
||||
|
||||
NE_RichTextInit(3);
|
||||
NE_RichTextMetadataLoadFAT(3, "fonts/font.fnt");
|
||||
NE_RichTextMaterialLoadGRF(3, "fonts/font_256_png.grf");
|
||||
|
||||
// Load a 16-color font to be used for rendering text to textures.
|
||||
|
||||
NE_RichTextInit(5);
|
||||
NE_RichTextMetadataLoadFAT(5, "fonts/font.fnt");
|
||||
NE_RichTextBitmapLoadGRF(5, "fonts/font_16_png.grf");
|
||||
|
||||
// Render text to a texture using the last font we've loaded
|
||||
|
||||
// We don't care about the palette, passing NULL will mark the palette
|
||||
// to be autodeleted when the material is deleted.
|
||||
NE_Material *Material = NULL;
|
||||
NE_RichTextRenderMaterial(5,
|
||||
"Sample: AWAV.\nÿ_ßðñÑü(o´Áá)|\nInvalid char: ŋ",
|
||||
&Material, NULL);
|
||||
|
||||
// Create a sprite to be used to render the texture we've rendered
|
||||
|
||||
TextSprite = NE_SpriteCreate();
|
||||
NE_SpriteSetMaterial(TextSprite, Material);
|
||||
|
||||
while (1)
|
||||
{
|
||||
NE_WaitForVBL(0);
|
||||
|
||||
NE_ProcessDual(Draw3DScene, Draw3DScene2);
|
||||
|
||||
scanKeys();
|
||||
if (keysHeld() & KEY_START)
|
||||
break;
|
||||
}
|
||||
|
||||
NE_SpriteDelete(TextSprite);
|
||||
NE_MaterialDelete(Material);
|
||||
|
||||
NE_RichTextEnd(2);
|
||||
NE_RichTextEnd(3);
|
||||
NE_RichTextEnd(5);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user