title: Render FreeType text with flipped ortho, difference between top and baseline of glyph
body: <p>I am working on a project where I implement a FreeType rendering object to draw text of which the rendering environment is specified with an orthographic projection matrix:</p>
  
  <pre><code>glm::ortho(0, Width, Height, 0);
  </code></pre>
  
  <p>This makes sure the coordinates are similar to standard GUI systems with <code>(0,0)</code> being the top-left part of the window instead of the bottom-left.</p>
  
  <p>However when rendering using FreeType, things get difficult, because FreeType operates with their origin at the bottom-left of a glyph (minus the descender). My issue is similar to <a href="https://stackoverflow.com/questions/25353472/render-freetype-gl-text-with-flipped-projection">https://stackoverflow.com/questions/25353472/render-freetype-gl-text-with-flipped-projection</a> but no answer was yet provided and his solution was not to my liking (the used library is also slightly different, I assume he is using a wrapper).</p>
  
  <p>So I render my text as follows:</p>
  
  <pre><code>renderText("Testing 123 if text performs sufficiently", 0.0f, 0.0f, 1.0f, 1.0f);
  </code></pre>
  
  <p>Of which <code>renderText</code> function contains:</p>
  
  <pre><code>renderText(const GLchar *text, GLfloat x, GLfloat y, GLfloat sx, GLfloat sy)
  {
      [...]
      GLfloat xpos = x + glyph-&gt;bitmap_left * sx; 
      GLfloat ypos = y - glyph-&gt;bitmap_top * sy; 
      GLfloat w = glyph-&gt;bitmap.width * sx;
      GLfloat h = glyph-&gt;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 }
      };
      [...]
  }
  </code></pre>
  
  <p>If I render it like this, it will render the text below the y coordinate of <code>0</code> so it won't be visible unless I add an offset to the y coordinate. So looking at FreeType's glyph metrics:</p>
  
  <p><img src="https://i.stack.imgur.com/addNM.png" alt="glyph metrics from FreeType"></p>
  
  <p>I want to offset the y position by a positive amount equal to the difference between the origin and the top of the glyph image so it always neatly renders the text at my given position. Looking at the image I believe this to be the yMax value so I added the following statement to the code before updating the VBO:</p>
  
  <pre><code>ypos += (glyph-&gt;face-&gt;bbox.yMax &gt;&gt; 6) * sy; 
  </code></pre>
  
  <p>Which seemed to fix the issue when I loaded the FreeType glyphs with font size 24, but as soon as I tried to use different font sizes it failed to work as this image shows:</p>
  
  <p><img src="https://i.stack.imgur.com/jOFW2.png" alt="font size differences"></p>
  
  <p>As you can see, it clearly doesn't work as I thought it would. I've been thouroughly searching through FreeType's documentation if I was missing something, but I could not find it. Am I using the wrong metrics (using Ascender didn't work as well)?</p>