Im using freetype for my game and getting the characters in FT_PIXEL_MODE_LCD type I then convert this to rgba to be easily put on top of other things and it works but im doing something wrong obviously to do with the alpha.
Heres my c++ code its already got the FT_Bitmap named bitmap
std::string data;
data.reserve(4 * width * height);
for( int y=0; y<height; y++ ){
for( int x=0; x<width; x++){
int pos = (y*pitch) + (x*3);
if( (unsigned char)bitmap.buffer[pos] == 0 && (unsigned char)bitmap.buffer[pos+1] == 0 && (unsigned char)bitmap.buffer[pos+2] == 0 ){
data.append(4, (unsigned char)0);
} else {
data.append(1, 255 - (unsigned char)bitmap.buffer[pos] );
data.append(1, 255 - (unsigned char)bitmap.buffer[pos+1] );
data.append(1, 255 - (unsigned char)bitmap.buffer[pos+2] );
//alpha
data.append(1, (unsigned char)255);
}
}
}
I do the 255 - the rgb chars to convert the data from white text on black background to black text on white background
Anyways the result is attached can someone help? Thanks