PDA

View Full Version : Display triangular mesh



Geof_R
01-17-2010, 02:26 PM
Hi,

I try to display few triangular mesh in a QT 3D view. My first triangular mesh is a big closed surface (green on attached pictures). The oppacity of this surface is not complete to be able to see others triangular meshes inside the green one.

Attached pictures
http://w3.gel.ulaval.ca/~geris2/ForumImage/MissingTriangles.jpg

http://w3.gel.ulaval.ca/~geris2/ForumImage/DissapearingTrinagles.jpg

I have two questions.
First one, why on the first surface ( green ) I see the triangles? Is it possible to obtain a uniforme surface without triangles shapes.

Second questions : On the red triangular meshes, when I rotate the view, some triangles seem to dissapear and create an hole in the mesh.

This is the way I display each triangular mesh in the view :
for ( size_t iMesh=0; iMesh<m_MeshList.size(); ++iMesh )
{
if ( iMesh == 0)
glColor4f ( 0, 255, 0, 0.1 );
else
glColor4f ( 255, 0, 0, 1 );

// Create vertices and facets list
//db
int VSize = m_MeshList[iMesh]->GetNbVertice()*3;
int FSize = m_MeshList[iMesh]->GetNbFacet()*3;
//db

GLfloat *vertices = new GLfloat[m_MeshList[iMesh]->GetNbVertice()*3 ];
GLubyte *indices = new GLubyte[m_MeshList[iMesh]->GetNbFacet()*3 ];
size_t iValue=0;
for ( size_t iVertices=0; iVertices<m_MeshList[iMesh]->GetNbVertice(); ++iVertices )
{
vertices[iValue] = m_MeshList[iMesh]->GetVertices()[iVertices].x();
++iValue;
vertices[iValue] = m_MeshList[iMesh]->GetVertices()[iVertices].y();
++iValue;
vertices[iValue] = m_MeshList[iMesh]->GetVertices()[iVertices].z();
++iValue;
}

iValue=0;
for ( size_t iFacet=0; iFacet<m_MeshList[iMesh]->GetNbFacet(); ++iFacet )
{
indices[iValue] = m_MeshList[iMesh]->GetFacets()[iFacet].x();
++iValue;
indices[iValue] = m_MeshList[iMesh]->GetFacets()[iFacet].y();
++iValue;
indices[iValue] = m_MeshList[iMesh]->GetFacets()[iFacet].z();
++iValue;
}

// activate and specify pointer to vertex array
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);

//glDrawElements(GL_TRIANGLE_STRIP, 12, GL_UNSIGNED_BYTE, indices);
glDrawElements(GL_TRIANGLES, m_MeshList[iMesh]->GetNbVertice(), GL_UNSIGNED_BYTE, indices);

// deactivate vertex arrays after drawing
glDisableClientState(GL_VERTEX_ARRAY);

kowal
01-17-2010, 04:04 PM
First one, why on the first surface ( green ) I see the triangles? Is it possible to obtain a uniforme surface without triangles shapes.


No. Graphics hardware can only draw points, lines, triangles, quads and polygons (only convex).
(Since GL 3.0 quads and polygons are deprecated (but still supported))

There are another primitives such as triangle fans or triangle strips, but they are bulit from basic shapes: triangles.

(Just google 'OpenGL primitives', and You will find all about them in first 5 links)

You can make your surface to look as it was smooth (by using lighting, shaders, and many other tricks), but it is always bulit from polygons.


Second questions : On the red triangular meshes, when I rotate the view, some triangles seem to dissapear and create an hole in the mesh.


yes, that is backface culling,
if You don't want it, disable it:


glDisable( GL_CULL_FACE );