PDA

View Full Version : Why my mesh is display partly?



ddguan
07-27-2014, 08:46 PM
Dear All:
I want to display a facial mesh model. I refer to the codes of OpenGL SuperBible, the codes use GLBatch to draw the mesh, but it only display parts of whole mesh, why?
1378
this is the whole mesh model, and i draw it using glBegin(GL_TRIANGLES); glColor4f(); glVertex3f();.... glEnd();
However, when i use GLBatch to draw, the result is like this:
1379

my code is:
void SetupRC()
{
....
//////////////////////////////////////////////////////////////

//Copy the vertex position and color of each triangle

int i;
for(i=0;i<106466;i++)
{
mVertex[i*9+0]=(m_vertex[m_face[i].vertex1].x-minx)/(maxx-minx) ;
mVertex[i*9+1]=(m_vertex[m_face[i].vertex1].y-miny)/(maxy-miny);
mVertex[i*9+2]=(m_vertex[m_face[i].vertex1].z-minz)/(maxz-minz) ;
mVertex[i*9+3]=(m_vertex[m_face[i].vertex2].x-minx)/(maxx-minx) ;
mVertex[i*9+4]=(m_vertex[m_face[i].vertex2].y-miny)/(maxy-miny);
mVertex[i*9+5]=(m_vertex[m_face[i].vertex2].z-minz)/(maxz-minz) ;
mVertex[i*9+6]=(m_vertex[m_face[i].vertex3].x-minx)/(maxx-minx) ;
mVertex[i*9+7]=(m_vertex[m_face[i].vertex3].y-miny)/(maxy-miny);
mVertex[i*9+8]=(m_vertex[m_face[i].vertex3].z-minz)/(maxz-minz) ;
}
for(i=0;i<106466;i++)
{
mColor[i*12+0]=(float)m_texture[m_face[i ].vertex1].red/255;
mColor[i*12+1]=(float)m_texture[m_face[i ].vertex1].green/255;
mColor[i*12+2]=(float)m_texture[m_face[i ].vertex1].blue/255;
mColor[i*12+3]=1.0f;

mColor[i*12+4]=(float)m_texture[m_face[i ].vertex2].red/255;
mColor[i*12+5]=(float)m_texture[m_face[i ].vertex2].green/255;
mColor[i*12+6]=(float)m_texture[m_face[i ].vertex2].blue/255;
mColor[i*12+7]=1.0f;

mColor[i*12+8]=(float)m_texture[m_face[i ].vertex3].red/255;
mColor[i*12+9]=(float)m_texture[m_face[i ].vertex3].green/255;
mColor[i*12+10]=(float)m_texture[m_face[i ].vertex3].blue/255;
mColor[i*12+11]=1.0f;
}
PlyBatch.Begin(GL_TRIANGLES,106466);
PlyBatch.CopyVertexData3f(mVertex);
PlyBatch.CopyColorData4f(mColor);
PlyBatch.End();
//////////////////////////////////////////////////////////////
//Create the GLBatch
PlyBatch.Begin(GL_TRIANGLES,106466);
PlyBatch.CopyVertexData3f(mVertex);
PlyBatch.CopyColorData4f(mColor);
PlyBatch.End();
....
}

void RenderScene()
{
.....
PlyBatch.Draw();
.....
}

Dan Bartlett
07-27-2014, 10:17 PM
Because you need to provide the number of vertices to PlyBatch.Begin(), so 106466*3 rather than the number of triangles. Currently it is only drawing 1/3 of the mesh.

ddguan
07-28-2014, 12:15 AM
[QUOTE=Dan Bartlett;1260712]Because you need to provide the number of vertices to PlyBatch.Begin(), so 106466*3 rather than the number of triangles. Currently it is only drawing 1/3 of the mesh.[/QUOTE
You are right,i misunderstand the input of GLBatch.Begin().Thank you!