[Change] Cleaned up font stuff somewhat.
This commit is contained in:
parent
3e61178e6d
commit
8471f53cc2
39
src/font.c
39
src/font.c
@ -17,8 +17,8 @@
|
||||
#include "font.h"
|
||||
|
||||
#include "ft2build.h"
|
||||
#include <freetype2/freetype.h>
|
||||
#include <freetype2/ftglyph.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_GLYPH_H
|
||||
|
||||
#include "lephisto.h"
|
||||
#include "log.h"
|
||||
@ -427,25 +427,20 @@ int gl_printHeight(const glFont* ft_font, const int width,
|
||||
*/
|
||||
static void glFontMakeDList(FT_Face face, char ch, GLuint list_base,
|
||||
GLuint* tex_base, int* width_base) {
|
||||
FT_Glyph glyph;
|
||||
FT_Bitmap bitmap;
|
||||
GLubyte* expanded_data;
|
||||
FT_GlyphSlot slot;
|
||||
int w, h;
|
||||
int i, j;
|
||||
double x, y;
|
||||
|
||||
if(FT_Load_Glyph(face, FT_Get_Char_Index(face, ch),
|
||||
FT_LOAD_DEFAULT))
|
||||
WARN("FT_Load_Glyph failed");
|
||||
slot = face->glyph; /* Small shortcut. */
|
||||
|
||||
if(FT_Get_Glyph(face->glyph, &glyph))
|
||||
WARN("FT_Ge_Glyph failed");
|
||||
/* Load the glyph. */
|
||||
if(FT_Load_Char(face, ch, FT_LOAD_RENDER))
|
||||
WARN("FT_Load_Char failed.");
|
||||
|
||||
/* Convert your glyph to a bitmap. */
|
||||
FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1);
|
||||
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
|
||||
|
||||
bitmap = bitmap_glyph->bitmap; /* To simplify. */
|
||||
bitmap = slot->bitmap; /* To simplify. */
|
||||
|
||||
/* Need the POT wrapping for GL. */
|
||||
w = gl_pot(bitmap.width);
|
||||
@ -476,7 +471,7 @@ static void glFontMakeDList(FT_Face face, char ch, GLuint list_base,
|
||||
/* Corrects a spacing flaw between letters and */
|
||||
/* downwards correction for letters like g or y. */
|
||||
glPushMatrix();
|
||||
glTranslated(bitmap_glyph->left, bitmap_glyph->top-bitmap.rows, 0);
|
||||
glTranslated(slot->bitmap_left, slot->bitmap_top - bitmap.rows, 0);
|
||||
|
||||
/* Take the opengl POT wrapping into account. */
|
||||
x = (double)bitmap.width/(double)w;
|
||||
@ -496,14 +491,12 @@ static void glFontMakeDList(FT_Face face, char ch, GLuint list_base,
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
glTranslated(face->glyph->advance.x >> 6, 0,0);
|
||||
width_base[(int)ch] = (int)(face->glyph->advance.x >> 6);
|
||||
glTranslated(slot->advance.x >> 6, slot->advance.y >> 6, 0);
|
||||
width_base[(int)ch] = slot->advance.x >> 6;
|
||||
|
||||
/* End of the display list. */
|
||||
glEndList();
|
||||
|
||||
FT_Done_Glyph(glyph);
|
||||
|
||||
gl_checkErr();
|
||||
}
|
||||
|
||||
@ -544,7 +537,15 @@ void gl_fontInit(glFont* font, const char* fname, const unsigned int h) {
|
||||
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);
|
||||
FT_Set_Char_Size(face,
|
||||
0, /* Same as width. */
|
||||
h << 6, /* In 1/64th of a pixel. */
|
||||
96,
|
||||
96);
|
||||
|
||||
/* Selected the character map. */
|
||||
if(FT_Select_Charmap(face, FT_ENCODING_UNICODE))
|
||||
WARN("FT_Select_Charmap failed to change character mapping.");
|
||||
|
||||
/* Have OpenGL allocate space for the textures / display lists. */
|
||||
font->list_base = glGenLists(128);
|
||||
|
Loading…
Reference in New Issue
Block a user