I am building a simple Wavefront Obj file loader and renderer in Java, using JOGL. However, whenever I am loading a simple bunny test mesh, it's rendering in a glitchy fashion, and I have no idea what could be causing it. I am just using geometry vertices and normals, no textures or materials.
The following is the GL initialization code from the init()
method:
gl.setSwapInterval(1);
gl.glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
gl.glEnable(GL2.GL_DEPTH_TEST);
gl.glDepthFunc(GL2.GL_LESS);
gl.glEnable(GL2.GL_CULL_FACE);
gl.glCullFace(GL2.GL_BACK);
gl.glShadeModel(GL2.GL_SMOOTH);
gl.glClearDepth(1.0d);
And this is the method that I'm using to render the model (fixed pipeline, for now):
gl.glBegin(GL2.GL_TRIANGLES);
for(Face face : master.faces) {
for(int i = 0; i < face.points.length; i++) {
gl.glNormal3f(face.normals[i].x, face.normals[i].y, face.normals[i].z);
gl.glVertex3f(face.points[i].x, face.points[i].y, face.points[i].z);
}
}
gl.glEnd();
Where master
is the main "group" that contains all the faces and vertices. I've checked - everything goes into the master group, and glNormal3f and glVertex3f get called for every needed vertex in every triangle.
Can anyone tell what could be causing those glitches?
Edit 1:
Here is the code I'm using to set the projection and modelview matrices up:
float aspect = (float) width / (float) height;
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(60.0f, aspect, 0.01f, 100.0f);
glu.gluLookAt(2.0f, 1.0f, 1.5f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();