[solved] 3D Object visualisation problem

Hello, I am drawing tetrahedrons (4 triangular faces polygons) with OpenGL.

There is a huge visualisation problem (the drawing itself and the coordinates are okay though)

You can see a video sample here

I want to draw the tetrahedrons and also their borders.

So here is what I do

/* Draw full tetrahedrons */
                glColor3d(m_RGBRender[0],m_RGBRender[1],m_RGBRender[2]);          
                glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
                glBegin(GL_TRIANGLES);
                for (pos = tetras.begin() ; pos + 4 < tetras.end() ; pos+=4) {
                                         glVertex3d((*pos)->get_x(),(*pos)->get_y(),(*pos)->get_z());
                     glVertex3d((*(pos+3))->get_x(),(*(pos+3))->get_y(),(*(pos+3))->get_z());
                     glVertex3d((*(pos+2))->get_x(),(*(pos+2))->get_y(),(*(pos+2))->get_z());
 
                     glVertex3d((*pos)->get_x(),(*pos)->get_y(),(*pos)->get_z());
                     glVertex3d((*(pos+1))->get_x(),(*(pos+1))->get_y(),(*(pos+1))->get_z());
                     glVertex3d((*(pos+2))->get_x(),(*(pos+2))->get_y(),(*(pos+2))->get_z());
 
                     glVertex3d((*pos)->get_x(),(*pos)->get_y(),(*pos)->get_z());
                     glVertex3d((*(pos+1))->get_x(),(*(pos+1))->get_y(),(*(pos+1))->get_z());
                     glVertex3d((*(pos+3))->get_x(),(*(pos+3))->get_y(),(*(pos+3))->get_z());
 
                     glVertex3d((*(pos+1))->get_x(),(*(pos+1))->get_y(),(*(pos+1))->get_z());
                     glVertex3d((*(pos+2))->get_x(),(*(pos+2))->get_y(),(*(pos+2))->get_z());
                     glVertex3d((*(pos+3))->get_x(),(*(pos+3))->get_y(),(*(pos+3))->get_z());
 
                }     
                glEnd();
 
 
   /* Draw borders of the tetrahedrons */
                glColor3d(m_RGBBordersW[0],m_RGBBordersW[1],m_RGBBordersW[2]);          
                glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
                glBegin(GL_TRIANGLES);
                for (pos = tetras.begin() ; pos + 4 < tetras.end() ; pos+=4) {
                     glVertex3d((*pos)->get_x(),(*pos)->get_y(),(*pos)->get_z());
                     glVertex3d((*(pos+3))->get_x(),(*(pos+3))->get_y(),(*(pos+3))->get_z());
                     glVertex3d((*(pos+2))->get_x(),(*(pos+2))->get_y(),(*(pos+2))->get_z());
 
                     glVertex3d((*pos)->get_x(),(*pos)->get_y(),(*pos)->get_z());
                     glVertex3d((*(pos+1))->get_x(),(*(pos+1))->get_y(),(*(pos+1))->get_z());
                     glVertex3d((*(pos+2))->get_x(),(*(pos+2))->get_y(),(*(pos+2))->get_z());
 
                     glVertex3d((*pos)->get_x(),(*pos)->get_y(),(*pos)->get_z());
                     glVertex3d((*(pos+1))->get_x(),(*(pos+1))->get_y(),(*(pos+1))->get_z());
                     glVertex3d((*(pos+3))->get_x(),(*(pos+3))->get_y(),(*(pos+3))->get_z());
 
                     glVertex3d((*(pos+1))->get_x(),(*(pos+1))->get_y(),(*(pos+1))->get_z());
                     glVertex3d((*(pos+2))->get_x(),(*(pos+2))->get_y(),(*(pos+2))->get_z());
                     glVertex3d((*(pos+3))->get_x(),(*(pos+3))->get_y(),(*(pos+3))->get_z());
 
                }     
                glEnd();

My OpenGl Init:

void GL_MAILLAGE::InitGL() 
{  
    ReinitGL();    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

My OpenGL Reinit (when window is resized etc…)

void GL_MAILLAGE::ReinitGL(double dx, double dy) 
{
    glViewport(0, 0, m_glCanvasSize.GetWidth(), m_glCanvasSize.GetHeight()); 
    glEnable (GL_DEPTH_TEST);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    // ...
    // other stuff for rotations/translations

    glOrtho(xmin,xmax,ymin,ymax,zmin,zmax);  
}

Can anyone see something I’m missing, I am in desperate need of help I don’t know what to do anymore.

Thank you very much for reading this.

I think your problem are discussed here:
http://www.opengl.org/resources/faq/technical/polygonoffset.htm

An example of the solution:
http://www.opengl.org/resources/faq/technical/pgonoff.c

Try to use this in the OpenGL initialization:
glEnable (GL_POLYGON_OFFSET_FILL);
glPolygonOffset (1., 1.);

Best regards,
Simone Betti.

Thank you very, very much. I was already playing with the polygonOffset but obviously not at the correct place :slight_smile:

Thank you!