[英]C++ glDrawElements Array as Parameter EXC_BAD_ACCESS Error
I got an EXC_BAD_ACCESS Error at the glDrawElements call. 在glDrawElements调用中出现EXC_BAD_ACCESS错误。 I think there is something wrong with the array passed to the Shape constructor.
我认为传递给Shape构造函数的数组有问题。 What could be the problem here.
这可能是问题所在。
main.cpp main.cpp
static const GLfloat cube_vertices[] = {
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
};
static const GLushort indices[] = {
0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1
};
cube = new Shape(shader, cube_vertices, 3 * 8, indices, 14);
Shape.h 形状
const GLushort *indices;
Shape.cpp Shape.cpp
Shape::Shape(Shader* cshader, const GLfloat *vertices, int size, const GLushort *cindices, int indSize) : {
indices = cindices;
}
Render method 渲染方法
glDrawElements(GL_TRIANGLES, 14, GL_UNSIGNED_SHORT, indices);
As I said here is the problem. 正如我所说的,这是问题所在。 What am I doing wrong?
我究竟做错了什么? Thanks.
谢谢。
If you are passing GL_TRIANGLES then your index buffer length should be a multiple of 3 (ie every 3 index values forms one triangle). 如果要传递GL_TRIANGLES,则索引缓冲区长度应为3的倍数(即,每3个索引值形成一个三角形)。
Other than that what you have posted looks OK - so we'll need a more complete test case to be able to help. 除此之外,您发布的内容看起来还不错-因此,我们需要一个更完整的测试用例才能提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.