2012-03-15 79 views
1

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

这里是我使用的代码:

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

回答

2

与渲染的HUD或其他覆盖东西的诀窍,是切换到更方便的视口和投影他们的组合。

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

相关问题