Jump to content

  • Log In with Google      Sign In   
  • Create Account

Rendering text


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Zotoaster   Members   -  Reputation: 148

Like
0Likes
Like

Posted 22 October 2013 - 12:38 PM

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

 

 

 

 

Attached Thumbnails

  • blurry gui.png


Sponsor:

#2 3TATUK2   Members   -  Reputation: 730

Like
0Likes
Like

Posted 22 October 2013 - 01:17 PM

http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_01



#3 Vilem Otte   Crossbones+   -  Reputation: 1424

Like
0Likes
Like

Posted 22 October 2013 - 01:40 PM

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


My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com


#4 shacktar   Members   -  Reputation: 750

Like
0Likes
Like

Posted 22 October 2013 - 02:37 PM


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.



#5 Zotoaster   Members   -  Reputation: 148

Like
0Likes
Like

Posted 22 October 2013 - 02:58 PM

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.



#6 Zimans   Members   -  Reputation: 230

Like
0Likes
Like

Posted 23 October 2013 - 05:29 AM

I've based my font rendering on this: http://code.google.com/p/freetype-gl/

 

--Z



#7 SC0x1   Members   -  Reputation: 249

Like
0Likes
Like

Posted 23 October 2013 - 07:09 AM

Simply + Unicode support:  https://github.com/SC0x1/XFontSys smile.png


Edited by SC0x1, 23 October 2013 - 07:10 AM.


#8 Zotoaster   Members   -  Reputation: 148

Like
0Likes
Like

Posted 29 October 2013 - 03:11 PM

I've got my text rendering properly. I have a small request. My code is based on this: http://nehe.gamedev.net/tutorial/freetype_fonts_in_opengl/24001/

 

Does anyone know how to get the width of a string using this?



#9 haegarr   Crossbones+   -  Reputation: 4313

Like
0Likes
Like

Posted 29 October 2013 - 03:30 PM

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, 29 October 2013 - 03:31 PM.


#10 Zotoaster   Members   -  Reputation: 148

Like
0Likes
Like

Posted 29 October 2013 - 03:48 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS