PDA

View Full Version : [solved] 3D Object visualisation problem

Vincent Dumont
05-11-2006, 01:19 PM
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 (http://magwa.ca/vincent/tetra.avi)

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);
}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);

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

05-12-2006, 02:07 AM
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.

Vincent Dumont
05-12-2006, 07:55 AM
Thank you very, very much. I was already playing with the polygonOffset but obviously not at the correct place :)

Thank you!