1
votes

SOLVED: I'm not really sure how though... thanks for all your help guys.

I tried glDisable(GL_CULL_FACE); but the mesh is still not visible.

Basically I'm trying to draw a mesh (made from verts, normals, and texture coords) in OpenGL, using a display list. The mesh is on .obj format (exported from 3ds max 2013)

The problem is that the mesh is not visible.

To draw the display list I'm just using glCallLists (list, 1);

I have verified that I can draw things to the screen by drawing a point in the center of the screen and that works fine.

Could it be possible that the camera is positioned inside the mesh? If so is there an OpenGL state that I could enable to allow me to see the inside of a set of verts?

I know that the data I have is all valid, verified by printing each vert, normal and texture coord to a file before adding it to the display list, it looks valid.

I have dont no glTranslatef or anything like that, my projection matrix is setup like this:

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (45.0, (float)1024/(float)768, -9999, 9999);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();

If you want to have a look at the .obj file, here it is: http://pastebin.com/PpG3vG5e

This is how I create the display list:

list = glGenLists (1);
glNewList (list, GL_COMPILE);
glBegin (GL_TRIANGLES);

for (i = 0; i < data.face_count; i++)
{
    // first vert
    normal[0][0] = (float)data.vertex_normal_list[data.face_list[i]->normal_index[0]]->e[0];
    normal[0][1] = (float)data.vertex_normal_list[data.face_list[i]->normal_index[0]]->e[1];
    normal[0][2] = (float)data.vertex_normal_list[data.face_list[i]->normal_index[0]]->e[2];
    tex[0][0] = (float)data.vertex_texture_list[data.face_list[i]->texture_index[0]]->e[0];
    tex[0][1] = (float)data.vertex_texture_list[data.face_list[i]->texture_index[0]]->e[1];
    tex[0][2] = (float)data.vertex_texture_list[data.face_list[i]->texture_index[0]]->e[2];
    vert[0][0] = (float)data.vertex_list[data.face_list[i]->vertex_index[0]]->e[0];
    vert[0][1] = (float)data.vertex_list[data.face_list[i]->vertex_index[0]]->e[1];
    vert[0][2] = (float)data.vertex_list[data.face_list[i]->vertex_index[0]]->e[2];

    // second vert
    normal[1][0] = (float)data.vertex_normal_list[data.face_list[i]->normal_index[1]]->e[0];
    normal[1][1] = (float)data.vertex_normal_list[data.face_list[i]->normal_index[1]]->e[1];
    normal[1][2] = (float)data.vertex_normal_list[data.face_list[i]->normal_index[1]]->e[2];
    tex[1][0] = (float)data.vertex_texture_list[data.face_list[i]->texture_index[1]]->e[0];
    tex[1][1] = (float)data.vertex_texture_list[data.face_list[i]->texture_index[1]]->e[1];
    tex[1][2] = (float)data.vertex_texture_list[data.face_list[i]->texture_index[1]]->e[2];
    vert[1][0] = (float)data.vertex_list[data.face_list[i]->vertex_index[1]]->e[0];
    vert[1][1] = (float)data.vertex_list[data.face_list[i]->vertex_index[1]]->e[1];
    vert[1][2] = (float)data.vertex_list[data.face_list[i]->vertex_index[1]]->e[2];

    // third vert
    normal[2][0] = (float)data.vertex_normal_list[data.face_list[i]->normal_index[2]]->e[0];
    normal[2][1] = (float)data.vertex_normal_list[data.face_list[i]->normal_index[2]]->e[1];
    normal[2][2] = (float)data.vertex_normal_list[data.face_list[i]->normal_index[2]]->e[2];
    tex[2][0] = (float)data.vertex_texture_list[data.face_list[i]->texture_index[2]]->e[0];
    tex[2][1] = (float)data.vertex_texture_list[data.face_list[i]->texture_index[2]]->e[1];
    tex[2][2] = (float)data.vertex_texture_list[data.face_list[i]->texture_index[2]]->e[2];
    vert[2][0] = (float)data.vertex_list[data.face_list[i]->vertex_index[2]]->e[0];
    vert[2][1] = (float)data.vertex_list[data.face_list[i]->vertex_index[2]]->e[1];
    vert[2][2] = (float)data.vertex_list[data.face_list[i]->vertex_index[2]]->e[2];

    for (j = 0; j < 3; j++)
    {
        glNormal3f (normal[j][0], normal[j][1], normal[j][2]);
        glTexCoord3f (tex[j][0], tex[j][1], tex[j][2]);
        glVertex3f (vert[j][0], vert[j][1], vert[j][2]);
    }
}

glEnd ();
glEndList ();

EDIT: I've tried things like:

glTranslatef (0, 0, 5);
glCallList (mesh);
glTranslatef (0, 0, 0);

but they don't work either :(

EDIT:

@datenwolf Here is the code I use to draw it:

Draw_Begin ();
Mdl_Draw (list, 0.0f, 0.0f, 0.0f);
Draw_End ();
1
A few things are possible: your mesh could be really small, your mesh could be completely inside of the clipping plane, or your display function is missing a glFlush().Derek
I don't think the mesh is really small since it has verticies like (31.6352 139.3443 145.9452). (I am doing no scaling either). Do I need a glFlush? I thought glCallLists then SwapBuffers would be sufficient. (EDIT: I added glFlush after glCallLists but still no mesh)Tom Tetlaw
If you are using double buffering, then you want to swap the buffers. See datenwolf's answer. He is right.Derek

1 Answers

3
votes

This

gluPerspective (45.0, (float)1024/(float)768, -9999, 9999);

is wrong. In a perspective projection both the near and the far plane distance must be of the same sign, i.e. both positive or both negative. Also the absolute value of the near plane must be smaller than the absolute value of the far plane. And the near plane distance must be nonzero. In mathematical notation:

sgn(near) = sgn(far) ^ 0 < |near| < |far|

Usually both near and far are chosen positive. Also as a rule of thumb the near clipping plane should be chosen as fer away as possible. The far plane can be placed at infinity (exploting some of the properties of homogenous matrices), but usually is placed as close as possible to max out depth buffer resolution.