Get font rendering working
This commit is contained in:
parent
33e997309e
commit
aa3ea24c16
6
Makefile
6
Makefile
|
@ -140,6 +140,10 @@ build/assets/materials/static.h build/assets/materials/static_mat.c: assets/mate
|
|||
@mkdir -p $(@D)
|
||||
$(SKELATOOL64) --name static -m $< --material-output -o build/assets/materials/static.h
|
||||
|
||||
build/assets/materials/ui.h build/assets/materials/ui_mat.c: assets/materials/ui.skm.yaml $(TEXTURE_IMAGES) $(SKELATOOL64)
|
||||
@mkdir -p $(@D)
|
||||
$(SKELATOOL64) --name ui --default-material default_ui -m $< --material-output -o build/assets/materials/ui.h
|
||||
|
||||
build/assets/materials/hud.h build/assets/materials/hud_mat.c: assets/materials/hud.skm.yaml $(TEXTURE_IMAGES) $(SKELATOOL64)
|
||||
@mkdir -p $(@D)
|
||||
$(SKELATOOL64) --name hud -m $< --material-output -o build/assets/materials/hud.h
|
||||
|
@ -355,7 +359,7 @@ $(BOOT_OBJ): $(BOOT)
|
|||
|
||||
# without debugger
|
||||
|
||||
CODEOBJECTS = $(patsubst %.c, build/%.o, $(CODEFILES)) $(MODEL_OBJECTS) build/assets/materials/static_mat.o build/assets/materials/hud_mat.o
|
||||
CODEOBJECTS = $(patsubst %.c, build/%.o, $(CODEFILES)) $(MODEL_OBJECTS) build/assets/materials/static_mat.o build/assets/materials/ui_mat.o build/assets/materials/hud_mat.o
|
||||
|
||||
CODEOBJECTS_NO_DEBUG = $(CODEOBJECTS)
|
||||
|
||||
|
|
96
assets/fonts/dejavu_sans_license.txt
Normal file
96
assets/fonts/dejavu_sans_license.txt
Normal file
|
@ -0,0 +1,96 @@
|
|||
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain. Glyphs imported from Arev fonts are (c) Tavmjung Bah (see below)
|
||||
|
||||
Bitstream Vera Fonts Copyright
|
||||
------------------------------
|
||||
|
||||
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
|
||||
a trademark of Bitstream, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of the fonts accompanying this license ("Fonts") and associated
|
||||
documentation files (the "Font Software"), to reproduce and distribute the
|
||||
Font Software, including without limitation the rights to use, copy, merge,
|
||||
publish, distribute, and/or sell copies of the Font Software, and to permit
|
||||
persons to whom the Font Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
|
||||
The above copyright and trademark notices and this permission notice shall
|
||||
be included in all copies of one or more of the Font Software typefaces.
|
||||
|
||||
The Font Software may be modified, altered, or added to, and in particular
|
||||
the designs of glyphs or characters in the Fonts may be modified and
|
||||
additional glyphs or characters may be added to the Fonts, only if the fonts
|
||||
are renamed to names not containing either the words "Bitstream" or the word
|
||||
"Vera".
|
||||
|
||||
This License becomes null and void to the extent applicable to Fonts or Font
|
||||
Software that has been modified and is distributed under the "Bitstream
|
||||
Vera" names.
|
||||
|
||||
The Font Software may be sold as part of a larger software package but no
|
||||
copy of one or more of the Font Software typefaces may be sold by itself.
|
||||
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
|
||||
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
|
||||
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
|
||||
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
||||
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
|
||||
FONT SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of Gnome, the Gnome
|
||||
Foundation, and Bitstream Inc., shall not be used in advertising or
|
||||
otherwise to promote the sale, use or other dealings in this Font Software
|
||||
without prior written authorization from the Gnome Foundation or Bitstream
|
||||
Inc., respectively. For further information, contact: fonts at gnome dot
|
||||
org.
|
||||
|
||||
Arev Fonts Copyright
|
||||
------------------------------
|
||||
|
||||
Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the fonts accompanying this license ("Fonts") and
|
||||
associated documentation files (the "Font Software"), to reproduce
|
||||
and distribute the modifications to the Bitstream Vera Font Software,
|
||||
including without limitation the rights to use, copy, merge, publish,
|
||||
distribute, and/or sell copies of the Font Software, and to permit
|
||||
persons to whom the Font Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright and trademark notices and this permission notice
|
||||
shall be included in all copies of one or more of the Font Software
|
||||
typefaces.
|
||||
|
||||
The Font Software may be modified, altered, or added to, and in
|
||||
particular the designs of glyphs or characters in the Fonts may be
|
||||
modified and additional glyphs or characters may be added to the
|
||||
Fonts, only if the fonts are renamed to names not containing either
|
||||
the words "Tavmjong Bah" or the word "Arev".
|
||||
|
||||
This License becomes null and void to the extent applicable to Fonts
|
||||
or Font Software that has been modified and is distributed under the
|
||||
"Tavmjong Bah Arev" names.
|
||||
|
||||
The Font Software may be sold as part of a larger software package but
|
||||
no copy of one or more of the Font Software typefaces may be sold by
|
||||
itself.
|
||||
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
|
||||
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of Tavmjong Bah shall not
|
||||
be used in advertising or otherwise to promote the sale, use or other
|
||||
dealings in this Font Software without prior written authorization
|
||||
from Tavmjong Bah. For further information, contact: tavmjong @ free
|
||||
. fr.
|
25
assets/materials/ui.skm.yaml
Normal file
25
assets/materials/ui.skm.yaml
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
materials:
|
||||
default_ui:
|
||||
gSPGeometryMode:
|
||||
clear: [G_ZBUFFER, G_LIGHTING, G_SHADE]
|
||||
gDPSetTextureLUT: G_TT_NONE
|
||||
gDPSetTexturePersp: G_TP_NONE
|
||||
gDPSetRenderMode: G_RM_XLU_SURF
|
||||
|
||||
sortOrder: 10
|
||||
|
||||
dejavu_sans:
|
||||
gDPSetTile:
|
||||
filename: "../fonts/dejavu_sans.png"
|
||||
siz: G_IM_SIZ_4b
|
||||
fmt: G_IM_FMT_I
|
||||
gDPSetCombineMode:
|
||||
color: ["0", "0", "0", ENVIRONMENT]
|
||||
alpha: [TEXEL0, "0", ENVIRONMENT, "0"]
|
||||
gDPSetRenderMode: G_RM_XLU_SURF
|
||||
gDPSetEnvColor:
|
||||
r: 255
|
||||
g: 255
|
||||
b: 255
|
||||
a: 255
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
|
||||
#include "font.h"
|
||||
#include "dejavusans.h"
|
||||
|
||||
struct FontKerning gDejaVuSansKerning[] = {
|
||||
{.amount = -1, .first = 76, .second = 84},
|
||||
|
|
8
src/font/dejavusans.h
Normal file
8
src/font/dejavusans.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef __FONT_DEJAVUSANS_H__
|
||||
#define __FONT_DEJAVUSANS_H__
|
||||
|
||||
#include "font.h"
|
||||
|
||||
extern struct Font gDejaVuSansFont;
|
||||
|
||||
#endif
|
|
@ -20,4 +20,64 @@ int fontDetermineKerning(struct Font* font, char first, char second) {
|
|||
} while (maxIterations >= 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Gfx* fontRender(struct Font* font, char* message, int x, int y, Gfx* dl) {
|
||||
int startX = x;
|
||||
char prev = 0;
|
||||
|
||||
for (; *message; prev = *message, ++message) {
|
||||
char curr = *message;
|
||||
|
||||
if (curr == '\n') {
|
||||
y += font->charHeight;
|
||||
x = startX;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((unsigned char)curr >= font->symbolCount) {
|
||||
continue;
|
||||
}
|
||||
|
||||
struct FontSymbol* symbol = &font->symbols[(int)curr];
|
||||
|
||||
x += fontDetermineKerning(font, prev, curr);
|
||||
|
||||
int finalX = x + symbol->xoffset;
|
||||
int finalY = y + symbol->yoffset;
|
||||
|
||||
gSPTextureRectangle(
|
||||
dl++,
|
||||
finalX << 2, finalY << 2,
|
||||
(finalX + symbol->width) << 2,
|
||||
(finalY + symbol->height) << 2,
|
||||
G_TX_RENDERTILE,
|
||||
symbol->x << 5, symbol->y << 5,
|
||||
0x400, 0x400
|
||||
);
|
||||
|
||||
x += symbol->xadvance;
|
||||
}
|
||||
|
||||
return dl;
|
||||
}
|
||||
|
||||
int fontCountGfx(struct Font* font, char* message) {
|
||||
int result = 0;
|
||||
|
||||
for (; *message; ++message) {
|
||||
char curr = *message;
|
||||
|
||||
if (curr == '\n') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((unsigned char)curr >= font->symbolCount) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result += 3;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef __FONT_FONT_H__
|
||||
#define __FONT_FONT_H__
|
||||
|
||||
#include <ultra64.h>
|
||||
|
||||
struct FontKerning {
|
||||
char amount;
|
||||
char first;
|
||||
|
@ -26,4 +28,8 @@ struct Font {
|
|||
unsigned short maxCollisions;
|
||||
};
|
||||
|
||||
int fontDetermineKerning(struct Font* font, char first, char second);
|
||||
Gfx* fontRender(struct Font* font, char* message, int x, int y, Gfx* dl);
|
||||
int fontCountGfx(struct Font* font, char* message);
|
||||
|
||||
#endif
|
|
@ -17,7 +17,6 @@ function checkForCollisions(kerningList, multiplier, arraySize) {
|
|||
return null;
|
||||
}
|
||||
|
||||
let totalCollisions = 0;
|
||||
let maxCollisions = 0;
|
||||
|
||||
for (const kerning of kerningList) {
|
||||
|
@ -27,7 +26,6 @@ function checkForCollisions(kerningList, multiplier, arraySize) {
|
|||
|
||||
while (sparseArray[index]) {
|
||||
index = (index + 1) % arraySize;
|
||||
totalCollisions = totalCollisions + 1;
|
||||
currentCollisions = currentCollisions + 1;
|
||||
}
|
||||
|
||||
|
@ -42,7 +40,7 @@ function checkForCollisions(kerningList, multiplier, arraySize) {
|
|||
}
|
||||
}
|
||||
|
||||
return {sparseArray, totalCollisions, maxCollisions};
|
||||
return {sparseArray, maxCollisions};
|
||||
}
|
||||
|
||||
function searchForBestKerning(kerningList) {
|
||||
|
@ -62,17 +60,17 @@ function searchForBestKerning(kerningList) {
|
|||
for (let i = 1; i < 0x10000; ++i) {
|
||||
const check = checkForCollisions(kerningList, i, arraySize);
|
||||
|
||||
if (!result || check.totalCollisions < result.totalCollisions) {
|
||||
if (!result || check.maxCollisions < result.maxCollisions) {
|
||||
result = check
|
||||
multiplier = i;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`totalCollisions = ${result.totalCollisions}`);
|
||||
console.log(`maxCollisions = ${result.maxCollisions}`);
|
||||
|
||||
mask -= 1;
|
||||
|
||||
return {result: result.sparseArray, multiplier: multiplier, mask: mask, totalCollisions: result.totalCollisions, maxCollisions: result.maxCollisions};
|
||||
return {result: result.sparseArray, multiplier: multiplier, mask: mask, maxCollisions: result.maxCollisions};
|
||||
}
|
||||
|
||||
function buildKerning(kerningList) {
|
||||
|
|
Loading…
Reference in a new issue