Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with Freetype and OpenGL
    primarykey
    data
    text
    <p>Hey, i'm having a weird issue with drawing text in openGL loaded with the Freetype 2 library. Here is a screenshot of what I'm seeing.</p> <p><a href="http://img203.imageshack.us/img203/3316/freetypeweird.png" rel="nofollow noreferrer">example http://img203.imageshack.us/img203/3316/freetypeweird.png</a></p> <p>Here are my code bits for loading and rendering my text.</p> <pre><code>class Font { Font(const String&amp; filename) { if (FT_New_Face(Font::ftLibrary, "arial.ttf", 0, &amp;mFace)) { cout &lt;&lt; "UH OH!" &lt;&lt; endl; } FT_Set_Char_Size(mFace, 16 * 64, 16 * 64, 72, 72); } Glyph* GetGlyph(const unsigned char ch) { if(FT_Load_Char(mFace, ch, FT_LOAD_RENDER)) cout &lt;&lt; "OUCH" &lt;&lt; endl; FT_Glyph glyph; if(FT_Get_Glyph( mFace-&gt;glyph, &amp;glyph )) cout &lt;&lt; "OUCH" &lt;&lt; endl; FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph; Glyph* thisGlyph = new Glyph; thisGlyph-&gt;buffer = bitmap_glyph-&gt;bitmap.buffer; thisGlyph-&gt;width = bitmap_glyph-&gt;bitmap.width; thisGlyph-&gt;height = bitmap_glyph-&gt;bitmap.rows; return thisGlyph; } }; </code></pre> <p>The relevant glyph information (width, height, buffer) is stored in the following struct</p> <pre><code>struct Glyph { GLubyte* buffer; Uint width; Uint height; }; </code></pre> <p>And finally, to render it, I have this class called RenderFont.</p> <pre><code>class RenderFont { RenderFont(Font* font) { mTextureIds = new GLuint[128]; mFirstDisplayListId=glGenLists(128); glGenTextures( 128, mTextureIds ); for(unsigned char i=0;i&lt;128;i++) { MakeDisplayList(font, i); } } void MakeDisplayList(Font* font, unsigned char ch) { Glyph* glyph = font-&gt;GetGlyph(ch); glBindTexture( GL_TEXTURE_2D, mTextureIds[ch]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, glyph-&gt;width, glyph-&gt;height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, glyph-&gt;buffer); glNewList(mFirstDisplayListId+ch,GL_COMPILE); glBindTexture(GL_TEXTURE_2D, mTextureIds[ch]); glBegin(GL_QUADS); glTexCoord2d(0,1); glVertex2f(0,glyph-&gt;height); glTexCoord2d(0,0); glVertex2f(0,0); glTexCoord2d(1,0); glVertex2f(glyph-&gt;width,0); glTexCoord2d(1,1); glVertex2f(glyph-&gt;width,glyph-&gt;height); glEnd(); glTranslatef(16, 0, 0); glEndList(); } void Draw(const String&amp; text, Uint size, const TransformComponent* transform, const Color32* color) { glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTranslatef(100, 250, 0.0f); glListBase(mFirstDisplayListId); glCallLists(text.length(), GL_UNSIGNED_BYTE, text.c_str()); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glLoadIdentity(); } private: GLuint mFirstDisplayListId; GLuint* mTextureIds; }; </code></pre> <p>Can anybody see anything weird going on here that would cause the garbled text? It's strange because if I change the font size, or the DPI, then some of the letters that display correctly become garbled, and other letters that were garbled before then display correctly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload