glDrawElements,其索引应用于顶点和法线

发布于 2024-09-10 04:10:08 字数 721 浏览 1 评论 0原文

当您有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人海汹涌 2024-09-17 04:10:08

否,请参阅 glDrawElements 的文档 ()

您只能通过使用交错数据(而不是交错索引)来实现“交错”,或者通过 glInterleavedArrays (参见 这里):

float data[] = { v1, v2, v3, n1, n2, n3 .... };
glInterleavedArrays(GL_N3F_V3F, 0, data);
glDrawElements(...);

或via:

float data[] = { v1, v2, v3, n1, n2, n3 };
glVertexPointer(3, GL_FLOAT, sizeof(float) * 3, data);
glNormalPointer(3, GL_FLOAT, sizeof(float) * 3, data + sizeof(float) * 3);
glDrawElements(...);

如你所见,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):

float data[] = { v1, v2, v3, n1, n2, n3 .... };
glInterleavedArrays(GL_N3F_V3F, 0, data);
glDrawElements(...);

or via:

float data[] = { v1, v2, v3, n1, n2, n3 };
glVertexPointer(3, GL_FLOAT, sizeof(float) * 3, data);
glNormalPointer(3, GL_FLOAT, sizeof(float) * 3, data + sizeof(float) * 3);
glDrawElements(...);

as you can see, glInterleavedArrays() is just some sugar around glInterleavedArrays() and friends.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文