请教OpenGl ,同样的数据为什么glBegin(GL_TRIANGLES)和glDrawArrays()结果显示就不一样呢?

hellobabyworld 2011-08-31 10:57:01
调用中需要使用到的数据结构:
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)的显示结果居然不一样。
求解???????
...全文
691 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ahxzb54 2012-05-09
  • 打赏
  • 举报
回复
哥们,这个问题解决了吗?
仙度瑞城 2011-08-31
  • 打赏
  • 举报
回复
我错了..原来是发了三次..
ryfdizuo 2011-08-31
  • 打赏
  • 举报
回复
glDrawArrays对顶点的排列顺序有要求的。具体找个例子看看。

64,651

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧