00001 #include "FTTextureGlyph.h"
00002
00003
00004 FTTextureGlyph::FTTextureGlyph( FT_Glyph 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_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, 0, 1);
00012 if( err || glyph->format != ft_glyph_format_bitmap)
00013 {
00014 return;
00015 }
00016
00017 FT_BitmapGlyph bitmap = ( FT_BitmapGlyph)glyph;
00018 FT_Bitmap* source = &bitmap->bitmap;
00019
00020 destWidth = source->width;
00021 destHeight = source->rows;
00022
00023 if( destWidth && destHeight)
00024 {
00025 glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
00026 glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE);
00027 glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
00028 glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
00029
00030 glBindTexture( GL_TEXTURE_2D, glTextureID);
00031 glTexSubImage2D( GL_TEXTURE_2D, 0, xOffset, yOffset, destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, source->buffer);
00032
00033 glPopClientAttrib();
00034 }
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 uv[0].x = static_cast<float>(xOffset) / static_cast<float>(width);
00046 uv[0].y = static_cast<float>(yOffset) / static_cast<float>(height);
00047 uv[1].x = static_cast<float>( xOffset + destWidth) / static_cast<float>(width);
00048 uv[1].y = static_cast<float>( yOffset + destHeight) / static_cast<float>(height);
00049
00050 pos.x = bitmap->left;
00051 pos.y = bitmap->top;
00052
00053 FT_Done_Glyph( glyph);
00054 }
00055
00056
00057 FTTextureGlyph::~FTTextureGlyph()
00058 {}
00059
00060
00061 float FTTextureGlyph::Render( const FTPoint& pen)
00062 {
00063 glGetIntegerv( GL_TEXTURE_2D_BINDING_EXT, &activeTextureID);
00064 if( activeTextureID != glTextureID)
00065 {
00066 glBindTexture( GL_TEXTURE_2D, (GLuint)glTextureID);
00067 }
00068
00069 glBegin( GL_QUADS);
00070 glTexCoord2f( uv[0].x, uv[0].y);
00071 glVertex2f( pen.x + pos.x, pen.y + pos.y);
00072
00073 glTexCoord2f( uv[0].x, uv[1].y);
00074 glVertex2f( pen.x + pos.x, pen.y + pos.y - destHeight);
00075
00076 glTexCoord2f( uv[1].x, uv[1].y);
00077 glVertex2f( pen.x + destWidth + pos.x, pen.y + pos.y - destHeight);
00078
00079 glTexCoord2f( uv[1].x, uv[0].y);
00080 glVertex2f( pen.x + destWidth + pos.x, pen.y + pos.y);
00081 glEnd();
00082
00083 return advance;
00084 }
00085