Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Text rendering in OpenGL

  1. #1

    Text rendering in OpenGL

    Hello everyone,

    Recently I am looking for a way to render nice quality text in OpenGL. I have came accross few very impressive text rendering libraries, but they were all written in C/C++ and I cant seem to find any in Delphi (or even Delphi binding).

    Are there such ready libraries or I have to write my own, to create outlines from font files, then to tesselate, etc?

    Thanks

  2. #2
    I don't think so, was looking for same thing a while ago and ended up using simple bitmap fonts

  3. #3
    Bitmap fonts have the benefit that they are much faster to render and take less video memory. It's only 2 textured triangles per character, whereas outlined character can be up to 100 tris. I think it was first Nehe tutorials where i learned how to use WinAPI and OpenGL to create the font 3D models, before i looked into bitmap fonts. Those tutorials save characters into displaylist. I think not even glut was needed, just some simple existing API function.

  4. #4
    Thank you for the replies!

    I might consider using bitmp fonts for beginning. I don't have yet experience with that, but as far as I image, I should render a character map (atlas) at runtime, using the OS's built in text rendering functions. The character map would be a single channel texture (alpha map). Then each quad's tex-coordinates should map an exact character from the texture. Then I can combine the character alpha map with a custom texture or color to fill the character in the fragment shader. Would that work? How do you do it in your implementations?

    But wouldn't be a problem for the mipmapping if I use a single texture for font atlas? Is it a better solution to store each character in different texture?

    About the 3d text geometry, since I target for multiplatform code, I am unable to use the windows api for text geometry. My only idea for now is to find and download a 3d font model set (I guess there should be any) or try to create in Blender, so I can load it from it's file and have each character as a tri model group and then use them to render the text.
    Last edited by Anton; 07-11-2014 at 09:52 PM.

  5. #5
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    If you're looking for 2d fonts, I would personally have to point out that ZenGL (by Andru) renders some quite pretty fonts. Basically, you feed it a font from your system (via ttf or whatever you prefer) and give it the characters you want. From this, it generate .zfi file which stores the information for how to render the font, and some .tga images which contain the visual information. Then all you need do is simply combine the two which in hindsight is reasonably easy to do. If you want a reference implementation, one can see some code for it here: https://sourceforge.net/p/prometheus...ee/PM_Font.pas
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  6. #6
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    I would suggest FreeType it is a portable font engine that would allow to use most fonts. I use it to create bitmap fonts but with some work I think you could pull the information you need to do full 3D. http://sourceforge.net/projects/freetype/

  7. #7
    Quote Originally Posted by Anton View Post
    I don't have yet experience with that, but as far as I image, I should render a character map (atlas) at runtime, using the OS's built in text rendering functions. The character map would be a single channel texture (alpha map). Then each quad's tex-coordinates should map an exact character from the texture. Then I can combine the character alpha map with a custom texture or color to fill the character in the fragment shader. Would that work? How do you do it in your implementations?
    No. You can pre-generate a texture, and save the character pixel widths in file. Texture is usually a 24-bit RGBA image. You can even pre-generate one and then add effects in photoshop/gimp.

    Quote Originally Posted by Anton View Post
    But wouldn't be a problem for the mipmapping if I use a single texture for font atlas? Is it a better solution to store each character in different texture?
    Mipmapping is done per texture basis, fonts shouldn't need any. Mipmapping technique is used to smoothen repeating textures like terrain that fade into distance. Font neither repeats nor has varying depth. And true, you don't want to include fonts in global single texture. You can't mipmap a texture atlas either, it will simply mess up clamping.

  8. #8
    Thanks for the replies all. ZenGL seems to have good text rendering features.

    I would suggest FreeType it is a portable font engine that would allow to use most fonts. I use it to create bitmap fonts but with some work I think you could pull the information you need to do full 3D. http://sourceforge.net/projects/freetype/
    This sounds good. Are there pascal headers for FreeType2? I see it is written in C, so the only way to use it in Pascal/Delphi program would be with dynamic linking.

    Mipmapping is done per texture basis, fonts shouldn't need any. Mipmapping technique is used to smoothen repeating textures like terrain that fade into distance. Font neither repeats nor has varying depth. And true, you don't want to include fonts in global single texture. You can't mipmap a texture atlas either, it will simply mess up clamping.
    Yes, this makes sense. So there would be no problem to use normal linear interpolation for rendering the font texture (I think i'll want to resize the text characters sometimes).. as long there the character quad is not fading in distance?

  9. #9
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    you will find the header files for freetype2 in the free pascal source (fpcsrc/2.6.4/packages/fcl-image/src/freetypeh.pp) I didn't use the freetype.pp which creates a font manager or something, I thought it to over kill for my needs. instead I followed the tutorials from the freetype sight to figure it out. there very good. I did have to make a small correction in the header file but can't remember what that was. if you run into problems I can send my modified source but better to try theres first because theres could be more up to date then mine

  10. #10
    I've used Nitrogen's Font Studio and the units that come with it to render fonts. Unfortunately http://www.nitrogen.za.org/ seems to be down. Does anyone know where Nitrogen disappeared to?

    EDIT: Found this one https://bitbucket.org/mikepote/font-studio Seems to have been updated in 2013.
    Last edited by vgo; 11-11-2014 at 09:59 AM.
    If you develop an idiot proof system, the nature develops better idiots.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •