有什么方法可以让一排瓷砖与 GL_QUAD_STRIP 一起使用吗?

发布于 2024-12-02 23:31:18 字数 336 浏览 2 评论 0原文

如果我想为游戏绘制一行 2D 方形图块,显而易见的方法是使用 GL_QUADS 并为每个图块指定 4 个顶点和纹理坐标。但由于这是一排正方形图块,因此每个正方形的最后两个坐标是下一个正方形的前两个坐标,这听起来正是 GL_QUAD_STRIP 的设计目的。您最终不必重复所有内部顶点。

当您尝试应用纹理时,问题就出现了。当您将纹理坐标绘制为四边形的“末端”时,您已经将它们绑定到顶点,但是当您想要重用最后两个作为下一个四边形的开头时,您需要为它们重新分配新的纹理坐标,除非您正在使用的图块与图块集纹理上使用的前一个图块直接相邻。

有什么办法可以让这个工作吗?或者您是否只需要坚持使用 GL_QUADS 并指定所有内部顶点两次?

If I want to draw a row of 2D square tiles for a game, the obvious way is to use GL_QUADS and specify 4 vertex and texture coordinates for each tile. But since this is a row of square tiles, the last two coordinates of each square are the first two of the next one over, which sounds like exactly what GL_QUAD_STRIP is designed for. You end up not having to repeat all the inner vertices.

The problem comes when you try to apply a texture. You've already bound texture coordinates to the vertices when you drew them as the "end" of a quad, but when you want to reuse the last two as the beginning of the next quad, you need to reassign new texture coordinates to them unless the tile you're using is directly adjacent to the tile that the previous tile used on your tileset texture.

Is there any way to make this work? Or do you just have to stick with GL_QUADS and specify all the inner vertices twice?

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

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

发布评论

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

评论(2

暮凉 2024-12-09 23:31:18

OpenGL 的更高版本引入了一种在从顶点数组绘制时重新启动图元的方法。您要做的就是指定一个特殊的虚拟元素索引,它不是引用顶点数组中的元素,而是指示新基元链的开始,例如四边形带: http://www.opengl.org/wiki/Vertex_Specification#Primitive_Restart

但是,如果您想独立制作图块纹理,那么它们共享顶点。顶点不仅仅是一个位置,它也是分配给它的纹理坐标和其他属性。所以实际上您绘制的不是四边形带(共享顶点)而是独立的四边形。

Later versions of OpenGL introduced a way to restart a primitive while drawing from a vertex array. What you do is specifying a special, dummy element index which instead of refering to a element in the vertex array indicates the beginning of a new primitive chain, like a quad strip: http://www.opengl.org/wiki/Vertex_Specification#Primitive_Restart

However if you want to make your tiles independently textured then they don't share vertices. A vertex is not just a position, it's also the texture coordinates and other attributes assigned to it. So actually you're not drawing a quad strip (which shares vertices) but independent quads.

鹤舞 2024-12-09 23:31:18

有一种方法可以做到这一点,但没有有用的方法来做到这一点。也就是说,没有办法在不添加更多索引的情况下做到这一点。这样做实际上只是将您的 GL_QUAD_STRIP 转换为 GL_QUADS

所以我建议你坚持使用GL_QUADS

There is a way to do it, but there's no useful way to do it. That is, there isn't a way to do it that doesn't add more indices. And doing it would effectively just be turning your GL_QUAD_STRIP into GL_QUADS.

So I would advise you to just stick with GL_QUADS.

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