如何绘制没有索引的立方体?OpenGL ES 2.0
我想绘制没有索引并使用 VBO 的立方体。我在互联网上找不到任何内容(教程,示例)。 我尝试过:
const GLfloat Vertices[] = {
-1.0f, -1.0f, 1.0f, //Vertex 0
1.0f, -1.0f, 1.0f, //v1
-1.0f, 1.0f, 1.0f, //v2
1.0f, 1.0f, 1.0f, //v3
1.0f, -1.0f, 1.0f, //...
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
};
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 24);
但事实证明有些奇怪的东西,但不是立方体
I want to draw cube without indices and using VBO. I can't find anything in internet(tutorials,examples).
What I tried:
const GLfloat Vertices[] = {
-1.0f, -1.0f, 1.0f, //Vertex 0
1.0f, -1.0f, 1.0f, //v1
-1.0f, 1.0f, 1.0f, //v2
1.0f, 1.0f, 1.0f, //v3
1.0f, -1.0f, 1.0f, //...
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
};
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 24);
But it turns out that something strange, but not the cube
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先检查您的 glDrawPrimatives 调用,确保您使用 GL_QUADS 作为绘制模式。其他任何事情都会产生奇怪的结果。
不过你的顶点很好。它们的顺序正确且位置正确。
编辑:由于您不能使用四边形,因此您必须单独定义每个三角形,您的第一个块将如下所示:
不过,我强烈建议使用索引,如果您保留与定义相同的顶点缓冲区,则可以设置你的索引是这样的:
First check in your glDrawPrimatives call,that you're using GL_QUADS as your draw mode. Anything else will give weird results.
You vertices are fine though. They're in the correct order and in the correct positions.
EDIT: Since you can't use quads, you will have to define each triangle individually, your first block will look like this:
I would highly suggest using indices though, if you keep the same vertex buffer as you defined, you can set up your indices like this: