View Full Version : Drawing Text
05-07-2012, 07:00 AM
Hi guys, I'm creating a 2D UI which will display text. Problem is, I don't know which text drawing method to use. The texture method seems simplest and quickest to set up in my mind but I'm not sure how it will work on various resolutions. Obviously resizing the UI will stuff up the crispness, but say I make it so that the UI is not adjustable in size, how would a resolution jump from 1024 to 2560 affect the final result? The other issue is that my UI will have an option to be able to size it not according to resolution but according to physical dimensions in cm... I suppose considering the fact that cm and pixel ratio is constant, that would basically mean a resolution change? no? but basically, I want the screen to display at its best in its fixed size version irrespective of resolution. Is the texture method still valid? Also, is it possible to use vector images as textures as opposed to .TGA or .BMP?
05-08-2012, 09:55 AM
You can solve the resolution related questions by making the texture size dependent on the display resolution. If the display resolution changes (should be a rare event) recreate the texture at the appropriate size for the new resolution.
This assumes you can render the font glyphs to a texture (using e.g. the freetype library). If you create the glyph texture offline you could prepare a couple of versions to cover different resolution ranges.
Sorry, don't know what a "vector image" is.
05-10-2012, 09:41 AM
Thanks for the suggestions, however there are a lot of different monitor resolutions and I prefer not to edit text in accordance with each resolution as that would be too much work. Secondly, I would probably eventually like to be able to resize my screen with the contents resizing accordingly, so keeping that in mind, making a set of images for different resolutions won't be able to compensate for resizing.
FYI, a raster image is one that is RGBA for example... i.e. each pixel has information regarding RGB and A depending on formats etc. If you resize, you get stretching. A vector image on the hand is one drawn with lines that have mathematical formulas attached... that way, when you resize, the image doesn't appear stretched as all the mathematically derived lines change in accordance to the transformation and the image doesn't get distorted. It's of limited use in game design for example because most objects in games don't get resized... e.g. a human character does't all of a sudden become 2ce as tall and twice as lean, so in games, generally you can get away with raster images.
05-10-2012, 10:35 AM
Well, if you want to have optimal text resolution for any window geometry you'll have to generate the text representation on the fly. As I already mentioned you can still use textured quads for each text character, but you need to generate the texture content at runtime (instead of loading a file). One way to do that is to use a font rendering library (freetype is a popular one). Alternatively you need to generate geometry to represent your font glyphs since that retains the scalability of a vector representation.
Textures in OpenGL are always raster images. The only way to handle vector formats is to rasterize them at a fixed resolution for display and if the size changes significantly update the rasterization to a higher/lower resolution. There is also an Nvidia extension NV_path_rendering (http://www.opengl.org/registry/specs/NV/path_rendering.txt) that can help with that.
05-10-2012, 11:47 AM
if the size changes significantly update the rasterization to a higher/lower resolution.
Or you can use Valve's nicer scaling technology. (PDF) (http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf)
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.