ric*_*h.e 0 c++ iphone opengl-es-2.0
我在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());
Run Code Online (Sandbox Code Playgroud)
但我似乎无法使用常量属性写入颜色.这会在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
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么?你能只用常量顶点属性调用glDrawElements吗?
你告诉OpenGL使用VertexAttribArray,然后你不提供数组元素.因此,OpenGL将尝试读取既未分配也未正确填充的内存.一定要做
glDisableVertexAttribArray(ARRAYINDEX)
Run Code Online (Sandbox Code Playgroud)
当您不提供特定阵列的数据时.使用就好了glVertexAttrib3f().但它不是一个数组,因此您不需要启用数组来使用它.
| 归档时间: |
|
| 查看次数: |
504 次 |
| 最近记录: |