So, I’m an openGL newbie, but not a Java newbie. Here’s my problem: Cubes and Spheres work, but when I started making a Terrain object for my openGL engine, I ran into a problem which has completely stumped me. In this demo I’ve included a superimposed wooden crate which is drawing correctly (except for when it crosses the axes) to show how the terrain is supposed to be rotating.
Firstly, here’s the jar file: http://www.ageofinsanity.com/jogl/Test/Test.jar
(Arrow keys, Q, and W to rotate, no zoom implemented) - source files are included in the jar
Here’s the critical code:
TestRenderer.java - void init(GlDrawable drawable):
// Prepare all geometry here but draw nothing
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_GEQUAL);
gl.glFrontFace(GL.GL_CCW);
gl.glEnable(GL.GL_CULL_FACE);
gl.glCullFace(GL.GL_BACK);
gl.glShadeModel(GL.GL_SMOOTH);
If I do glFrontFace with Clockwise instead of Counter-Clockwise, the whole terrain draws fine, except flipped horizontally (if you were just looking at the 2D texture. Also, the Normal points downward instead of upward. This wouldn’t be a concern if I was drawing a generated landmass, but in this case, Im not.
I realize that I could just flip the texture and heightmap horizontally and invert the Normal, but that’s just a workaround. I’d rather have the code work exactly the way I intend.
The other (bigger) problem I’m having is that objects closer than .5f (on the Z-axis) and farther than 1.0f (on the Z-axis) don’t get drawn. I have no idea why this is happening, especially considering I have tried gluPerspective over and over, and it hasn’t helped a bit.
Any help is greatly appreciated. I’ve been studying guides on here, as well as NeHe’s guide and this page. I’m completely out of ideas. Please help me out.