繁体   English   中英

OpenGL中有多个视口和文本……也许是相机?

[英]Multiple viewports and text in OpenGL…maybe it's the camera?

我必须有一个使用两个视口的OpenGL程序。 在其中一个中,我必须拥有一架带有工作摄像机的直升机模型,该摄像机可以围绕它旋转。 在决定进行视口拆分之前,我让相机在模型上工作,因为它具有更高的优先级。 另一个视口应该显示FPS计数器,但是由于某些原因,我只能从特定角度看到文本。

我的代码如下:

    //sets up the viewports
    void setView(int option)
    {
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        switch (option)
        {
            case 1: 
                glViewport(0,height-150,width,150);
                break;
            case 2:
                glViewport(0,0,width,height-150);
                break;
        }
        if(persp)
            gluPerspective(fovy, (GLfloat) width /(GLfloat) height , near, far);
        else
            glOrtho(left,right,bottom,top,-10,10);  

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        myCam.updateLook();
    }

    void writeBitmapString(void *font, char *string)
    {  
       char *c;
       for (c = string; *c != '\0'; c++) glutBitmapCharacter(font, *c);
    } 

    //main draw function
    void display(void)
    {   
        //Text portion of the window
        setView(1);
        glColor3f(1.0, 0.0, 0.0);
        glRasterPos3f(0, 0, 0.0);
        writeBitmapString((void*)font, "Test text");
        glutSwapBuffers();

        //Viewport for heli
        setView(2);
        glEnable(GL_DEPTH_TEST);
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);                
        glPushMatrix();
    //....The rest is just the modelling stuff
    glPopMatrix(); // final pop clause
    glFlush();
    glutSwapBuffers();

任何帮助将不胜感激。

听起来确实像您想要这里的HUD(请原谅我双重猜测您的意图)。 渲染场景,然后对模型视图和投影矩阵执行glLoadIdentity。 然后加载您的glOrtho。 最后,设置文本和渲染的栅格位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM