|
From: | Dave Calkins |
Subject: | Re: [ft] anti-aliasing question |
Date: | Sun, 07 Feb 2010 08:51:45 -0500 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.7) Gecko/20100111 Thunderbird/3.0.1 |
If that fails, could you perhaps attach some sample renderings in png format? In order to try and factor out any effect of the GL side of things, I wrote a small stand-alone windows app which just loads a font, renders a single glyph, and then writes out the rendered bitmap in the glyph slot to a .png and .txt file. So there's nothing here but calling FreeType and then storing the resultant gray scale bitmap. At first I didn't see a huge difference, but this was before changing the flags Werner suggested. I changed those (to ensure the byte code interpreter is enabled) and rebuilt this sample and it does look a little different. The text is brighter, so maybe there's a darkening happening when rendering to GL. The FreeTypeGL rendering code is shown below. Its storing the gray scale image in a texture which gets treated as the alpha channel to render a solid rectangle. Since I'm doing 2D rendering with GL, there should be a 1-to-1 between the rendered pixels and the texture pixels so I don't believe any texture filtering should be ocurring. >>> setup the texture for the glyph err = FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL); FT_Bitmap bitmap = glyph->bitmap; destWidth = bitmap.width; destHeight = bitmap.rows; if(destWidth && destHeight) { glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, glTextureID); glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer); glPopClientAttrib(); } // 0 // +----+ // | | // | | // | | // +----+ // 1 uv[0].X(static_cast<float>(xOffset) / static_cast<float>(width)); uv[0].Y(static_cast<float>(yOffset) / static_cast<float>(height)); uv[1].X(static_cast<float>(xOffset + destWidth) / static_cast<float>(width)); uv[1].Y(static_cast<float>(yOffset + destHeight) / static_cast<float>(height)); corner = FTPoint(glyph->bitmap_left, glyph->bitmap_top); >>> render the glyph texture float dx, dy; if(activeTextureID != glTextureID) { glBindTexture(GL_TEXTURE_2D, (GLuint)glTextureID); activeTextureID = glTextureID; } dx = floor(pen.Xf() + corner.Xf()); dy = floor(pen.Yf() + corner.Yf()); glBegin(GL_QUADS); glTexCoord2f(uv[0].Xf(), uv[0].Yf()); glVertex2f(dx, dy); glTexCoord2f(uv[0].Xf(), uv[1].Yf()); glVertex2f(dx, dy - destHeight); glTexCoord2f(uv[1].Xf(), uv[1].Yf()); glVertex2f(dx + destWidth, dy - destHeight); glTexCoord2f(uv[1].Xf(), uv[0].Yf()); glVertex2f(dx + destWidth, dy); glEnd(); return advance; |
glyph.png
Description: PNG image
glyph.txt
Description: Text document
main.cpp
Description: Text document
main.h
Description: Text document
SaveToPNG.cpp
Description: Text document
SaveToPNG.h
Description: Text document
SaveToTXT.cpp
Description: Text document
SaveToTXT.h
Description: Text document
[Prev in Thread] | Current Thread | [Next in Thread] |