如何在 OpenGL ES 2.0 中创建彩色方形网格?

发布于 2024-10-01 03:20:09 字数 120 浏览 0 评论 0原文

使用 Open GL ES 2.0,我想创建一个大的正方形网格,其中每个正方形可以采用定义文件指定的某种颜色。所以这不是一个只有黑白方块的简单棋盘......
为了避免伪影,最好的方法是什么?

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

碍人泪离人颜 2024-10-08 03:20:09

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

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

因此,内存中的顶点数组将是:

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

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

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

使用 glDrawArrays(GL_TRIANGLES, ...) 进行一次绘制调用来绘制顶点数组。

There's nothing that will implicitly cause artifacts when drawing a grid of squares. There's no inherent z-fighting, depth, or transparency problems with the drawing as described in this question.

In the application, create a vertex array with two attributes (position, color) for each vertex. For each square in the grid you'll need 4 vertices. This will describe 2 independent triangles that make up each grid square. Avoid using triangle strips because you don't want the color attribute shared or interpolated between adjacent grid squares.

So your vertex array in memory will be:

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

Create a simple pass-through shader pair that sends the vertex color through as a varying to the fragment shader. The fragment color simply sets the output color to the value of the varying.

If you layout the grid positions from -1.0 through 1.0, you don't even need to add viewing transform uniforms or corresponding shader logic.

Make a single draw call to draw your vertex array with glDrawArrays(GL_TRIANGLES, ...).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文