3

Using Open GL ES 2.0, I want to create a large grid of squares, where each square can take a certain color as specified by a definition file. So this is not a simple checkerboard of only black and white squares...
What is the best way to do this in order to avoid artifacts?

Thanks in advance

4

1 回答 1

2

在绘制正方形网格时,没有什么会隐含地导致伪影。如本问题所述,绘图不存在固有的 z 冲突、深度或透明度问题。

在应用程序中,为每个顶点创建一个具有两个属性(位置、颜色)的顶点数组。对于网格中的每个正方形,您需要 4 个顶点。这将描述构成每个网格正方形的 2 个独立三角形。避免使用三角形条,因为您不希望在相邻网格方块之间共享或插值颜色属性。

所以你在内存中的顶点数组将是:

square0Pos0
color0
square0Pos1
color0
square0Pos2
color0
square0Pos3
color0
square1Pos0
color1
...

创建一个简单的传递着色器对,将顶点颜色作为变量发送到片段着色器。片段颜色只是将输出颜色设置为变量的值。

如果您从 -1.0 到 1.0 布局网格位置,您甚至不需要添加查看变换制服或相应的着色器逻辑。

进行一次绘图调用以使用glDrawArrays(GL_TRIANGLES, ...).

于 2010-11-10T17:58:39.773 回答