# Thread: [solved] 3D Object visualisation problem

1. ## [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

Code :
```/* 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:

Code :
```void GL_MAILLAGE::InitGL()
{
ReinitGL();
glMatrixMode(GL_MODELVIEW);
}```
My OpenGL Reinit (when window is resized etc..)

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

glMatrixMode(GL_PROJECTION);

// ...
// 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.

2. ## Re: [solved] 3D Object visualisation problem

I think your problem are discussed here:
http://www.opengl.org/resources/faq/...ygonoffset.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.

3. ## Re: [solved] 3D Object visualisation problem

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

Thank you!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•