Jump to content
  • Advertisement
Sign in to follow this  

Freetype rendering solid blocks

This topic is 4857 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

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)
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);
    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)

		if (tex_x+width>=256) 
			tex_y += static_cast<int>(CharHeight)+1;

		// 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
    glGenTextures(1, &TextureID);

	glBindTexture(GL_TEXTURE_2D, TextureID);
    delete [] Bitmap;

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]

Share this post

Link to post
Share on other sites
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.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!