Текст отображает вверх ногами freetype

Имею вот такой FontRenderer:

FontRenderer::FontRenderer(const string& fontPath) {
    FT_Init_FreeType(&ft);
    FT_New_Face(ft, "arial.ttf", 0, &face);
    FT_Set_Pixel_Sizes(face, 0, 48);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}

void FontRenderer::DrawString(const string& text, float x, float y) {
    glLoadIdentity();
    glTranslatef(x, y, 0);
    glScalef(0.5f, 0.5f, 0.5f);

    FT_GlyphSlot slot = face->glyph;

    for (char character : text) {
        if (FT_Load_Char(face, character, FT_LOAD_RENDER))
            continue;
        
        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 = x + slot->bitmap_left;
        GLfloat y2 = -y - slot->bitmap_top;
        GLfloat w = slot->bitmap.width;
        GLfloat h = slot->bitmap.rows;

        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();

        x += slot->advance.x >> 6;
        y += slot->advance.y >> 6;
    }
}

Шрифт находит, с текстурой всё в порядке, но она отображает вверх ногами:


Ответы (1 шт):

Автор решения: ladno

Пофиксил так:

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);
→ Ссылка