C++ 如何绘制2D&;OpenGL中的3D素材一起使用?

C++ 如何绘制2D&;OpenGL中的3D素材一起使用?,c++,visual-c++,opengl,3d,2d,C++,Visual C++,Opengl,3d,2d,如何在OpenGL中同时绘制二维和三维图形?如果可能的话,请给我一些C++代码。 请演示如何在3D对象的后面和前面绘制。您在正确的轨道上,但绘制2d图形时还必须禁用深度测试:glDisable(GL\u depth\u TEST) 否则它可能会被3d图形隐藏。关于这种方式: void render_perspective_scene(void); void render_ortho_scene(void); void render_HUD(); void display() { f

如何在OpenGL中同时绘制二维和三维图形?如果可能的话,请给我一些C++代码。
请演示如何在3D对象的后面和前面绘制。

您在正确的轨道上,但绘制2d图形时还必须禁用深度测试:
glDisable(GL\u depth\u TEST)

否则它可能会被3d图形隐藏。

关于这种方式:

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();
}

我试着把东西画成3D,然后用glOrtho在2D里画东西,但是3D的东西似乎覆盖了我所有的2D画,所以这些2D的东西会闪烁!!!请提供您现有的代码,我们需要看看您尝试了什么,以便我们可以进一步帮助您。tks Neil,我已经找到了原因,因为我忘了调用glloadIdentityDable深度测试似乎只有在我们在3D场景后绘制某些内容时才有意义?