Object is translucent. Depth problem.

Okay, so I’m new here. I’m trying to load the f-16 obj file that Nate Robins provided with his examples. Here is how my code goes, very simple I believe.


	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	GLfloat lightpos[] = {-1, -1, -1, 0};
	glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
	glEnable(GL_DEPTH_TEST);
	glPushMatrix();
	glRotatef(-38.0,-0.84,1.00,0.00);
	drawModel();
	glPopMatrix();
	glutSwapBuffers();

This is what I get.

I do ask glut for a depth buffer.


glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

All I want to do is see the obj correctly, from any angle and in any way possible. Any help is much appreciated, Thank you.

Can’t find any problem with depth in your code
What’s wrong with this picture? Can you provide more details?

This is what it should look like. Sorry if I wasn’t detailed enough.

To my understanding, your first picture is just observing the model from another direction than the your second picture.

Yep. Your rotation is the the problem. It’s actually no observable translucency anywhere.

I differ. The view angle is same but careful observation shows parts of the plain ( especially the second rocket) visible instead the other way, as it comes just under the wing. Rotation would have affected the tail too.

@Waleed: Please check the drawmodel(). Are you drawing backface after the front face? Are you using blending function?

@awhig:

Here is my drawmodel() function,


void drawModel(void)
{
    if(!pmodel)
	{
		pmodel = glmReadOBJ("f-16.obj");
		if(!pmodel)
			exit(0);
		glmUnitize(pmodel);
		glmFacetNormals(pmodel);
		glmVertexNormals(pmodel, 90.0);
    }
	glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}

@thokra:

It’s not translucent. I don’t know what it is. It’s the same angle and I should not be able to see the rocket in the middle. I should barely be able to see the tips of the second rockets as well. It’s driving me crazy!

How does it look when you leave out the rotation?

@Waleed

How are the triangles defined in the model file? Are there any entries for back faces, with negative values?

Most probable reason looks to be wrong lighting calculations. i.e calculation between face/vertex normal and light vector is still positive for a face that is facing away from you. If this is true then back faces will look to you as front faces.

As a test, do one thing, disable all lighting and check the quality of model drawn. If you get exactly what is desired it means there is some problem in lighting calculations.

I wasn’t specifying a viewing frustum whatsoever. That was my problem. I just added

gluPerspective(60,aspect,0.1,10);

right after

glMatrixMode(GL_PROJECTION);

and everything worked perfectly.

Thank you thokra, awhig and excali for your help, much appreciated.