I am working on a project in which I implement a FreeType rendering object to draw text for which the visualization environment is specified with an orthographic projection matrix:
glm::ortho(0, Width, Height, 0);
This ensures that the coordinates are similar to standard GUI systems, with (0,0) being the upper left part of the window instead of the lower left.
However, when rendering using FreeType, everything becomes complicated, because FreeType works with their beginning in the lower left corner of the glyph (minus descender). My problem is similar to https://stackoverflow.com/questions/25353472/render-freetype-gl-text-with-flipped-projection , but the answer has not yet been provided and its solution was not to their liking (the library used is also slightly different, I suppose he uses a wrapper).
So, I am making my text as follows:
renderText("Testing 123 if text performs sufficiently", 0.0f, 0.0f, 1.0f, 1.0f);
Of which the renderText function contains:
renderText(const GLchar *text, GLfloat x, GLfloat y, GLfloat sx, GLfloat sy) { [...] GLfloat xpos = x + glyph->bitmap_left * sx; GLfloat ypos = y - glyph->bitmap_top * sy; GLfloat w = glyph->bitmap.width * sx; GLfloat h = glyph->bitmap.rows * sy; // Update VBO GLfloat vertices[4][4] = { { xpos, ypos, 0, 0 }, { xpos + w, ypos, 1, 0 }, { xpos, ypos + h, 0, 1 }, { xpos + w, ypos + h, 1, 1 } }; [...] }
If I do it like this, it will display the text at y coordinate 0 so that it is not visible unless I add an offset to the y coordinate. So, let's look at the FreeType glyph metrics:

I want to shift the y position by a positive amount equal to the difference between the beginning and the top of the glyph image so that it always accurately displays the text at my given position. Looking at the image, I find this to be yMax, so I added the following code to the code before updating VBO:
ypos += (glyph->face->bbox.yMax >> 6) * sy;
It seemed like a problem when I downloaded FreeType glyphs with a font size of 24, but as soon as I tried to use different font sizes, it couldn't work, as shown in this image:

As you can see, this clearly does not work as I thought. I searched through FreeType for documentation if I had something missing, but I could not find it. Am I using the wrong metrics (using Ascender also doesn't work)?