🔒 Locked
FreeType2
Advertisement
Original Post
Anyone know of good resources for rendering FreeType2 glyph''s to OpenGL. I know that there is libraries that do this for me, but I''m looking to do it on my own. I''ve looked at the source code for some of these libraries but I''m having some trouble following them. So is there any other good tuts out there?
Well, I''ve done everything the documentation has said to extract the load and extract the glyph''s. I''ve obtained the bitmaps, and I''m using glBitmap to render. What comes out is garbage. I think I may be accessing the bitmap information, or it''s simply incompatible with glBitmap''s format. The documentation doesn''t talk a lot about it''s bitmaps, so I''m a little lost about how to proceed.
OK, I see. You are right, actually FT2''s bitmap format is incompatible with OpenGL''s. What OGL specifies as a ''bitmap'' is just what the name suggests: a map, where each bit represents a pixel. It can either be black or white, ie. you''ll get a monochrome image.
FreeType''s bitmaps consist of greyscale values, since the glyphs can be anti-aliased. They represent grey levels between black and white, and thus can''t be rendered using OGL''s glBitmap(). To render FT glyphs in OpenGL, you can either use direct framebuffer writes (glDrawPixels), or a texture. The later one is much faster, and the recommended approach. Both will give you the same visual quality.
I''ll assume, you already requested a pointer to a valid FT_Bitmap structure in FT. Now, FTbitmap->buffer contains an array of unsigned byte values, giving the opacity of each glyph pixel. FTbitmap->pitch is the stride (in bytes), FTbitmap->rows and FTbitmap->width the glyph dimensions. The format is compatible to one of the uni-component formats in OpenGL: GL_LUMINANCE, GL_ALPHA, GL_INTENSITY8, etc.
For example:
glRasterPos2i(xpos, ypos);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, FTbitmap->pitch);
glDrawPixels(FTbitmap->width, FTbitmap->rows, GL_LUMINANCE, GL_UNSIGNED_BYTE, FTbitmap->buffer);
will draw a single glyph on the screen (well, it should, it is from the top of my head
)
FreeType''s bitmaps consist of greyscale values, since the glyphs can be anti-aliased. They represent grey levels between black and white, and thus can''t be rendered using OGL''s glBitmap(). To render FT glyphs in OpenGL, you can either use direct framebuffer writes (glDrawPixels), or a texture. The later one is much faster, and the recommended approach. Both will give you the same visual quality.
I''ll assume, you already requested a pointer to a valid FT_Bitmap structure in FT. Now, FTbitmap->buffer contains an array of unsigned byte values, giving the opacity of each glyph pixel. FTbitmap->pitch is the stride (in bytes), FTbitmap->rows and FTbitmap->width the glyph dimensions. The format is compatible to one of the uni-component formats in OpenGL: GL_LUMINANCE, GL_ALPHA, GL_INTENSITY8, etc.
For example:
glRasterPos2i(xpos, ypos);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, FTbitmap->pitch);
glDrawPixels(FTbitmap->width, FTbitmap->rows, GL_LUMINANCE, GL_UNSIGNED_BYTE, FTbitmap->buffer);
will draw a single glyph on the screen (well, it should, it is from the top of my head
quote:
Original post by spiffgq
Some (most, actually) of FreeType''s bitmaps are not power-of-two dimensions.
Of course not, FT2 gives you individual glyphs. And you certainly wouldn''t want to create a dedicated texture for each glyph... In practice, you would collect all glyphs in a charset, and arrange them into a single large texture. The fact that the individual glyphs are no power of two is not relevant in this case.
Not sure, I never used fully monochrome fonts. But why would you want to ? glBitmap() is usually not well optimized in the driver, as it is very rarely used. Most of the time, the driver will emulate it with textures anyway. You are going to get much more performance by directly using 8bit textures, and you get the bonus of an antialiased font.
Well, FT can do things that are very hard to achieve with bitmapped fonts. Kerning, for example, or simply the possibility to switch font and size at runtime. You could also use a different approach: instead of rendering each glyph in the alphabet into a texture, and compositing with polygons, you could simply render an entire text line into a texture (using FT), and display that text row using a quad. It will take more memory, and it''ll be slower, but give you excellent quality and flexibility.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement