Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Tenshi Moya

Hello. I am having trouble generating a font display list

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

- Hello. I''ve been trying to create a font texture generator so that I can use a variety of different fonts without having to use a file. However, my function is not working properly. If you can give me some help with this, I would greatly appreciate it. - You''ll notice that I had to set the textSize, width, fWidth, height, and fHeight variables to constant values. This is because for some reason the program will crash if I leave them as they are assigned. - The end result of this routine is just white squares... help would be greatly appreciated. =) // Function receives the name of the font and height of the font, and a reference to a variable kept in my Font class to use for Carriage returns. &base is a reference to a display List and texture holds the individual bitmaps of each character in the font.
// Build the font
GLvoid BuildFont(string fontName, int fontHeight, int &fH, GLuint &base, GLubyte **texture )
{
    // Power of 2 dimensions of each texture
    int fWidth;
    int fHeight;
    int textSize;
    
    int maxHeight = 0;

    GLYPHMETRICS GlyphMetrics;
    MAT2 Matrix;
    FIXED f;
    f.fract = 0; f.value = 1;
    Matrix.eM11 = Matrix.eM22 = f;
    f.value = 0;
    Matrix.eM12 = Matrix.eM21 = f;
    
    HFONT font, oldfont;
    base = glGenLists(96);

    font = CreateFont( -fontHeight, 0, 0, 0, FW_BOLD, false, false, false, ANSI_CHARSET,
                            OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
                            FF_DONTCARE|DEFAULT_PITCH, fontName.c_str());

	oldfont = (HFONT)SelectObject(hDC, font);// Selects The Font We Want                            
    for ( WORD charGet = 32; charGet < 128; charGet++ )
    {
        GLubyte *lpBuffer = NULL;
        int Size = GetGlyphOutline(hDC, charGet, GGO_GRAY8_BITMAP, &GlyphMetrics, 0, NULL, &Matrix);
        GetGlyphOutline(hDC, charGet, GGO_METRICS, &GlyphMetrics, 0, NULL, &Matrix);
        lpBuffer = new GLubyte[Size];
        GetGlyphOutline(hDC, charGet, GGO_GRAY8_BITMAP, &GlyphMetrics, Size, lpBuffer, &Matrix);

        // Only 65 levels of gray. Need to brighten Alpha    
        for ( int i = 0; i < Size; i++ )
        {
            lpBuffer = static_cast(static_cast(lpBuffer[i]) * 256.0f / 65.0f);
        }
        int width = Size / GlyphMetrics.gmBlackBoxY;
        int height = GlyphMetrics.gmBlackBoxY;

        maxHeight = ( height > maxHeight ) ? maxHeight : height;
        
        // Get the power of 2 height / width for each character
        if ( width < 8 )
           fWidth = 8;
        else if ( width < 16 )
           fWidth = 16;
        else if ( width < 32 )
           fWidth = 32;
        else if ( width < 64 )
           fWidth = 64;
        else
           fWidth = 128;
           
        if ( height < 8 )
           fHeight = 8;
        else if ( height < 16 )
           fHeight = 16;
        else if ( height < 32 )
           fHeight = 32;
        else if ( height < 64 )
           fHeight = 64;
        else
           fHeight = 128;

        textSize = ( fHeight * fWidth ) << 2; // *4
        textSize = 4096;
        fHeight = fWidth = width = height = 32;
        GLubyte* fontTexture = new GLubyte[textSize];
        // Copy the Alpha data into an all-white block
        for ( int i = 0; i < textSize; i+=4 )
        { 
            fontTexture[i] = fontTexture[i+1] = fontTexture[i+2] = 0xFF;
            fontTexture[i+3] = lpBuffer[i / 4];
        }
        // Copy over our font texture
        texture[charGet - 32] = fontTexture;
        glNewList( base + (charGet - 32), GL_COMPILE ); // Begin character
                glBegin( GL_QUADS );
                        glTexCoord2f(0.0f, 1.0f);
                        glVertex2d( 0, 0 );
                        glTexCoord2f(1.0f, 1.0f);
                        glVertex2d( fWidth, 0 );
                        glTexCoord2f(1.0f, 0.0f );
                        glVertex2d( fWidth, fHeight );
                        glTexCoord2f(0.0f, 0.0f );
                        glVertex2d( 0, fHeight );
                glEnd(); 
                glTranslated( width, 0, 0 );
        glEndList();
        delete []lpBuffer;
    }
    // Set Max height
    fH = maxHeight;
    
	SelectObject(hDC, oldfont);				// Selects The Font We Want
	DeleteObject(font);				  	     // Delete The Font

}

Share this post


Link to post
Share on other sites
Advertisement

  • 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!