Text in OpenGL

Started by
5 comments, last by e_pech 15 years, 9 months ago
Hey! Does anyone know how I can output text in OpenGL but in a way I'll be able to manipulate the vertices (know the exact size of the whole text drawn, slant it at any inclination, and some other things)... I'm using C++ w/MFC and the WglUseFontOutlines function, however I can't manipulate the vertices and for me it's kind of limited so, I was wondering if anyone has an idea of any other way I can output text. By the way, I'd like to use LINES and not Rasters or Bitmaps. Thank you sooo much and if I'm being really picky, it's not me, it's my boss hehehe :D
Advertisement
Matrices don't do the job? You can use scaling matrices, affine matrices etc.
Have a look here.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Lord Evil, you're the man... I'm learning all this OpenGL stuff... I'm a newbie... so I was trying to solve the problem using a wrong technique! Matrices DO the job (for Shearing)! I had to read a little bit about it (almost an hour) but I solved the problem! Thanks man!!

Do you by a chance know how I can find out the exact size of a text drawn on the screen??

Thanks a lot!
I think you should use the last parameter of wglUseFontOutlines: LPGLYPHMETRICSFLOAT (a pointer to a GLYPHMETRICSFLOAT array).

This should contain the default sizes for each character (glyph). With that and your projection matrix, viewport and scaling settings you should get the rendered size.

Here's the corresponding MSDN article.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Yeah, I'm trying to use those attributes of that structure however, I don't know what I'm doing wrong because no matter what Letter I output it always gives me the same size... BlackBoxX, BlackBoxY, gmfCellIncX, etc... the parameter doesn't change...

I want to center text on the screen so... I Substract the size of one Letter (let's suppose I'm just drawing a letter, nothing else on the screen, my Ortho2D is set to 0 - 10) so... I just do (10 - textSize)/2. Right?

But, the thing is that if I want to output 15 letters or so... every single letter has a different size and apparently(width of 'i' is less than 'M'), PLEASE correct me if I'm wrong those attributes won't change, I even tried

agmf[0]->Attribute

and I tried it changing the array index and still the same thing....

I hope I was clear!

I appreciate your help!
Might depend on your font, since there are monospaced fonts out there,i.e. size of "i" = size of "m".

Also, for centering the text you need to be aware where the origin of the text is. I personally use texture mapped fonts with freetype which uses the leftmost bottomline coordinate as the origin (compare "f" and "q" for the bottom line -> q expands below the line).

So vertical centering should be: y = (screenHeight - textHeight)/2 + distanceTopToOrigin.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Thnx man! I'll take a look at it! I appreciate your follow up and help... For now, I'll go and hit the sack for a little bit.. Here in Mexico it's 4.30am....

This topic is closed to new replies.

Advertisement