rougier / freetype-gl

OpenGL text using one vertex buffer, one texture and FreeType
Other
1.65k stars 266 forks source link

texture_font_new_from_file isn't working #214

Closed AceKiron closed 5 years ago

AceKiron commented 5 years ago

I am following TheCherno's Sparky Game Engine series on youtube (https://www.youtube.com/watch?v=Rsdc6I80aFQ&list=PLlrATfBNZ98fqE45g3jZA_hLGUrD4bo6_&index=25&t=37m34s) but the atlas looks like image even after I added a glyph

FTAtlas = texture_atlas_new(512, 512, 1);
FTFont = texture_font_new_from_file(FTAtlas, 20, "arial.ttf");
texture_font_get_glyph(FTFont, new char('A'));

He did texture_font_get_glyph(FTFont, 'A'); and I had to do texture_font_get_glyph(FTFont, new char('A')); but that's probably just of his being an older version.

AceKiron commented 5 years ago

nvm got it working, had to just do

glBindTexture(GL_TEXTURE_2D, FTAtlas->id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, FTAtlas->width, FTAtlas->height, 0, GL_RED, GL_UNSIGNED_BYTE, FTAtlas->data);
wmamrak commented 5 years ago

texture_font_get_glyph(FTFont, new char('A')); is a memory leak; you should do texture_font_get_glyph(FTFont, "A");

ltqsoft commented 5 years ago

freetype-gl uses utf-8 charset, which may cost more than one character for each glyph, thus you should pass a string which corresponds to the utf-32 codepoint of the glyph itself. And inside this repo source files you will also find a way to iterate each of the codepoints in your utf-8 string.

AceKiron commented 5 years ago

Already got it fixed