From f90a2a273cad61bf3351ebde72deb510008f9324 Mon Sep 17 00:00:00 2001 From: Allanis Date: Mon, 4 Feb 2013 09:32:03 +0000 Subject: [PATCH] [Change] Load fonts from project directory, throw it in data pack. --- bin/Makefile | 2 +- scripts/ai/test.lua | 1 + src/main.c | 2 +- src/opengl.c | 10 ++++++++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/Makefile b/bin/Makefile index de4299e..a284a43 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -29,7 +29,7 @@ LDGL = -lGL LDFLAGS = -lm $(LDLUA) $(LDSDL) $(LDXML) $(LDTTF) $(LDGL) DATA = data -DATAFILES = $(shell find ../scripts/ai/ ../gfx/ ../dat/ -name '*.lua' -o -name '*.png' -o -name '*.xml') +DATAFILES = $(shell find ../scripts/ ../gfx/ ../dat/ -name '*.lua' -o -name '*.png' -o -name '*.xml' -o -name '*.ttf') %.o: %.c %.h @gcc -c $(CFLAGS) -o $@ $< diff --git a/scripts/ai/test.lua b/scripts/ai/test.lua index f64f3e6..09a1a41 100644 --- a/scripts/ai/test.lua +++ b/scripts/ai/test.lua @@ -1,5 +1,6 @@ function follow() face(1,1) + accel(1) end function goto() diff --git a/src/main.c b/src/main.c index 432d4f8..6384edd 100644 --- a/src/main.c +++ b/src/main.c @@ -192,7 +192,7 @@ int main(int argc, char** argv) { if(ai_init()) WARN("Error initializing AI"); - gl_fontInit(NULL, "../gfx/fonts/FreeSans.ttf", 16); + gl_fontInit(NULL, NULL, 16); // Data loading. ships_load(); diff --git a/src/opengl.c b/src/opengl.c index efd0648..aa0b43d 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -15,6 +15,8 @@ #define SCREEN_W gl_screen.w #define SCREEN_H gl_screen.h +#define FONT_DEF "../gfx/fonts/FreeSans.ttf" + // The screen info, gives data of current opengl settings. gl_info gl_screen; @@ -422,6 +424,9 @@ static void gl_fontMakeDList(FT_Face face, char ch, GLuint list_base, GLuint* te void gl_fontInit(gl_font* font, const char* fname, unsigned int h) { if(font == NULL) font = &gl_defFont; + + uint32_t bufsize; + FT_Byte* buf = pack_readfile(DATA, (fname) ? fname : FONT_DEF, &bufsize); font->textures = malloc(sizeof(GLuint)*128); font->h = h; @@ -434,8 +439,8 @@ void gl_fontInit(gl_font* font, const char* fname, unsigned int h) { // Objects that freetype uses to store font info. FT_Face face; - if(FT_New_Face(library, fname, 0, &face)) - WARN("FT_New_Face failed loading library from %s", fname); + if(FT_New_Memory_Face(library, buf, bufsize, 0, &face)) + WARN("FT_New_Memory_Face failed loading library from %s", fname); // FreeType is pretty nice and measures using 1/64 of a pixel, therfore expand. FT_Set_Char_Size(face, h << 6, h << 6, 96, 96); @@ -452,6 +457,7 @@ void gl_fontInit(gl_font* font, const char* fname, unsigned int h) { // We can now free the face and library. FT_Done_Face(face); FT_Done_FreeType(library); + free(buf); } void gl_freeFont(gl_font* font) {