Jump to content
  • Advertisement
Sign in to follow this  
Zotoaster

OpenGL Rendering text

This topic is 2092 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

I've been working on a GUI system because why not. I couldn't get Qt to compile for me despite all my efforts, and I happened to have a decent GUI system that worked for Windows, and it had the graphics abstracted out, so I thought I'd replace it with OpenGL so I can work it from my Mac. I've never used OpenGL before but I've got the form rendering working fine, but I was a little surprised at how complicated it can be to get any text up. I followed the NeHe tutorial on text rendering using FreeType (http://nehe.gamedev.net/tutorial/freetype_fonts_in_opengl/24001/ ). The first problem was that for some reason text positioned at 0,0 was rendering at the bottom left. I'm sure I've made some mistake with some matrix transformation somewhere but my understanding of them is still lacking so I fixed it by subtracting the Y coord from the screen height. More importantly, the text is really blurry. Attached is a screenshot for reference.

 

I am willing to show my code for the text and general rendering if anyone wants to look at it. Ideally I'd like a plug-and-play library with a text(x, y, string) method so I can get on with my engine and finish with this story.

 

Thanks

 

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

I'm using one of the techniques described in 3TATUK2's link - I basically make a quad for each letter. I support multiple fonts, where fonts are stored as distance field map, and the images are described in AngelCode's format http://www.angelcode.com/products/bmfont/

 

For more distance field and fonts usage - see http://code.google.com/p/libgdx/wiki/DistanceFieldFonts

Share this post


Link to post
Share on other sites


The first problem was that for some reason text positioned at 0,0 was rendering at the bottom left

 

In the OpenGL convention, 0,0 is the bottom left. The Y coordinate subtraction from the height is the typical practice to place the coordinate into window space.

Share this post


Link to post
Share on other sites

I'm looking at 3TATUK2's link. Is it possible to do it without using shaders? My current system doesn't need them and I'd rather have fewer dependencies.

Share this post


Link to post
Share on other sites

FreeType is explained in 3 tutorials. The first one shows how to render bitmaps, how to determine the size of the bitmaps, and how to determine the advance when rendering the text (see especially section "7. Simple text rendering" in that tutorial). You can find the corresponding part in line 40 of one of the NeHe listing, namely

   glTranslatef(face->glyph->advance.x >> 6 ,0,0);

This line extracts the horizontal advance, which is a 26.6 fixed point number (again, see the FreeType documentation), throws the decimal places away, and builds a translation from that. Obviously it assume a horizontal scripting system.

 

However, for your use case you want to sum up the advances for all characters of your string (for the last perhaps just the width).

Edited by haegarr

Share this post


Link to post
Share on other sites

The problem is that after the 'init' method, the 'face' is discarded so I don't have access to it later on. It seems the data is stored somewhere in these lists, but I'm new to OpenGL and I don't have a clue what they're about.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!