amhood

08-15-2004, 12:28 AM

hi, i am currently trying to render a mesh model, i use the float pointer *pVertex to point to the triangle vertex array, and the GLuint pointer *pIndex to point to the triangle index array, the rendering code below works quite well:

glBegin(GL_TRIANGLES);

for (int i=0; i [LESS THAN] iTriangleCount; i++)

{

GLuint index1 = pIndex[3*i];

GLuint index2 = pIndex[3*i+1];

GLuint index3 = pIndex[3*i+2];

glVertex3f(pVertex[5*index1],

pVertex[5*index1+1],

pVertex[5*index1+2]);

glVertex3f(pVertex[5*index2],

pVertex[5*index2+1],

pVertex[5*index2+2]);

glVertex3f(pVertex[5*index3],

pVertex[5*index3+1],

pVertex[5*index3+2]);

}

glEnd();

One thing to explain is that for each vertex, 2 floating numbers are stored after the 3 coordinate values, that's why there is a "5" in the code.

However, when I use the code below, rendering results turn out to be a mess:

glVertexPointer(3, GL_FLOAT, 2*sizeof(GLfloat),

pVertex);

glEnableClientState(GL_VERTEX_ARRAY);

glDrawElements(GL_TRIANGLES,

3 * iTriangleCount,

GL_UNSIGNED_INT, pIndex);

glDisableClientState(GL_VERTEX_ARRAY);

Could anybody tell me what the problem is? Thanks so much!!

glBegin(GL_TRIANGLES);

for (int i=0; i [LESS THAN] iTriangleCount; i++)

{

GLuint index1 = pIndex[3*i];

GLuint index2 = pIndex[3*i+1];

GLuint index3 = pIndex[3*i+2];

glVertex3f(pVertex[5*index1],

pVertex[5*index1+1],

pVertex[5*index1+2]);

glVertex3f(pVertex[5*index2],

pVertex[5*index2+1],

pVertex[5*index2+2]);

glVertex3f(pVertex[5*index3],

pVertex[5*index3+1],

pVertex[5*index3+2]);

}

glEnd();

One thing to explain is that for each vertex, 2 floating numbers are stored after the 3 coordinate values, that's why there is a "5" in the code.

However, when I use the code below, rendering results turn out to be a mess:

glVertexPointer(3, GL_FLOAT, 2*sizeof(GLfloat),

pVertex);

glEnableClientState(GL_VERTEX_ARRAY);

glDrawElements(GL_TRIANGLES,

3 * iTriangleCount,

GL_UNSIGNED_INT, pIndex);

glDisableClientState(GL_VERTEX_ARRAY);

Could anybody tell me what the problem is? Thanks so much!!