Discussion:
WglUseFontBitmap alternatives
(too old to reply)
Andrea B. Previtera
2007-03-18 20:01:22 UTC
Permalink
Raw Message
Hi,
I've always used WglUseFontBitmap to create and output 2d text in my
opengl apps. The alternative would be using bitmapped fonts, which anyway
would limit me to *monospaced* fonts. Nonetheless, the problem with
WglUseFontBitmap driven text, is that for some reason I can't really find a
way to get the outputted string width in pixels...

Do you have any suggestion on how to find it, or even better a third way to
output 2d text? Thank you in advance,

- bee
Bruno Babic
2007-03-19 11:18:15 UTC
Permalink
Raw Message
Post by Andrea B. Previtera
Hi,
I've always used WglUseFontBitmap to create and output 2d text in my
opengl apps. The alternative would be using bitmapped fonts, which anyway
would limit me to *monospaced* fonts. Nonetheless, the problem with
WglUseFontBitmap driven text, is that for some reason I can't really find a
way to get the outputted string width in pixels...
You can use bitmapped fonts which aren't monospaced.
I've done it without any problems and it works perfectly. Output width
in pixels works fine too.
Post by Andrea B. Previtera
Do you have any suggestion on how to find it, or even better a third way to
output 2d text? Thank you in advance,
I've done it in such way that I have one file which consists of
character data (rect-like structure) which contains x, y, width and
height of a certain character inside bitmap that I use as a texture for
character quads.

Everything else is the same like the usual bitmapped fonts, except that
you must manually compute output width by adding each character's width
from output string.
--
bbabic(a)globalnet.hr
2b||!2b?
Uwe Kotyczka
2007-03-19 11:34:01 UTC
Permalink
Raw Message
Post by Andrea B. Previtera
I've always used WglUseFontBitmap to create and output 2d text in my
opengl apps. The alternative would be using bitmapped fonts, which anyway
would limit me to *monospaced* fonts. Nonetheless, the problem with
WglUseFontBitmap driven text, is that for some reason I can't really find a
way to get the outputted string width in pixels...
No need to drop wglUseFontBitmap!
It is possible to get the string length in pixels.
It goes like this:

double negStrWidth;
GLdouble tmpCurrentRasterPosition[4];
CString strText = _T("TEST");

glGetDoublev(GL_CURRENT_RASTER_POSITION, tmpCurrentRasterPosition);
negStrWidth = tmpCurrentRasterPosition[0];
glCallLists(strText.GetLength(), GL_UNSIGNED_BYTE, strText);
glGetDoublev(GL_CURRENT_RASTER_POSITION, tmpCurrentRasterPosition);
negStrWidth -= tmpCurrentRasterPosition[0];

If you need to calculate the string width before actually
rendering it you can first render it invisible [using a stencil
buffer if availible or by glDrawBuffer(GL_NONE)].
For details you might want to take a look at my demo
http://home.arcor.de/kotyczka/opengl_en.html.

Feel free to send me an email for further questions.
u***@web.de
2016-12-13 18:52:57 UTC
Permalink
Raw Message
Post by Uwe Kotyczka
For details you might want to take a look at my demo
http://home.arcor.de/kotyczka/opengl_en.html.
Update: Now it can be found at
http://kotyczka.000webhostapp.com/opengl_en.html
Uwe Kotyczka
2017-01-02 00:12:09 UTC
Permalink
Raw Message
Post by u***@web.de
Post by Uwe Kotyczka
For details you might want to take a look at my demo
http://home.arcor.de/kotyczka/opengl_en.html.
Update: Now it can be found at
http://kotyczka.000webhostapp.com/opengl_en.html
Moved once again to
http://kotyczka.webspace4free.net/opengl_en.html

Wolfgang Draxinger
2007-03-22 09:47:22 UTC
Permalink
Raw Message
Post by Andrea B. Previtera
The alternative would be using bitmapped fonts,
which anyway would limit me to *monospaced* fonts.
No, it won't. Ages ago (2001 namely) I wrote a small example
class, that generates a font texture along with some box data.
It has no kerning, but proportional fonts work flawlessly.
Post by Andrea B. Previtera
Do you have any suggestion on how to find it, or even better a
third way to output 2d text? Thank you in advance,
I abandoned the idea of texture mapped fonts, as with Unicode you
have no chance to store all possible characters and character
ligatures in a texture. Instead I'm now using the freetype
library to render a whole text into a texture and display that.
It's easier and works well.

Wolfgang Draxinger
--
E-Mail address works, Jabber: ***@jabber.org, ICQ: 134682867
Loading...