[Haskell-cafe] renderString problems
Sven Panne
sven.panne at aedion.de
Sun Aug 26 09:50:23 EDT 2007
On Wednesday 01 August 2007 18:30, Dave Tapley wrote:
> I'm having a lot of trouble using renderString from Graphics.UI.GLUT.Fonts.
> All my attempts to render a StrokeFont have so far failed.
> Using a BitmapFont I can get strings to appear but they demonstrate
> the odd behaviour of translating themselves a distance equal to their
> length every time my displayCallback function is evaluated.
This is actually not a bug, but a feature. :-) From the Haddock docs for
renderString:
------------------------------------------------------------------------
Render the string in the named font, without using any display lists.
Rendering a nonexistent character has no effect.
If the font is a bitmap font, renderString automatically sets the OpenGL
unpack pixel storage modes it needs appropriately and saves and restores the
previous modes before returning. The generated call to bitmap will adjust the
current raster position based on the width of the string. If the font is a
stroke font, translate is used to translate the current model view matrix to
advance the width of the string.
------------------------------------------------------------------------
The rational behind this is that you set a position once, and subsequent
multiple renderString calls will render the individual strings one after the
other, just like printf appends strings on the output. If this is not clear
from the documentation, any suggestions how to improve the docs?
And another hint: On usual consumer graphic cards, stroke fonts are normally
faster than bitmapped fonts. The fastest, most flexible (scaling,
filtering, ...) and visually nicest option would be textured quads, but this
is not supported by GLUT.
> My requests are:
> * Does anyone know how to keep the position fixed?
For bitmapped fonts, explicitly set the currentRasterPosition. For stroke
fonts, you can use the normal modelview machinery
(loadIdentity/preservingMatrix/...).
> * Are there any good examples of (working) GLUT code available on
> the web, I'm finding it very hard to make any progress at the moment.
> Certainly not at Haskell speed :(
Depending on the distribution you use, you probably have the example already
somewhere on your disk or you can directly have a look at the repository:
http://darcs.haskell.org/packages/GLUT/examples/
Cheers,
S.
More information about the Haskell-Cafe
mailing list