Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Bitmap positioning

This topic is 5580 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all... I started learning OpenGL some days ago, and I made some progress. Right now, I''m trying to transfer what I''ve learned in NeHe lesson 13 (bitmap fonts) to the first few "interesting" lessons (I''m trying to add a frames/sec display to a spinning pyramid and a textured quad). What I have is a class to load a font and display a string at a given position. It is working in the bare bone code from lesson 13. Basically, the print method does this:
void print( float x, float x, char* s, ... ) {
  // build the resulting string
  ...

  // create an array of display list indices from the string
  ...

  glRasterPos2f( x, y );
  glPushAttrib( GL_LIST_BIT );
  glListBase( FontBase );
  glCallLists( length, GL_UNSIGNED_INT, listindices );
  glPopAttrib();
}
 
Now, in lesson 13, the projection matrix is built with glOrtho(...) and all works nicely, producing a mapping between pixels and raster position, so that (0,0) is lower left, (640,480) is upper right. In the code from the other lesson, projection is set up with gluPerspective(45.0f,ratio,0.1f,100.0f) to have a perspective. Now my problem is that no matter what I do, I cannot restore the ortho-mapping. I tried about anything up to re-initializing the projection- and modelview matrices. The current code looks like this:
  glPushMatrix();
  glLoadIdentity();
  glOrtho(0, 640, 0, 480, 1.0, -1.0); //hardcoded resolution
  glTranslatef( 0.0f, 0.0f, -2.0f );
  glColor4f( 1.0f, 1.0f, 0.5f, 1.0f );
  font.print( -20.0, 50.0, "FPS: %03.3f", cur_fps );
  glPopMatrix();
 
Using the raster position (-20.0,50.0) takes me somewhere near the lower left. But how do I make it that for font.print() (0,0) is lower left?

Share this post


Link to post
Share on other sites
Advertisement
If you can, save yourself the trouble or messing with matrices and use glWindowPos to directly set the raster position in window coordinates. It''s in the OpenGL 1.4 core, so you will have to treat it as an extension on Windows.

As for the problem you have, make sure that the modelview is set to identity AND projection matrix is set to orthographic. One of them is not enough. Something like this.

  
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(...);

// draw here


glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

But as I said, save yourself the touble and use glWindowPos.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!