glDrawElements 无法在 iPhone 上运行,但 glDrawArrays 可以运行
我尝试将我的 OpenGL 应用程序转换为 OpenGL ES。我在 Mac 上以这种方式绘制元素:
glUseProgram(m_program);
// Update uniform value.
glUniform4f(uniforms[UNIFORM_COLOR], (GLfloat)color[0], (GLfloat)color[1], (GLfloat)color[2], (GLfloat)color[3]);
// Update attribute values.
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, data);
glEnableVertexAttribArray(ATTRIB_VERTEX);
// Validate program before drawing. This is a good check, but only really necessary in a debug build.
// DEBUG macro must be defined in your debug configurations if that's not already the case.
glDrawElements(GL_TRIANGLE_STRIP, count, GL_UNSIGNED_INT, indices);
一切正常,但当我尝试在 iPhone 4(iOS 4.2 和 XCode 3.2.5)上以这种方式绘制时,我什么也看不到。奇怪的是,所有计算都已完成,当我尝试用 glDrawArrays 绘制它时,屏幕上会显示一些内容(但顶点未按正确的顺序渲染):
glUseProgram(m_program);
// Update uniform value.
glUniform4f(uniforms[UNIFORM_COLOR], (GLfloat)color[0], (GLfloat)color[1], (GLfloat)color[2], (GLfloat)color[3]);
// Update attribute values.
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, data);
glEnableVertexAttribArray(ATTRIB_VERTEX);
glDrawArrays(GL_TRIANGLE_STRIP, 0, count);
我错过了什么吗?
I have tried to convert my OpenGL application to OpenGL ES. I am drawing elements on Mac this way:
glUseProgram(m_program);
// Update uniform value.
glUniform4f(uniforms[UNIFORM_COLOR], (GLfloat)color[0], (GLfloat)color[1], (GLfloat)color[2], (GLfloat)color[3]);
// Update attribute values.
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, data);
glEnableVertexAttribArray(ATTRIB_VERTEX);
// Validate program before drawing. This is a good check, but only really necessary in a debug build.
// DEBUG macro must be defined in your debug configurations if that's not already the case.
glDrawElements(GL_TRIANGLE_STRIP, count, GL_UNSIGNED_INT, indices);
Everything is OK but when I try to draw this way on iPhone 4 (iOS 4.2 and XCode 3.2.5) I can see nothing. Strange thing is all computations is done and when I try to draw it with glDrawArrays, something is shown on screen (but vertexes are not rendered in right order):
glUseProgram(m_program);
// Update uniform value.
glUniform4f(uniforms[UNIFORM_COLOR], (GLfloat)color[0], (GLfloat)color[1], (GLfloat)color[2], (GLfloat)color[3]);
// Update attribute values.
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, data);
glEnableVertexAttribArray(ATTRIB_VERTEX);
glDrawArrays(GL_TRIANGLE_STRIP, 0, count);
Am I missing anything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
iPhone 上不允许使用 GL_UNSIGNED_INT 作为 glDrawElements 索引数组的类型。我必须使用 GL_UNSIGNED_BYTE 或 GL_UNSIGNED_SHORT
GL_UNSIGNED_INT as type of glDrawElements indices array is not allowed on iPhone. I have to use GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT
在 Apple 开发者论坛上,我提示可以使用 OES_element_index_uint 扩展在 iPhone 上使用 GL_UNSGNED_INT
On the Apple Developers forum I have go hint that GL_UNSGNED_INT can be used on iPhone using OES_element_index_uint ectension