OpenGL:相对于屏幕设置glPrint()位置

时间:2012-03-15 02:54:54

标签: c++ opengl text

我正在尝试在屏幕左下方打印一些调试信息(FPS,摄像机位置和旋转等)。我已经设置它以便使用glTranslate()glRasterPos2f()正常工作,但是如果我尝试调整窗口大小,文本就不再完美地放在角落里,并且取决于我伸展多少在窗外,它可能出现在屏幕中间,或者它可能开始被切断。有没有办法使用glPrint()来打印文字,左边是10px,右边是10px?

以下是我正在使用的代码:

GLvoid glPrint(const char *fmt, ...){                   // Custom GL "Print" Routine
    char        text[256];                              // Holds Our String
    va_list     ap;                                     // Pointer To List Of Arguments
    va_start(ap, fmt);                                  // Parses The String For Variables
        vsprintf(text, fmt, ap);                        // And Converts Symbols To Actual Numbers
    va_end(ap);                                         // Results Are Stored In Text

    glPushAttrib(GL_LIST_BIT);                          // Pushes The Display List Bits
    glListBase(base - 32);                              // Sets The Base Character to 32
    glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);  // Draws The Display List Text
    glPopAttrib();                                      // Pops The Display List Bits
}

void GLOUT(float xLocation, float yLocation, float colorRed, float colorGreen, float colorBlue){
    glDisable(GL_TEXTURE_2D);
    glLoadIdentity();
    glTranslatef(0,0,-.002);
    glColor3f(colorRed,colorGreen,colorBlue);
    glRasterPos2f(xLocation/10000, yLocation/10000);
    glPopMatrix();
}

enter image description here

1 个答案:

答案 0 :(得分:2)

渲染HUD或其他叠加内容的技巧是切换到更方便的视口和投影组合。

您不会被迫使用OpenGL坚持一个特定的投影。让我猜一下:你在窗口的调整大小处理程序中设置视口和投影,对吧?建议:将该代码移动到绘图功能,并且(希望)有一个顿悟这样做。

相关问题