【发布时间】:2013-03-21 10:05:32
【问题描述】:
我一直在学习 OpenGL,并且能够使用三角形条创建成功的 2D 绘图系统。我编写了一个粒子生成器来测试几何体的批处理,一切正常,我能够在 iPhone 5 上以 60 fps 的速度渲染 30k+ 个顶点。我使用退化三角形连接粒子并立即绘制它们。我想要完成的是不使用退化三角形的批量渲染,因为这会将发送到 GPU 的数据量减少 1/3,这将是巨大的。
我正在尝试使用带有三角形的 glDrawElements 来使用以下代码绘制 2 个精灵
//the vertices for the square (2d)
GLfloat square[] = {
50, 50, //bottom left
100, 50, //bottom right
50, 100, //top left
100, 100, //top right
150, 200, //bottom left
200, 150, //bottom right
150, 200, //top left
200, 200 //top right
};
//texture coords
GLfloat tex[] = {
0,0,
1,0,
0,1,
1,1,
0,0,
1,0,
0,1,
1,1
};
GLubyte indices[] =
{
0,2,3,
0,3,1,
0,2,3,
0,3,1
};
//actual drawing code
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, square);
glVertexAttribPointer(ATTRIB_TEX, 2, GL_FLOAT, GL_FALSE, 0, tex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, image);
glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_BYTE, indices);
此代码可以毫无问题地绘制第一张图像,但第二张图像失真。我一直在网上寻找,但无法弄清楚如何使这项工作正常工作。
【问题讨论】:
标签: iphone ios opengl-es opengl-es-2.0