如何在OpenGL中一起绘制2D和3D材质?

问题描述:

如何绘制2D & OpenGL中的3D材质?如果可能,请给我看一些C++代码。 请同时显示如何在3D对象前面绘制&。如何在OpenGL中一起绘制2D和3D材质?

+0

我试过gluPerspective画事情3D,然后用glOrtho画的东西在2D,但随后3D的东西似乎覆盖所有的二维图纸,从而使这些2D东西闪烁! – jondinham

+0

任何解决方案?.. – jondinham

+3

请提供您现有的代码,我们需要查看您所尝试的内容,以便我们可以进一步帮助您。 –

关于这样:

void render_perspective_scene(void); 

void render_ortho_scene(void); 

void render_HUD(); 

void display() 
{ 
    float const aspect = (float)win_width/(float)win_height; 

    glViewport(0,0,win_width,win_height); 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glFrustum(-aspect*near/lens, aspect*near/lens, -near/lens, near/lens, near, far); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
    render_perspective_scene(); 

    // just clear the depth buffer, so that everything that's 
    // drawn next will overlay the previously rendered scene. 
    glClear(GL_DEPTH_BUFFER_BIT); 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glOrtho(-aspect*scale, aspect*scale, -scale, scale, 0, 1); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
    render_ortho_scene(); 

    // Same for the HUD, only that we render 
    // that one in pixel coordinates. 
    glClear(GL_DEPTH_BUFFER_BIT); 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glOrtho(0, win_width, 0, win_height, 0, 1); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
    render_HUD(); 
} 

你在正确的轨道上,但是您绘制2D图形时,还必须禁用深度测试:glDisable(GL_DEPTH_TEST);

否则可能会被你的3D图形变成隐藏。

+0

只有当我们在3D场景背后绘制东西时,diable depth test才有意义? – jondinham