Game Development Reference
In-Depth Information
The code in RenderLineOnBitmap() is fairly straightforward. The only subtle point
is the bitwise shift operation, which converts the internal FreeType 26.6 bit ixed-
point format to a standard integer. First, we shift StartX left to get the FreeType's
coordinate, and for each pixel, we shift x right to get the screen position.
The 26.6 fixed-point format is used internally in FreeType to
define fractional pixel coordinates.
39. The DrawGlyph() routine copies raw pixels from the glyph, or multiplies the source
by the glyph's pixel, depending on the rendering mode:
void DrawGlyph (const clPtr<Bitmap>& Out, FT_Bitmap* Bmp,
int X0, int Y0, unsigned int Color )
{
unsigned char* Data = Out->FBitmapData;
int W = Out->FWidth;
int Width = W - X0;
if ( Width > Bmp->width ) { Width = Bmp->width; }
for ( int Y = Y0 ; Y < Y0 + Bmp->rows ; ++Y )
{
unsigned char* Src = Bmp->buffer + (Y-Y0)*Bmp->pitch;
if ( FMaskMode )
{
for ( int X = X0 + 0 ; X < X0 + Width ; X++ )
{
int Int = *Src++;
unsigned char Col = (Int & 0xFF);
for(int j = 0 ; j < 4 ; j++)
Data[(Y * W + X) * 4 + j]= Col;
}
}
else
{
for ( int X = X0 + 0 ; X < X0 + Width ; X++ )
{
unsigned int Col = MultColor(Color, *Src++);
if ( Int > 0 )
{ ((unsigned int*)Data)[Y * W + X] = Col; }
}
}
}
}
 
Search WWH ::




Custom Search