freetype
[Top][All Lists]
Advanced

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

[ft] Questions using FT_RENDER_MODE_MONO


From: Graham Hemingway
Subject: [ft] Questions using FT_RENDER_MODE_MONO
Date: Tue, 15 Apr 2008 15:08:05 -0500

Hello,
   I am relatively new to FreeType, and first I want to say thank you to the developers.  Well, my question is about the format of the bitmap buffer returned by using FT_RENDER_MODE_MONO.  I want to get bitmaps that are not anti-aliased and my end target is OpenGL textures that use 32-bits per pixel (8 per channel RGBA).  So I need to do the conversion from the 1-bit per pixel output.  What I would like is for all four components of the texture (unsigned bytes) to be either 0 or 255 based on the glyph bitmap.  Below is some code that I tried but it only rendered garbage.  Any suggestions on how to go about this?

//Allocate memory for the texture data (four component)
GLubyte *data = "" GLubyte[4 * slot->bitmap.width * slot->bitmap.rows];

//Set color to white and alpha to bitmap value
unsigned int bmIndex = 0, dataIndex = 0, byteIndex, bitOffset;
unsigned char byte;
for(int j=0; j < slot->bitmap.rows; j++) {
for(int i=0; i < slot->bitmap.width; i++){

//Get the byte index and bit offset
                        byteIndex = bmIndex / 8;
                        bitOffset = bmIndex % 8;

                        //Get the byte
byte = slot->bitmap.buffer[byteIndex];

                        //Rotate, AND, and multiply to get 0 or 255 value
                        byte = ((byte >> bitOffset) & 1) * 255;

                        //Set all four components of the GL texture
data[dataIndex++] = byte;
data[dataIndex++] = byte;
data[dataIndex++] = byte;
data[dataIndex++] = byte;
                        //Increment bmIndex
                        bmIndex++;
}
}

Thanks,
    Graham

reply via email to

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