freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ft] Problem Rendering FreeType Fonts with OpenGL


From: Thomas K.
Subject: [ft] Problem Rendering FreeType Fonts with OpenGL
Date: Mon, 16 Jul 2007 22:19:59 +0200

Hi all,
I'd like to print out text using FreeType 2. Unfortunately I could not quite 
get it to work the way its supposed to.
Here's the piece of code which does the rendering of text:
[code]
void CFont<RTTFont>::Render ( const char* string )  { 
        unsigned int error;
        float rPos[4];
        //FT_Set_Pixel_Sizes(_pFontRes->_FTFace, GetPixelWidth(), 
GetPixelHeight());
        FT_Set_Char_Size(_pFontRes->_FTFace, 24 * 64, 24 * 64, 72, 72);

        FT_Bitmap* bitmap;
        GLuint texId[255];
        glGenTextures(255,texId);
        unsigned int i = 0;

        bool texCreated[255];
        for(i=0;i<255;++i)
                texCreated[i] = false;

        glPushMatrix();
        for(i=0;i<strlen(string);++i) {
                error = FT_Load_Char( _pFontRes->_FTFace, string[i], 
FT_LOAD_RENDER);
                FTException(error);
                _ASSERT( 
_pFontRes->_FTFace->glyph->format==FT_GLYPH_FORMAT_BITMAP );

                glGetFloatv(GL_CURRENT_RASTER_POSITION,rPos);

                glBindTexture(GL_TEXTURE_2D,texId[ string[i] ]);
                if(!texCreated[ string[i] ]) {

                        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 
_pFontRes->_FTFace->glyph->bitmap.width, 
_pFontRes->_FTFace->glyph->bitmap.rows, 0,
                                GL_LUMINANCE, GL_UNSIGNED_BYTE, 
_pFontRes->_FTFace->glyph->bitmap.buffer );

                        texCreated[ string[i] ] = true;
                };

                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 
// Linear Filtering
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 
// Linear Filtering

                GLenum err = glGetError();

                glBindTexture(GL_TEXTURE_2D,texId[ string[i] ]);
                glMatrixMode(GL_MODELVIEW);
                glDisable(GL_LIGHTING);
                glEnable(GL_TEXTURE_2D);
                glDisable(GL_DEPTH_TEST);
                glEnable(GL_BLEND);
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

                glBegin(GL_QUADS);
                glTexCoord2d(0,0);
                glVertex2d(0,_pFontRes->_FTFace->glyph->bitmap.rows);

                glTexCoord2d(0,1);
                glVertex2d(0,0);

                glTexCoord2d(1,1);
                glVertex2d(_pFontRes->_FTFace->glyph->bitmap.width,0);

                glTexCoord2d(1,0);
                
glVertex2d(_pFontRes->_FTFace->glyph->bitmap.width,_pFontRes->_FTFace->glyph->bitmap.rows);
                glEnd();
                glTranslatef(_pFontRes->_FTFace->glyph->advance.x/64, 0.0, 0.0);
        };
        glPopMatrix();
        glDeleteTextures(255, texId);


};


[/code]
As I am still merely trying out how to actually draw things, I did not make use 
of any opengl lists yet. Now the problem is visible in the following image:
http://mhooo.mirrormoon.org/img/mygui_font.png

Basically I have two buttons and an edit field there, the first button should 
have the text "Skip-FPS: xxx", the second button "FPS: xxx" and the edit field 
"test" followed by a cursor. Unfortunately some characters are screwed up (i.e. 
the "s" character) and I have no idea why that is.
"_pFontRes-&gt;_FTFace" is basically the FreeType2 face struct which is 
returned after loading a font.
Furthermore I have no idea why glTexCoord2d does not work if I use the bitmaps 
height and width as coordinates, but only if I use 1 (one) as a param.

Thanks,
Jimmy
-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser




reply via email to

[Prev in Thread] Current Thread [Next in Thread]