PDA

View Full Version : Drawing 2d text : glRasterPos



Ignasi
09-19-2011, 03:02 AM
Hi,

I'm trying to do draw a 2d text in screen coordinates (in order to be always visible by the user), in a 3d context.

It works fine, but after restoring the projection and modelview matrixs something doesn't work properly with selection. I always get a hit wherever I put the mouse pointer. It seems like something is wrong with the modelview restoration. I don't know what I'm missing.

Thats's a code snippet of what I'm doing:

//changing to 2d projection
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, (GLfloat)(viewport[2] - viewport[0]), 0.0, (GLfloat)(viewport[3] - viewport[1]), -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glPushAttrib(GL_LIST_BIT);
glListBase(IDBASELISTAFUENTETEXTO);

glRasterPos2d(...);
glCallLists(...); //to draw the text

glPopAttrib();

//restore matrixs
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

I've even tried to use glPushAttrib(GL_ALL_ATTRIB_BITS) and glPopAttrib()...

Thanks in advance,

Ignasi