My understanding of Culling is that if something opaque is in front of something else, whatever is in the back will not be drawn. If this is correct, I’m having problems with the triangle fan. It can be seen through some shapes, but not through others. I’ve shown the drawing code below, and linked to the full code (which includes rotation via the arrow keys, and reset with the space bar) here: http://www.theouterrim.net/Test1.java Would someone please tell me what I’m missing in the geometry here? Thanks.
protected boolean drawGLScene(float frameTime)
{
/* Clear The Screen And The Depth Buffer */
gl.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);
/* Reset The Current Modelview Matrix */
gl.loadIdentity();
gl.rotatef(angleRotateX, 1.0f, 0.0f, 0.0f);
gl.rotatef(angleRotateY, 0.0f, 1.0f, 0.0f);
gl.polygonMode(GL.FRONT_AND_BACK, GL.LINE);
gl.enable(GL.CULL_FACE);
gl.frontFace(GL.CW);
gl.color3f(0.0f, 0.0f, 1.0f);
gl.begin(GL.TRIANGLE_FAN);
gl.vertex3f(20.0f, 30.0f, 200.0f);
gl.vertex3f(20.0f, 40.0f, 0.0f);
gl.vertex3f(60.0f, 30.0f, -20.0f);
gl.vertex3f(40.0f, -20.0f, -10.0f);
gl.vertex3f(20.0f, 40.0f, 0.0f);
gl.end();
gl.begin(GL.TRIANGLE_FAN);
gl.vertex3f(-20.0f, 30.0f, 200.0f);
gl.vertex3f(-40.0f, -20.0f, -10.0f);
gl.vertex3f(-60.0f, 30.0f, -20.0f);
gl.vertex3f(-20.0f, 40.0f, 0.0f);
gl.vertex3f(-40.0f, -20.0f, -10.0f);
gl.end();
gl.begin(GL.POLYGON);
gl.vertex3f(-20.0f, 40.0f, 0.0f);
gl.vertex3f(-60.0f, 30.0f, -20.0f);
gl.vertex3f(0.0f, 40.0f, -70.0f);
gl.vertex3f(60.0f, 30.0f, -20.0f);
gl.vertex3f(20.0f, 40.0f, 0.0f);
gl.end();
gl.begin(GL.POLYGON);
gl.vertex3f(40.0f, -20.0f, -10.0f);
gl.vertex3f(20.0f, -20.0f, -60.0f);
gl.vertex3f(-20.0f, -20.0f, -60.0f);
gl.vertex3f(-40.0f, -20.0f, -10.0f);
gl.vertex3f(40.0f, -20.0f, -10.0f);
gl.end();
gl.begin(GL.TRIANGLE_STRIP);
gl.vertex3f(40.0f, -20.0f, -10.0f);
gl.vertex3f(60.0f, 30.0f, -20.0f);
gl.vertex3f(20.0f, -20.0f, -60.0f);
gl.vertex3f(0.0f, 40.0f, -70.0f);
gl.vertex3f(-20.0f, -20.0f, -60.0f);
gl.vertex3f(-60.0f, 30.0f, -20.0f);
gl.vertex3f(-40.0f, -20.0f, -10.0f);
gl.end();
gl.begin(GL.POLYGON);
gl.vertex3f(-20.0f, 40.0f, 0.0f);
gl.vertex3f(20.0f, 40.0f, 0.0f);
gl.vertex3f(40.0f, -20.0f, -10.0f);
gl.vertex3f(-40.0f, -20.0f, -10.0f);
gl.end();
return true;
}
Your resizeGLScene method pushes both the projection and modelling matrices, but nothing in the program pops them again. As the projection matrix stack may only be two deep, calling resizeGLScene twice may cause OpenGL to error. You’re not storing the matrixes for any reason, and just loadIdentity straight after, so it’s probably worth just deleting those lines.
I’ve got my buffers inside out… :-X