我有一个错误,花了我相当长的时间来修复。在我评论以下行之前,我不断收到 EXC_BAD_ACCESS 和对 memmove 错误的引用,没有任何进一步的描述:
[自加载着色器];
glGenVertexArraysOES(1, &_vao);
glBindVertexArrayOES(_vao);
// Vertex Buffer
glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(ATTRIB_VERTEX);
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
glEnableVertexAttribArray(ATTRIB_TEXTURE);
glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*) (sizeof(float) * 7));
// Index Buffer
glGenBuffers(1, &_indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER,0);
////////// COMMENTED THIS ONE //////////////
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);//
////////////////////////////////////////////
glBindVertexArrayOES(0);
我认为将缓冲区绑定到 0 意味着取消绑定它,所以我真的无法理解这将如何使我的应用程序崩溃。
谢谢提供信息!我只是不关心这个问题......
我的结构:
const Vertex Vertices[4] = {
{{0.75, -1, 0}, {1, 0, 0, 1}, {0.125, 0.833496}},
{{0.75, 1, 0}, {0, 1, 0, 1}, {0.125, 1}},
{{-0.75, 1, 0}, {0, 0, 1, 1}, {0, 1}},
{{-0.75, -1, 0}, {0, 0, 0, 1}, {0, 0.833496}},
};
const GLushort Indices[6] =
{
0, 1, 2,
2, 3, 0
};