简体   繁体   English

iPhone opengl es glDrawElements问题

[英]iphone opengl es glDrawElements issue

I'm quite new to opengl es so I'm wondering if it is possible to use the glDrawElements function to draw two separate squares(I actually want to draw more than two, but for learning I will create only two) ? 我是opengl es的新手,所以我想知道是否可以使用glDrawElements函数绘制两个单独的正方形(我实际上想绘制两个以上的正方形,但是为了学习,我只会创建两个)。

the vertex array looks like this: 顶点数组如下所示:

CGFloat array[] = CGFloat数组[] =

{ 0.2, 0.4, 0.2, 0.2, 0.4, 0.2, 0.4, 0.4, {0.2,0.4,0.2,0.2,0.4,0.2,0.4,0.4,

0.8, 1.0, 0.8, 0.8, 1.0, 0.8, 1.0, 1.0, }; 0.8、1.0、0.8、0.8、1.0、0.8、1.0、1.0,};

Thanks a lot for your attention ! 非常感谢您的关注!

You can do this by using an array of indices with your vertices, or by using degenerate triangles between your squares. 您可以通过在顶点上使用索引数组或在正方形之间使用退化三角形来实现此目的。 An index array will let you specify what vertex is connected to what, and makes it easy to create many disconnected objects. 索引数组将使您可以指定将什么顶点连接到什么顶点,并使创建许多断开连接的对象变得容易。 For an example, you can look at the source code to my application Molecules , where I render many disconnected atoms and bonds all within the same indexed array (indexed vertex buffer object, really). 例如,您可以查看我的应用程序Molecules的源代码,在这里我渲染了许多断开的原子并将所有键绑定在同一索引数组(实际上是索引顶点缓冲区对象)内。 The iPhone graphics hardware is optimized for strip-ordered indexed triangles . iPhone图形硬件针对条形有序索引三角形进行了优化

As David points out, if you still wish to use triangle strips for your squares, you can connect them simply by creating an extra degenerate triangle between your two squares that has a side composed of the same vertex repeated twice, with the third vertex being the starting point of your second square. 正如David指出的那样,如果您仍然希望对正方形使用三角带,则可以通过在两个正方形之间创建一个额外的退化三角形来简化它们的连接,该三角形的边由相同的顶点重复两次,第三个顶点为您第二个方块的起点。 If you were to draw it out, it would look like a line between your two squares. 如果要绘制出来,它看起来就像是两个正方形之间的一条线。 Modern GPUs are pretty efficient at stripping out these degenerate triangles. 现代GPU在去除这些退化三角形方面非常有效。

because you're using triangle strips, you can't just do this in the obvious way, because you'll draw some extra triangles in between your two squares. 因为您使用的是三角形条纹,所以不能仅仅以明显的方式进行操作,因为您将在两个正方形之间绘制一些额外的三角形。

Here are a couple of articles about how to get around this by using extra invisible triangles: 以下是几篇有关如何通过使用额外的不可见三角形来解决此问题的文章:

http://www.gamedev.net/reference/articles/article1871.asp http://en.wikipedia.org/wiki/Triangle_strip http://www.gamedev.net/reference/articles/article1871.asp http://en.wikipedia.org/wiki/Triangle_strip

if you're not drawing a huge number of squares, you might just want to stick with separate short glDrawElements calls and avoid having to think about all this. 如果您不绘制大量正方形,则可能只想坚持使用单独的简短glDrawElements调用,而不必考虑所有这些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM