/* * OpenGL implementation of glWindowPos*MESA() */ void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w ) { GLfloat fx, fy; /* Push current matrix mode and viewport attributes */ glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT ); /* Setup projection parameters */ glMatrixMode( GL_PROJECTION ); glPushMatrix(); glLoadIdentity(); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); glLoadIdentity(); glDepthRange( z, z ); glViewport( (int) x - 1, (int) y - 1, 2, 2 ); /* set the raster (window) position */ fx = x - (int) x; fy = y - (int) y; glRasterPos4f( fx, fy, 0.0, w ); /* restore matrices, viewport and matrix mode */ glPopMatrix(); glMatrixMode( GL_PROJECTION ); glPopMatrix(); glPopAttrib(); }
void CHapticViewerView::drawTextGL(int x, int y, char* text) { glPushAttrib(GL_TRANSFORM_BIT | GL_VIEWPORT_BIT | GL_LIGHTING); glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); y = m_windowHeight - FONT_HEIGHT - y; glViewport(x-1, y-1, 0, 0); glRasterPos4f(0, 0, 0, 1); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glColor3f(1.0, 1.0, 1.0); glListBase(m_fontListBase); glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); glPopAttrib(); }
void PositionText( int x, int y ) { // If you are to use this font code for your applications, // you must be aware that you cannot position the font in 3D, // which means you can't rotate and scale it. That will be covered in // the next font tutorial. BUT, though that might be a drag, this code // is useful because when you display the text, it will always be on top // of everything else. This is good if the camera is moving around, and you // don't want the text to move. If the text was positioned in 3D you would have // to come up with a tricky way of making it always render in front of the camera. // To do this, we need to set the Raster Position. That is the position that OpenGL // starts drawing at. Since it's in floating point, it's not very intuitive, so what // we do is create a new view port, and then always draw the text at (0, 0, 0) in that // view port. The weird part is that the Y is flipped, so (0, 0) is the bottom left corner. // Below we do some simple math to flip it back to normal. // Before we create a new view port, we need to save the current one we have. // This saves our transform (matrix) information and our current viewport information. // At the end of this function we POP it back. glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT ); // Here we use a new projection and modelview matrix to work with. glMatrixMode( GL_PROJECTION ); // Set our matrix to our projection matrix glPushMatrix(); // Push on a new matrix to work with glLoadIdentity(); // reset the matrix glMatrixMode( GL_MODELVIEW ); // Set our matrix to our model view matrix glPushMatrix(); // Push on a new matrix to work with glLoadIdentity(); // Reset that matrix // Because the Y is flipped, we want 0 to be at the top, not bottom. // If we subtract the font height from the screen height, that should display the // font at the top of the screen (if they passed in 0 for Y), but then we subtract // the Y from that to get the desired position. Since the font's drawing point is // at the base line of the font, we needed to subtract the font height to make sure // if they passed in (0, 0) it wouldn't be off screen. If you view this in window mode, // the top of the window will cut off part of the font, but in full screen it works fine. // You just need to add about 25 to the Y to fix that for window mode. y = SCREEN_HEIGHT - FONT_HEIGHT - y; // Calculate the weird screen position // Now we create another view port (that is why we saved the old one above). // Since glViewPort takes the lower LEFT corner, we needed to change the Y // to make it more intuitive when using PositionText(). We minus 1 from the X and Y // because 0 is taken into account with the position. The next 2 parameters are set // to 0 for the width and height so it will always draw in the middle of that position. // glRasterPos4f() takes (0, 0, 0) as the middle of the viewport, so if we give it a small // width/height it will draw at the X and Y given. Sounds strange, to test this, try // using glRasterPos4f(0, 0, 0, 1) instead of PositionText() and you will see, everything // will be drawn from the middle. glViewport( x - 1, y - 1, 0, 0 ); // Create a new viewport to draw into // This is the most important function in here. This actually positions the text. // The parameters are (x, y, z, w). w should always be 1 , it's a clip coordinate. // don't worry about that though. Because we set the projection and modelview matrix // back to the beginning (through LoadIdentity()), the view port is looking at (0, 0, 0). // This is the middle, so if we set the drawing position to the middle, it will draw at our // X and Y because the width/height of the viewport is 0, starting at X and Y. // You can actually call this function (or glRasterPos2f(0, 0)) instead of PositionText(), // but it is in floating point and doesn't work as nicely. You will see why if you try. glRasterPos4f( 0, 0, 0, 1 ); // Set the drawing position // Now that we positioned the raster position, any text we draw afterwards will start // from that position. Now we just have to put everything else back to normal. glPopMatrix(); // Pop the current modelview matrix off the stack glMatrixMode( GL_PROJECTION ); // Go back into projection mode glPopMatrix(); // Pop the projection matrix off the stack glPopAttrib(); // This restores our TRANSFORM and VIEWPORT attributes }
template< > inline void glRasterPos4< float > (float x,float y,float z, float w ) { glRasterPos4f(x,y,z,w); };
///////////////////////////////////////////////////////// // Render // void GEMglRasterPos4f :: render(GemState *state) { glRasterPos4f (x, y, z, w); }
void glRasterPos4fv(const GLfloat *v) { glRasterPos4f(v[0], v[1], v[2], v[3]); }
//------------------------------------------------------------------------------ // void DrawStringAt(const wxString &str, GLfloat x, GLfloat y, GLfloat z, GLfloat k) //------------------------------------------------------------------------------ void DrawStringAt(const wxString &str, GLfloat x, GLfloat y, GLfloat z, GLfloat k) { glRasterPos4f(x, y, z, k); glCallLists(strlen(str.c_str()), GL_BYTE, (GLubyte*)str.c_str()); }
M(void, glRasterPos4f, jfloat x, jfloat y, jfloat z, jfloat w) { glRasterPos4f(x, y, z, w); }