Jump to content
  • Advertisement
Sign in to follow this  
The_Nerd

OpenGL FreeType + OpenGL help

This topic is 5050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright. I got FreeType2 working fine. My only problem is that I don't know how to locate the font buffers from FreeType2 into my set size textures (64x64... or what ever). Do I just center on the X axis and drop it to the bottom of the image? What does the left and top variables in FT_BitmapGlyphRec do? Are they the center of the glyph, and do I just line that center up with the center of my image? I am lost. Please help. How do I know where to position the glyph buffers in my texture images? Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Ok. Look at my problem at please explain to me how to fix it. Thanks.

Screenshot

How do I make the periods goto the bottom? I was thinking I could just "bottom" all the characters, but then what about '-' and '+', etc... What field in FT_Face tells you the offset amount?

Oh by the way. Right now I am just centering all the bitmaps from FreeType in a 32x32 texture.

Code to build textures using FreeType2:
/*------------------------------------------------------------------------------------------------------------------*/
bool VID_BuildGLFont(uchar8 *ucpFontName, uint16 uiIndex)
{
FT_Face Face;
ENG_FILE *FileHandle;
uchar8 *ucpBuffer;
ulong32 ulSize;
uint16 uiI, uiJ, uiJJ, uiX, uiY;
float32 fOffX, fOffY;
Ner3DFont *CurrentFont=&tpFonts[uiGFontCount];
Ner3DImage *Char;

FileHandle = ENG_FileOpen((char *)ucpFontName);
if (!FileHandle) return false;
ulSize=ENG_FileSize(FileHandle);
ucpBuffer=(uchar8 *)malloc(ulSize);
if (!ucpBuffer) return false;
ENG_FileRead(ucpBuffer, ulSize, FileHandle);
ENG_FileClose(FileHandle);

if (FT_New_Memory_Face(FontLibrary, ucpBuffer, ulSize, uiIndex, &Face)) return false;
//FT_Set_Char_Size(Face,16.0*26.6,16.0*26.6,72,72);
FT_Set_Pixel_Sizes(Face, DEFAULT_CHAR_WIDTH-1, DEFAULT_CHAR_WIDTH-1);
//n3dDebug("%d/%d/%d/%d", Face->bbox.xMin/64, Face->bbox.yMin/64, Face->bbox.xMax/64, Face->bbox.yMax/64);
for (uiI=0;uiI<256;uiI++)
{
FT_Load_Glyph(Face, FT_Get_Char_Index(Face, uiI), FT_LOAD_DEFAULT);
FT_Render_Glyph(Face->glyph, FT_RENDER_MODE_NORMAL);
Char=&CurrentFont->Chars[uiI].Glyph;
Char->New(DEFAULT_CHAR_WIDTH, DEFAULT_CHAR_WIDTH, 32);
//n3dDebug("%d = %d/%d", uiI, Face->glyph->bitmap.width, Face->glyph->bitmap.rows);
//n3dDebug("Baby: %d", Face->glyph->bitmap.pixel_mode);
fOffX=(float32)(DEFAULT_CHAR_WIDTH-Face->glyph->bitmap.width)/2.0;
fOffY=(float32)(DEFAULT_CHAR_WIDTH-Face->glyph->bitmap.rows)/2.0;
if (Face->glyph->bitmap.pixel_mode==FT_PIXEL_MODE_GRAY)
{
for (uiJ=0;uiJ<Face->glyph->bitmap.rows;uiJ++)
for (uiJJ=0;uiJJ<Face->glyph->bitmap.width;uiJJ++)
{
uiY=uiJ+fOffY;
uiX=uiJJ+fOffX;
//n3dDebug("Offset for %c = %d, %d", uiI, Face->glyph->bitmap_left, Face->glyph->bitmap_left);
memset(Char->Buffer[uiY*DEFAULT_CHAR_WIDTH+uiX], Face->glyph->bitmap.buffer[uiJ*Face->glyph->bitmap.width+uiJJ], 4);
//Char->Buffer[uiJ*4][3]=256;
}
}
//CurrentFont->Chars[uiI].Matrix=Face->glyph->metrics;
CurrentFont->Chars[uiI].iLeft=Face->glyph->bitmap_left;
CurrentFont->Chars[uiI].iTop=Face->glyph->bitmap_top;
//n3dDebug("Baring: %d %d", Face->glyph->bitmap_left, Face->glyph->bitmap_top);
Char->uiFlags=1;
Char->Bind();
//Char->Free(true);
}
uiGFontCount++;
}
/*------------------------------------------------------------------------------------------------------------------*/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!