View Full Version : extra surface inside the octahedron

11-20-2015, 01:38 AM
Hi. I'm trying to render an octahedron with simple lighting effects. I only draw eight triangles. Why there's an extra surface inside the octahedron? See the attachment (my post gets denied if I use [img] tag in it and I don't know why:(

11-20-2015, 04:49 AM
That looks as if depth testing isn't working, resulting in back faces being drawn over front faces.

Is depth testing enabled? Does the window have a depth buffer? Is the depth buffer being cleared before rendering? Is the projection transformation meaningful (a perspective projection with too small a value for the near distance will result in very coarse depth resolution).

Alternatively, does enabling back-face culling fix the issue? For a convex object, front faces can't overlap, so depth testing isn't necessary if back faces are culled. Note that this requires the faces to have consistent orientation (clockwise or counter-clockwise).

11-20-2015, 06:27 AM
Thanks for your help, GClements. I've enabled GL_DEPTH_TEST and cleared the depth buffer every time before drawing. The extra surface is gone:). However, I can still see the back part of the octahedron. Lines that I newly added to my code are:


I use shader only to implement all the effects (lighting, camera motion, etc.). Do I only need to add these lines and then OpenGL will do the rest for me?

Currently I'm following this tutorial (ogldev.atspace.co.uk) but re-write some code to make it work on Linux.

11-20-2015, 10:41 AM
... I can still see the back part of the octahedron. Check to make sure the triangle normals are facing outward.