glutBitmapString shows nothing

后端 未结 1 1065
暖寄归人
暖寄归人 2021-01-15 13:17

I\'m going to show FPS on the screen with the freeglut function glutBitmapString,but it shows nothing. Here is my code. Is there anyone can figure where the problem is?

相关标签:
1条回答
  • 2021-01-15 13:47

    The position that's provided by glRasterPos is treated just like a vertex, and transformed by the current model-view and projection matrices. In you example, you specify the text to be position at (20,20), which I'm guessing is supposed to be screen (viewport, really) coordinates.

    If it's the case that you're rendering 3D geometry, particularly with a perspective projection, your text may be clipped out. However, there are (at least) two simple solutions (presented in order of code simplicity):

    1. use one of the glWindowPos functions instead of glRasterPos. This function bypasses the model-view and projection transformations.

    2. use glMatrixMode, glPushMatrix, and glPopMatrix to temporarily switch to window coordinates for rendering:

      // Switch to window coordinates to render
      glMatrixMode( GL_MODELVIEW );
      glPushMatrix();
      glLoadIdentity();    
      
      glMatrixMode( GL_PROJECTION );
      glPushMatrix();
      glLoadIdentity();
      gluOrtho2D( 0, windowWidth, 0, windowHeight );
      
      glRasterPos2i( 20, 20 );  // or wherever in window coordinates
      glutBitmapString( ... );
      
      glPopMatrix();
      glMatrixMode( GL_MODELVIEW );
      glPopMatrix();
      
    0 讨论(0)
提交回复
热议问题