GUIFont::GUIFont(const char* fn, int fontsize)
{
// initalize Freetype and create a bitmap for the fonts
int* Bitmap = new int[BitmapSize*BitmapSize];
memset(Bitmap, 0, BitmapSize*BitmapSize*sizeof(int));
CharHeight = 0;
FT_Library library;
FT_Face face;
if( FT_Init_FreeType( &library ) )
{
//... an error occurred during library initialization ...
throw FatalError("Cannot Initalize the FreeType Library");
}
if( FT_New_Face( library, fn, 0, &face ) )
{
//... an error occurred during library initialization ...
throw FatalError("Cannot Initalize the FreeType Face");
}
FT_Set_Char_Size(face,fontsize << 6,fontsize << 6,96,96);
DisplayListID = glGenLists(256);
//* TAKEN FROM TA SPRING *//
int tex_x=0,tex_y=0;
for (unsigned int c=0; c<256; c++)
{
if( FT_Load_Glyph(face, FT_Get_Char_Index(face, c), FT_LOAD_DEFAULT) )
throw FatalError("FT_Load_Glyph failed");
// load glyph
FT_Glyph glyph;
if( FT_Get_Glyph(face->glyph, &glyph) )
throw FatalError("FT_Get_Glyph failed");
// render glyph to bitmap
if( FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, NULL, 1) )
throw FatalError("FT_Glyph_To_Bitmap failed");
FT_BitmapGlyph glyph_bitmap = (FT_BitmapGlyph)glyph;
int width = glyph_bitmap->bitmap.width;
int height = glyph_bitmap->bitmap.rows;
if (height>CharHeight)
CharHeight=height;
if (tex_x+width>=256)
{
tex_y += static_cast<int>(CharHeight)+1;
tex_x=0;
}
// render glyph bitmap to texture
for (int y=0; y<glyph_bitmap->bitmap.rows; y++)
{
for (int x=0; x<glyph_bitmap->bitmap.width; x++)
{
char shade = glyph_bitmap->bitmap.buffer[x+y*glyph_bitmap->bitmap.pitch];
int color = ((int)shade << 24) | 0x00ffffff;
Bitmap[(tex_x+x)+(tex_y+y)*TEXSIZE] = color;
}
}
if( false )////** dumps each bitmap **////
{/*...*/}
CharWidths[c]=glyph->advance.x / (float)0x10000;
// set up display list
//*this works*//
tex_x += width+1;
// discard glyph
FT_Done_Glyph(glyph);
}
//**//
CreateBitmap("Font.bmp",256,256,(void*)Bitmap,32);
glGenTextures(1, &TextureID);
glBindTexture(GL_TEXTURE_2D, TextureID);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 4, TEXSIZE, TEXSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, Bitmap);
FT_Done_FreeType(library);
delete [] Bitmap;
}
Freetype rendering solid blocks
i just begain using freetype to render my 2d text
before i had been using windows to generate the text for me with wglUseFontBitmaps and whatever
so i have freetype set up and render the chars but all it spits out is solid blocks basically the size of the text (it IS size correctly however)
but the code is the same as that from the NeHe turorial (44 i think)
i can't find any diffrence between the taspring and NeHe tutorial that would cause freetype to spit out squares
font.jpg
(in the bitmap the squares are solid white and the background is pure black)
can any one point out where im going wrong
[Edited by - SW INC on December 2, 2005 11:28:00 PM]
I had the same problem. It has something to do with a version mismatch between NeHe and the latest freetype version (api shift or whatnot?)
Try removing the "FT_Get_Char_Index(face, c)" and just replacing it with "c".
If that doesn't work, you might have to dig through the freetype docs/tutorial/example and figure what the differences are between it and the NeHe code.
Try removing the "FT_Get_Char_Index(face, c)" and just replacing it with "c".
If that doesn't work, you might have to dig through the freetype docs/tutorial/example and figure what the differences are between it and the NeHe code.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement