Archived

This topic is now archived and is closed to further replies.

FreeType2

This topic is 5310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 )

Share this post


Link to post
Share on other sites
Some (most, actually) of FreeType''s bitmaps are not power-of-two dimensions. You''ll have to adjust the dimensions before you can use OpenGL.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Would it also be possible to set the render mode to monochrome through FreeType so that OpenGL could use it (using ft_render_mode_monochrome)? Or is there still other issues with formating that need contending with?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Just curious really. I''m pretty intent on the AA fonts too. I''m a little off about creating textures and rendering them like polygons though. If I go that way I might as well use bitmapped fonts and do away with FreeType.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites