Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

FTPixmapGlyph.cpp

Go to the documentation of this file.
00001 #include    "FTPixmapGlyph.h"
00002 
00003 FTPixmapGlyph::FTPixmapGlyph( FT_GlyphSlot glyph)
00004 :   FTGlyph( glyph),
00005     destWidth(0),
00006     destHeight(0),
00007     data(0)
00008 {
00009     err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL);
00010     if( err || ft_glyph_format_bitmap != glyph->format)
00011     {
00012         return;
00013     }
00014 
00015     FT_Bitmap bitmap = glyph->bitmap;
00016 
00017     //check the pixel mode
00018     //ft_pixel_mode_grays
00019         
00020     int srcWidth = bitmap.width;
00021     int srcHeight = bitmap.rows;
00022     
00023    // FIXME What about dest alignment?
00024     destWidth = srcWidth;
00025     destHeight = srcHeight;
00026     
00027     if( destWidth && destHeight)
00028     {
00029         data = new unsigned char[destWidth * destHeight * 4];
00030     
00031         // Get the current glColor.
00032         float ftglColour[4];
00033         glGetFloatv( GL_CURRENT_COLOR, ftglColour);
00034 
00035         unsigned char redComponent =   static_cast<unsigned char>( ftglColour[0] * 255.0f);
00036         unsigned char greenComponent = static_cast<unsigned char>( ftglColour[1] * 255.0f);
00037         unsigned char blueComponent =  static_cast<unsigned char>( ftglColour[2] * 255.0f);
00038 
00039         unsigned char* src = bitmap.buffer;
00040 
00041         unsigned char* dest = data + ((destHeight - 1) * destWidth) * 4;
00042         size_t destStep = destWidth * 4 * 2;
00043 
00044         if( ftglColour[3] == 1.0f)
00045         {
00046             for( int y = 0; y < srcHeight; ++y)
00047             {
00048                 for( int x = 0; x < srcWidth; ++x)
00049                 {
00050                     *dest++ = redComponent;
00051                     *dest++ = greenComponent;
00052                     *dest++ = blueComponent;
00053                     *dest++ = *src++;
00054                 }
00055                 dest -= destStep;
00056             }
00057         }
00058         else
00059         {
00060             for( int y = 0; y < srcHeight; ++y)
00061             {
00062                 for( int x = 0; x < srcWidth; ++x)
00063                 {
00064                     *dest++ = redComponent;
00065                     *dest++ = greenComponent;
00066                     *dest++ = blueComponent;
00067                     *dest++ = static_cast<unsigned char>(ftglColour[3] * *src++);
00068                 }
00069                 dest -= destStep;
00070             }
00071         }
00072         destHeight = srcHeight;
00073     }
00074 
00075     pos.X( glyph->bitmap_left);
00076     pos.Y( srcHeight - glyph->bitmap_top);
00077 }
00078 
00079 
00080 FTPixmapGlyph::~FTPixmapGlyph()
00081 {
00082     delete [] data;
00083 }
00084 
00085 
00086 const FTPoint& FTPixmapGlyph::Render( const FTPoint& pen)
00087 {
00088     glBitmap( 0, 0, 0.0f, 0.0f, pen.X() + pos.X(), pen.Y() - pos.Y(), (const GLubyte*)0);
00089     
00090     if( data)
00091     {
00092         glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
00093         glDrawPixels( destWidth, destHeight, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)data);
00094     }
00095         
00096     glBitmap( 0, 0, 0.0f, 0.0f, -pos.X(), pos.Y(), (const GLubyte*)0);
00097 
00098     return advance;
00099 }

Generated on Sun Dec 5 22:24:06 2004 for FTGL by doxygen 1.3.6