Skip to content

Commit

Permalink
Add new glyphs to font (typographer's quotes, copyright sign)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorio committed Jan 8, 2023
1 parent 5ee9920 commit e8e3961
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 30 deletions.
9 changes: 7 additions & 2 deletions Data/Images/Textures/3000.sfl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
font
font (partial windows-1252)
32 57
3000.tga
95
100
32 1 41 0 0 0 57 13
33 2 4 10 38 2 20 13
34 13 4 15 12 1 20 17
Expand Down Expand Up @@ -97,4 +97,9 @@ font
124 311 191 8 45 2 20 12
125 320 191 19 45 -1 20 17
126 340 208 24 11 2 37 27
145 401 191 13 14 1 20 13
146 415 191 14 14 -1 20 13
147 430 191 24 14 1 20 24
148 455 191 24 14 -1 20 24
169 365 191 35 38 0 20 34
0
Binary file modified Data/Images/Textures/3000.tga
Binary file not shown.
59 changes: 37 additions & 22 deletions src/QD3D/TextMesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "game.h"
#include <stdio.h>

#define MAX_CODEPOINTS 256

typedef struct
{
float x;
Expand All @@ -17,9 +19,8 @@ typedef struct
} AtlasGlyph;

static GLuint gFontTexture = 0;
static int gNumGlyphs = 0;
static float gLineHeight = 0;
static AtlasGlyph* gAtlasGlyphs = NULL;
static AtlasGlyph gAtlasGlyphs[MAX_CODEPOINTS];

static const TextMeshDef gDefaultTextMeshDef =
{
Expand Down Expand Up @@ -56,7 +57,7 @@ TQ3TriMeshData* TextMesh_SetMesh(const TextMeshDef* def, const char* text, TQ3Tr
spacing = def->letterSpacing;
}

GAME_ASSERT(gAtlasGlyphs);
// GAME_ASSERT(gAtlasGlyphs);
GAME_ASSERT(gFontTexture);

// Compute number of quads and line width
Expand All @@ -67,9 +68,7 @@ TQ3TriMeshData* TextMesh_SetMesh(const TextMeshDef* def, const char* text, TQ3Tr
if (*c == '\n') // TODO: line widths for strings containing line breaks aren't supported yet
continue;

GAME_ASSERT(*c >= ' ');
GAME_ASSERT(*c <= '~');
const AtlasGlyph g = gAtlasGlyphs[*c - ' '];
const AtlasGlyph g = gAtlasGlyphs[(uint8_t) *c];
lineWidth += g.xadv + spacing;
if (*c != ' ')
numQuads++;
Expand Down Expand Up @@ -116,9 +115,7 @@ TQ3TriMeshData* TextMesh_SetMesh(const TextMeshDef* def, const char* text, TQ3Tr
continue;
}

GAME_ASSERT(*c >= ' ');
GAME_ASSERT(*c <= '~');
const AtlasGlyph g = gAtlasGlyphs[*c - ' '];
const AtlasGlyph g = gAtlasGlyphs[(uint8_t) *c];

if (*c == ' ')
{
Expand Down Expand Up @@ -177,36 +174,52 @@ static void ParseSFL(const char* data)
{
int nArgs = 0;
int junk = 0;
int numGlyphs = 0;

SkipLine(&data); // Skip font name
// Skip font name
SkipLine(&data);

// Get line height (first int is font size)
nArgs = sscanf(data, "%d %f", &junk, &gLineHeight);
GAME_ASSERT(nArgs == 2);
SkipLine(&data);

SkipLine(&data); // Skip image filename
// Skip image filename
SkipLine(&data);

nArgs = sscanf(data, "%d", &gNumGlyphs);
// Get glyph count
nArgs = sscanf(data, "%d", &numGlyphs);
GAME_ASSERT(nArgs == 1);
GAME_ASSERT(numGlyphs <= MAX_CODEPOINTS);
SkipLine(&data);

#if 0
GAME_ASSERT_MESSAGE(!gAtlasGlyphs, "atlas glyphs were already loaded");
gAtlasGlyphs = (AtlasGlyph*) NewPtrClear(gNumGlyphs * sizeof(AtlasGlyph));
gAtlasGlyphs = (AtlasGlyph*) NewPtrClear(numGlyphs * sizeof(AtlasGlyph));
#endif

for (int i = 0; i < gNumGlyphs; i++)
for (int i = 0; i < numGlyphs; i++)
{
int codepoint = 0;
AtlasGlyph g = {0};

nArgs = sscanf(
data,
"%d %f %f %f %f %f %f %f",
&junk,
&gAtlasGlyphs[i].x,
&gAtlasGlyphs[i].y,
&gAtlasGlyphs[i].w,
&gAtlasGlyphs[i].h,
&gAtlasGlyphs[i].xoff,
&gAtlasGlyphs[i].yoff,
&gAtlasGlyphs[i].xadv);
&codepoint,
&g.x,
&g.y,
&g.w,
&g.h,
&g.xoff,
&g.yoff,
&g.xadv);

GAME_ASSERT(nArgs == 8);
GAME_ASSERT(codepoint >= 0);
GAME_ASSERT(codepoint < MAX_CODEPOINTS);

gAtlasGlyphs[codepoint] = g;

SkipLine(&data);
}
Expand Down Expand Up @@ -239,11 +252,13 @@ void TextMesh_Init(void)

void TextMesh_Shutdown(void)
{
#if 0
if (gAtlasGlyphs)
{
DisposePtr((Ptr) gAtlasGlyphs);
gAtlasGlyphs = NULL;
}
#endif

if (gFontTexture)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Screens/BonusScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ int mouseY = 0;

tmd.coord = (TQ3Point3D) {50,-100,0};
tmd.color = TQ3ColorRGBA_FromInt(0xe54c19ff);
TextMesh_Create(&tmd, "Don't save yet");
TextMesh_Create(&tmd, "Don\222t save yet");

captionsCreatedYet = true;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Screens/FileSelect.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static void MakeFileObjects(const int fileNumber, bool createPickables)
snprintf(textBuffer, sizeof(textBuffer), "Level %d: %s", 1 + saveData.realLevel, kLevelNames[saveData.realLevel]);

tmd.coord.y = y+70*gs;
tmd.scale = .25f * gs;
tmd.scale = .2f * gs;
TextMesh_Create(&tmd, textBuffer);

time_t timestamp = saveData.timestamp;
Expand Down Expand Up @@ -379,8 +379,6 @@ static void SetupFileScreen(void)
}
else
{
//TextMesh_Create(&tmd, "Save where?");

snprintf(textBuffer, sizeof(textBuffer), "Entering level %d. Save where?", gRealLevel+2);
tmd.scale = .33f;
tmd.color = gTitleTextColor;
Expand All @@ -391,7 +389,7 @@ static void SetupFileScreen(void)
tmd.scale = .33f;
tmd.color = gDeleteColor;
tmd.align = TEXTMESH_ALIGN_RIGHT;
TextMesh_Create(&tmd, "Don't save");
TextMesh_Create(&tmd, "Don\222t save");

// Make floppy
gNewObjectDefinition.group = MODEL_GROUP_BONUS;
Expand Down
2 changes: 1 addition & 1 deletion src/Screens/SettingsScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static const char* GenerateKiddieModeSubtitle(void)

static const char* GenerateDetailSubtitle(void)
{
return gGamePrefs.lowDetail ? "The \"ATI Rage II\" look" : NULL;
return gGamePrefs.lowDetail ? "The \223ATI Rage II\224 look" : NULL;
}

#if !(__APPLE__)
Expand Down

0 comments on commit e8e3961

Please sign in to comment.