Freetype рисует только красный цвет
Имею вот такой FontRenderer:
FontRenderer::FontRenderer(ResourceLocation fontLocation, int size) {
FT_Init_FreeType(&ft);
FT_New_Face(ft, fontLocation.GetFilePath().c_str(), 0, &face);
FT_Set_Pixel_Sizes(face, 0, size*2);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
FT_GlyphSlot slot = face->glyph;
for (GLubyte character = 0; character < 128; character++) {
if (FT_Load_Char(face, character, FT_LOAD_RENDER))
continue;
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, slot->bitmap.width, slot->bitmap.rows, 0, GL_RED, GL_UNSIGNED_BYTE, slot->bitmap.buffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLfloat x2 = slot->bitmap_left;
GLfloat y2 = slot->bitmap_top;
GLfloat w = slot->bitmap.width;
GLfloat h = slot->bitmap.rows;
Glyph glyph = {
textureID,
x2, y2,
w, h,
slot->advance.x, slot->advance.y
};
glyphs[character] = glyph;
}
FT_Done_Face(face);
FT_Done_FreeType(ft);
}
void FontRenderer::DrawString(const string& text, float x, float y, int color) {
glLoadIdentity();
glTranslatef(x, y+20, 0);
glScalef(0.5f, 0.5f, 0.5f);
glColor4f((color >> 16 & 255) / 255.0f, (color >> 8 & 255) / 255.0f, (color >> 24 & 255) / 255.0f, (color & 255) / 255.0f);
std::string::const_iterator character;
for (character = text.begin(); character != text.end(); character++) {
Glyph glyph = glyphs[*character];
glBindTexture(GL_TEXTURE_2D, glyph.textureID);
GLfloat x2 = x + glyph.x;
GLfloat y2 = -y - glyph.y;
GLfloat w = glyph.width;
GLfloat h = glyph.height;
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(x2, y2);
glTexCoord2f(0, 1); glVertex2f(x2, y2 + h);
glTexCoord2f(1, 1); glVertex2f(x2 + w, y2 + h);
glTexCoord2f(1, 0); glVertex2f(x2 + w, y2);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
x += glyph.advanceX >> 6;
y += glyph.advanceY >> 6;
}
}
Отрисовывается отлично, но текст красный.
Источник: Stack Overflow на русском