PDA

View Full Version : Object is translucent. Depth problem.



Waleed
12-22-2011, 05:51 AM
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.

http://i65.photobucket.com/albums/h230/willy_foe_lyfe/plane.png

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.

excali
12-22-2011, 06:17 AM
Can't find any problem with depth in your code
What's wrong with this picture? Can you provide more details?

Waleed
12-22-2011, 06:22 AM
http://i65.photobucket.com/albums/h230/willy_foe_lyfe/plane_correct.png

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

excali
12-22-2011, 06:39 AM
To my understanding, your first picture is just observing the model from another direction than the your second picture.

thokra
12-22-2011, 06:46 AM
Yep. Your rotation is the the problem. It's actually no observable translucency anywhere.

awhig
12-22-2011, 01:21 PM
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?

Waleed
12-23-2011, 11:51 AM
@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);
}

Waleed
12-23-2011, 11:54 AM
@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!

thokra
12-23-2011, 03:06 PM
How does it look when you leave out the rotation?

awhig
12-23-2011, 04:42 PM
@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.

Waleed
12-24-2011, 10:39 AM
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.