glDrawElements,其索引应用于顶点和法线
当您有 2 个数组(一个用于法线,一个用于顶点)并使用顶点和法线之间交错的索引缓冲区时,是否可以使用 glDrawElements 方法。
示例:渲染立方体
// 8 of vertex coords
GLfloat vertices[] = {...};
// 6 of normal vectors
GLfloat normals[] = {...};
// 48 of indices (even are vertex-indices, odd are normal-indices)
GLubyte indices[] = {0,0,1,0,2,0,3,0,
0,1,3,1,4,1,5,1,
0,2,5,2,6,2,1,2,
1,3,6,3,7,3,2,3,
7,4,4,4,3,4,2,4,
4,5,7,5,6,5,5,5};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glNormalPointer(3, GL_FLOAT, 0, normals);
glDrawElements(GL_QUADS,...);//?see Question
Is it possible to use the glDrawElements method when you have lets say 2 arrays (one for Normals and one for Vertices) and use the Index-buffer interleaved between vertices and normals).
EXAMPLE: rendering a Cube
// 8 of vertex coords
GLfloat vertices[] = {...};
// 6 of normal vectors
GLfloat normals[] = {...};
// 48 of indices (even are vertex-indices, odd are normal-indices)
GLubyte indices[] = {0,0,1,0,2,0,3,0,
0,1,3,1,4,1,5,1,
0,2,5,2,6,2,1,2,
1,3,6,3,7,3,2,3,
7,4,4,4,3,4,2,4,
4,5,7,5,6,5,5,5};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glNormalPointer(3, GL_FLOAT, 0, normals);
glDrawElements(GL_QUADS,...);//?see Question
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
否,请参阅
glDrawElements 的文档 ()
。您只能通过使用交错数据(而不是交错索引)来实现“交错”,或者通过
glInterleavedArrays
(参见 这里):或via:
如你所见,
glInterleavedArrays()
只是周围的一些糖glInterleavedArrays() 和朋友们。
No, see the documentation of
glDrawElements()
.You can only achieve 'interleaving' by using interleaved data (not interleaved indices), either via
glInterleavedArrays
(see here):or via:
as you can see,
glInterleavedArrays()
is just some sugar aroundglInterleavedArrays()
and friends.