OpenGL的表面呈现的问题表面、问题、OpenGL

2023-09-08 10:36:44 作者:戏子无情ぴ

我刚开始加载一些OBJ文件,并使用OpenGL渲染。当我使这些网格我得到这样的结果(见图片)。 我认为它的某种深度的问题,但我不能搞清楚自己干。 多数民众赞成的参数进行渲染:

I just started loading some obj files and render it with opengl. When I render these meshes I get this result (see pictures). I think its some kind of depth problem but i cant figure it out by myself. Thats the parameters for rendering:

    // Dark blue background
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

// Enable depth test
glEnable( GL_DEPTH_TEST );

// Cull triangles which normal is not towards the camera
glEnable(GL_CULL_FACE);

我用这个教程code为模板。的https://$c$c.google.com/p/opengl-tutorial-org/source/browse/#hg%2Ftutorial08_basic_shading

I used this Tutorial code as template. https://code.google.com/p/opengl-tutorial-org/source/browse/#hg%2Ftutorial08_basic_shading

推荐答案

这个问题很简单,你正在做的正面或背面剔除。

The problem is simple, you are doing FRONT or BACK culling.

和目标文件中包含CCW(反顺时针)或CW(顺时针)cordinates,这么写从左至右或从右到左。 你的OpenGL code期待它倒过来,所以它隐藏了面,你正在寻找落后的。

And the object file contains CCW(Counter-Clock-Wise) or CW (Clock-Wise) cordinates, so written from left to right or right to left. Your openGL code is expecting it in the other way round, so it hides the surfaces which you are looking backward on.

要检查该解决您的问题,只是采取了过glEnable(GL_CULL_FACE); 因为这恰好似乎是产生这个问题。

To check this solves your problem, just take out the glEnable(GL_CULL_FACE); As this exactly seems to be producing the problem.

此外,您可以使用 glCullFace(ENUM); 其中,ENUM必须是 GL_FRONT GL_BACK 。 如果你没有在这两种情况下至少有一个不能看到你的网格(指在两种情况下: GL_FRONT GL_BACK 你只看到了部分网状),那是一个问题,除preting的.OBJ你的code。或.OBJ使用没有严格的表面载体。 (CCW和CW的混合)

Additionally you can use glCullFace(ENUM); where ENUM has to be GL_FRONT or GL_BACK. If you don't in at least one of both cases can't see your mesh (means in both cases: GL_FRONT or GL_BACK your just seeing the partial mesh) , thats a problem with your code of interpreting the .obj. or the .obj uses not strict surface vectors. (A mix of CCW and CW)