【发布时间】:2012-03-13 12:40:19
【问题描述】:
我在 glDrawArrays 上看到了很多与 EXC_BAD_ACCESS 信号相关的其他帖子,但没有一个完全符合我的问题,所以就这样吧。
以下代码有效:
glEnableVertexAttribArray(mAttributes.position);
glEnableVertexAttribArray(mAttributes.color);
GLsizei stride = sizeof(Vertex);
const GLvoid* pPos = &mVertices2[0].mPos.x;
const GLvoid* pColors = &mVertices2[0].mColor.r;
glVertexAttribPointer(mAttributes.position, 2, GL_FLOAT, GL_FALSE, stride, pPos);
glVertexAttribPointer(mAttributes.color, 3, GL_FLOAT, GL_FALSE, stride, pColors);
glDrawArrays(GL_LINE_STRIP, 0, mVertices2.size());
但我似乎无法使用常量属性写入颜色。这会在 glDrawArrays 上崩溃:
glEnableVertexAttribArray(mAttributes.position);
glEnableVertexAttribArray(mAttributes.color);
glVertexAttribPointer(mAttributes.position, 2, GL_FLOAT, GL_FALSE, stride, pPos);
glVertexAttrib3f(mAttributes.color, 1.0f, 0.0f, 0.0f);
glDrawArrays(GL_LINE_STRIP, 0, mVertices2.size()); // <-- EXC_BAD_ACCESS because of the line above
有人知道为什么吗?你能不能只用glDrawElements的常量顶点属性调用?
【问题讨论】:
标签: iphone c++ opengl-es-2.0