请教OpenGl ,同样的数据为什么glBegin(GL_TRIANGLES)和glDrawArrays()结果显示就不一样呢?
调用中需要使用到的数据结构:
typedef struct
{
float x, /*The x component of the vertex position*/
y, /*The y component of the vertex position*/
z; /*The z component of the vertex position*/
} ObjVertex;
typedef struct
{
float x, /*The x component of the normal vector*/
y, /*The y component of the normal vector*/
z; /*The z component of the normal vector*/
} ObjNormal;
typedef struct
{
float u, /*The u parametric texturing co-ordinate*/
v; /*The v parametric texturing co-ordinate*/
} ObjTexCoord;
typedef struct
{
unsigned int m_aVertexIndices[3],
m_aNormalIndices[3],
m_aTexCoordIndicies[3];
} ObjFace;
typedef struct _ObjMesh
{
ObjVertex*m_aVertexArray;
ObjNormal*m_aNormalArray;
ObjTexCoord*m_aTexCoordArray;
ObjFace *m_aFaces;
unsigned int*m_aIndices;
unsigned int m_iNumberOfVertices,
m_iNumberOfNormals,
m_iNumberOfTexCoords,
m_iNumberOfFaces;
} ObjMesh;
(1)使用glBegin()语句:
glBegin(GL_TRIANGLES);
for(i=0;i<pMesh->m_iNumberOfFaces;i++)
{
unsigned int j;
ObjFace *pf = &pMesh->m_aFaces[i];
/*
**Draw the polygons with Normals only
*/
for(j=0;j<3;j++)
{
glNormal3f( pMesh->m_aNormalArray[ pf->m_aNormalIndices[j] ].x,
pMesh->m_aNormalArray[ pf->m_aNormalIndices[j] ].y,
pMesh->m_aNormalArray[ pf->m_aNormalIndices[j] ].z);
glVertex3f( pMesh->m_aVertexArray[ pf->m_aVertexIndices[j] ].x,
pMesh->m_aVertexArray[ pf->m_aVertexIndices[j] ].y,
pMesh->m_aVertexArray[ pf->m_aVertexIndices[j] ].z);
}
}
glEnd();
(2)使用glDrawArrays()语句调用:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,pMesh->m_aVertexArray);
if(pMesh->m_aNormalArray)
{
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT,0,pMesh->m_aNormalArray);
}
if(pMesh->m_aTexCoordArray)
{
glTexCoordPointer(2,GL_FLOAT,0,pMesh->m_aTexCoordArray);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
glDrawArrays(GL_TRIANGLES,0,pMesh->m_iNumberOfFaces);
相同的数据*pMesh,程序运行调用(1)和(2)的显示结果居然不一样。
求解???????
[解决办法]
glDrawArrays对顶点的排列顺序有要求的。具体找个例子看看。
[解决办法]
我错了..原来是发了三次..