0

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()
Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156
  • 1
    What exactly is the question here? You enable culling and the anticipated effect occurs (backfaces are removed). If you want to see the inside of your cylinder, why not just disable culling again? Or did I misunderstand you? – kroneml Jul 11 '12 at 09:35
  • I would rather have culling enable for speed of rendering. Mostly, the main question is *why the disk vanishes with culling enable*. Question edited. – Sardathrion - against SE abuse Jul 11 '12 at 09:40

2 Answers2

4

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.

kroneml
  • 677
  • 3
  • 16
2

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.

Christian Rau
  • 45,360
  • 10
  • 108
  • 185
  • I think the combination of `glPush/PopMatrix` and `glRotate` should be a little less efficient than just changing the orientation of the disk (not that it matters for this small example). However, this is of course a valid alternative solution for this problem! – kroneml Jul 11 '12 at 10:17
  • @kroneml Yes indeed. Changing the orientation didn't occur to me until I read your answer (haven't used GLU quadrics for ages, like everyone should), so I just let it stand as an alternative. Since he uses GLU quadrics and the fixed-function matrix stack, performance isn't an option here anyway, but you're probably right that the orientation change should be for free. – Christian Rau Jul 11 '12 at 10:49