在ortho上的OpenGL透视覆盖

时间:2016-04-19 11:13:45

标签: opengl textures perspective orthographic

我已经使用Ortho bound设置了背景纹理。我有一些透视图,需要覆盖在此之上。

为什么无法看到透视中的前景对象?

void handleResize(int w, int h)
    {
        width=w;
        height=h;
        glViewport(0, 0, w, h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);
    }
    void Draw2D()
    {     
        //ORTHO
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0f, 1024.0, 0.0, 512.0, 0.0, 1.f);

         glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, _textureId);

        //Bottom
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glBegin (GL_QUADS);
        glTexCoord2d(0.0,0.0); glVertex2d(0.0,0.0);
        glTexCoord2d(1.0,0.0); glVertex2d(1024.0,0.0);
        glTexCoord2d(1.0,1.0); glVertex2d(1024.0,512.0);
        glTexCoord2d(0.0,1.0); glVertex2d(0.0,512.0);
        glEnd();    
    }
    void Draw3D()
    {    
        //PERSPECTIVE
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0, (float)width / (float)height, 1.0, 200.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();           
        glTranslatef(0.0f, 0.0f, -6.0f);            
        glutWireCube(0.5);      
    }
    void drawScene()
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);             
        Draw3D();
        Draw2D();           
        glutSwapBuffers();
}

@Matso ..我正在使用以下功能进行深度测试

void initRendering() 
{
    //glEnable(GL_DEPTH_TEST);//Comment this
    glDepthMask(false);//Use this
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);    
    Image* image = loadBMP("earth.bmp");
    _textureId = loadTexture(image);
    delete image;
}

介绍

glDepthMask(false);

做了这个伎俩。我能够查看我的透视图。

0 个答案:

没有答案