Main Page | File List | File Members

FTTextureGlyph.cpp

Go to the documentation of this file.
00001 #include "FTTextureGlyph.h" 00002 00003 00004 FTTextureGlyph::FTTextureGlyph( FT_GlyphSlot glyph, int id, int xOffset, int yOffset, GLsizei width, GLsizei height) 00005 : FTGlyph( glyph), 00006 destWidth(0), 00007 destHeight(0), 00008 glTextureID(id), 00009 activeTextureID(0) 00010 { 00011 err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL); 00012 if( err || glyph->format != ft_glyph_format_bitmap) 00013 { 00014 return; 00015 } 00016 00017 FT_Bitmap bitmap = glyph->bitmap; 00018 00019 destWidth = bitmap.width; 00020 destHeight = bitmap.rows; 00021 00022 if( destWidth && destHeight) 00023 { 00024 glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT); 00025 glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE); 00026 glPixelStorei( GL_UNPACK_ROW_LENGTH, 0); 00027 glPixelStorei( GL_UNPACK_ALIGNMENT, 1); 00028 00029 glBindTexture( GL_TEXTURE_2D, glTextureID); 00030 glTexSubImage2D( GL_TEXTURE_2D, 0, xOffset, yOffset, destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer); 00031 00032 glPopClientAttrib(); 00033 } 00034 00035 00036 // 0 00037 // +----+ 00038 // | | 00039 // | | 00040 // | | 00041 // +----+ 00042 // 1 00043 00044 uv[0].x = static_cast<float>(xOffset) / static_cast<float>(width); 00045 uv[0].y = static_cast<float>(yOffset) / static_cast<float>(height); 00046 uv[1].x = static_cast<float>( xOffset + destWidth) / static_cast<float>(width); 00047 uv[1].y = static_cast<float>( yOffset + destHeight) / static_cast<float>(height); 00048 00049 pos.x = glyph->bitmap_left; 00050 pos.y = glyph->bitmap_top; 00051 } 00052 00053 00054 FTTextureGlyph::~FTTextureGlyph() 00055 {} 00056 00057 00058 float FTTextureGlyph::Render( const FTPoint& pen) 00059 { 00060 glGetIntegerv( GL_TEXTURE_2D_BINDING_EXT, &activeTextureID); 00061 if( activeTextureID != glTextureID) 00062 { 00063 glBindTexture( GL_TEXTURE_2D, (GLuint)glTextureID); 00064 } 00065 00066 glBegin( GL_QUADS); 00067 glTexCoord2f( uv[0].x, uv[0].y); 00068 glVertex2f( pen.x + pos.x, pen.y + pos.y); 00069 00070 glTexCoord2f( uv[0].x, uv[1].y); 00071 glVertex2f( pen.x + pos.x, pen.y + pos.y - destHeight); 00072 00073 glTexCoord2f( uv[1].x, uv[1].y); 00074 glVertex2f( pen.x + destWidth + pos.x, pen.y + pos.y - destHeight); 00075 00076 glTexCoord2f( uv[1].x, uv[0].y); 00077 glVertex2f( pen.x + destWidth + pos.x, pen.y + pos.y); 00078 glEnd(); 00079 00080 return advance; 00081 } 00082

Generated on Fri Aug 13 13:40:45 2004 for FTGL by doxygen 1.3.7