views:

173

answers:

3

Hey all, I am very very new to OpenGL, so please bear with me. :) I'm working through NeHe's OpenGL tutorials, and I have developed my own version of Lesson 5, in which you rotate a 3D shape around the origin. I'm not sure what I did wrong, I copied the code nearly line-for-line, but I'm seeing strange overlaps in my surfaces.

Does anyone have any suggestions as to what would cause such an issue?

Thanks!

Example here: http://yfrog.com/2copengllesson5p

A: 

Looks like you've got an issue with the depth buffer. In particular it looks like each polygon is being drawn without regard to depth i.e. each fragment coming from the polygons is passing the depth test. This would mean that the polygons are simply drawn over each other in whatever order they happen to be rendered in.

Did you disable writing to the depth buffer with something like

glDepthMask( GL_FALSE )

by any chance?

If it's not that then did you remember to clear the depth buffer at the beginning of each frame? The Nehe tutorial starts with

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

which clears both the depth and colour buffers. Make sure you haven't got rid of the GL_DEPTH_BUFFER_BIT part of that.

HTH

Troubadour
Here are the relevant "properties" of my GL:gl = context.getGL(); gl.glColor3f(0.0f, 0.0f, 0.0f); gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glShadeModel(GL.GL_SMOOTH); // Enables Smooth Shading gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing
craig
Try adding `gl.glDepthMask(true);` add see if that makes a difference.
Troubadour
Adding the gl.glDepthMask(true) didn't seem to change anything. :(
craig
A: 

To me it looks like you are missing enabling the Depth buffer or maybe creating a framebuffer with a z-buffer. (this is similar to what Troubadour is writing)

glEnable(GL_DEPTH_TEST);
epatel
A: 

Wow, completely fixed it with one line:

gl.glEnable(GL.GL_CULL_FACE);

I have no idea what it does, but it wasn't mentioned in any tutorials I used, but my demo works perfectly now. Off to Google to figure out what that did. :D

craig