简体   繁体   English

绘制大量正方形的最快方法?

[英]Fastest way to draw a ton of squares?

I have a collection of Square objects in a list called squares. 我在称为Square的列表中有一个Square对象集合。 I iterate over the list and draw each square individually, I'm wondering if there is a faster way to do this? 我遍历列表并分别绘制每个正方形,我想知道是否有更快的方法? I don't think GL_QUAD will work because that fills in the square when I just want the outline. 我认为GL_QUAD不起作用,因为当我只需要轮廓时,它会填满正方形。

Here's my code 这是我的代码

    for sq in squares:
            x1, y1 = sq.point
            x2, y2 = x1 + sq.length - 1, y1 + sq.length - 1
            batch.add(2, pyglet.gl.GL_LINES, None, ('v2i', (x1, y1, x1, y2)))
            batch.add(2, pyglet.gl.GL_LINES, None, ('v2i', (x1, y1, x2, y1)))
            batch.add(2, pyglet.gl.GL_LINES, None, ('v2i', (x2, y2, x1, y2)))
            batch.add(2, pyglet.gl.GL_LINES, None, ('v2i', (x2, y2, x2, y1)))

    batch.draw()

(x1,y1) would be the bottom left point of the square and (x2,y2) is the top right. (x1,y1)是正方形的左下角,而(x2,y2)是右上角。

In OpenGL you can avoid polygon filling by calling: 在OpenGL中,您可以通过调用以下命令来避免填充多边形:

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

To get filled polygons again use: 要再次获得填充的多边形,请使用:

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

This way, you could use quads or 2 triangles. 这样,您可以使用四边形或2个三角形。 Using this(glPolygonMode) and vertexs arrays should greatly improve performance. 使用this(glPolygonMode)和顶点数组应该可以大大提高性能。

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

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