If I draw a gluCylinder with a gluDisk on top. Without culling enabled, I get the desired cylinder with lid effect. However, if I enable culling, the disk (aka lid) disappears. Why is that? This is the main question. In addition, with culling enabled the back faces of the cylinder are also not drawn. I get why this is happening but I would still like to see the inside of the cylinder drawn. The code is:

    glPushMatrix()
    quadratic = gluNewQuadric()
    gluQuadricNormals(quadratic, GLU_SMOOTH)
    gluQuadricTexture(quadratic, GL_TRUE)
    glRotatef(90, 1, 0, 0)
    glTranslate(0, 0, -3*sz)
    gluCylinder(quadratic, 0.75*sz, 0.75*sz, 3.0*sz, 32, 32)
    gluDisk(quadratic, 0.0, 0.75*sz, 32, 32)
    glPopMatrix()
有帮助吗?

解决方案

Your disk is facing in the wrong direction (wrong winding). Therefore, it is culled. You can try to reverse its orientation using gluQuadricOrientation, this should do the trick. For more information, refer to the OpenGL spec for gluDisk and glCullFace.

其他提示

A disk is just a plane without any thickness. So one side is front and the other is back and with culling enabled one of those gets culled away. You are probably just seeing the culled away side. If this is not the side you want to see, just rotate the disk around. Nothing fancier to it. So just wrap it into a:

glPushMatrix();
glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
gluDisk(quadratic, 0.0, 0.75*sz, 32, 32);
glPopMatrix();

Or, like kroneml suggests, change its triangles' orientations. Decide for yourself which one is more conceptually correct in your situation.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top