Why does setting glRasterPos make my ftgl text disappear?

815 views Asked by At

I'm struggling with the FTGL library for fonts in opengl. For example, I still haven't figured out how to put the text somewhere on the screen other than the bottom left. I'm currently using a pixmap font, and I started experimenting with glRasterPos.

The following code "works" in that it displays the text on the bottom left in white:

ftglRenderFont(ftgl_freesans, "HELLO WORLD!", FTGL_RENDER_ALL);

In the following example, the text does not show up at all:

float r[4];
glGetFloatv(GL_CURRENT_RASTER_POSITION, r);
glRasterPos4fv(r);
ftglRenderFont(ftgl_freesans, "HELLO WORLD!", FTGL_RENDER_ALL);

I'm confused! Nothing should be different, so why does the font not render?

1

There are 1 answers

0
Tim On BEST ANSWER

glRasterPos is transformed by the current value of the matrix stack when you call it, it doesn't just 'set' the value.

Querying the value of current raster position returns the already transformed location. So that calling glRasterPos(glGet(GL_CURRENT_RASTER_POSITION)) has the effect of putting the current window space position through the transformation matrix again, which is not what you want.

If you set the modelview and projection matrix to identity, then your get/set operation should do what you expect.

A quote from MSDN:

The object coordinates presented by glRasterPos are treated just like those of a glVertex command. They are transformed by the current modelview and projection matrices and passed to the clipping stage. If the vertex is not culled, then it is projected and scaled to window coordinates, which become the new current raster position.