Open GL ES - 渲染 2D 精灵时的 Z 顺序

发布于 2024-08-13 12:01:24 字数 301 浏览 3 评论 0原文

我想知道是否有一种方法可以让 OpenGL ES 渲染一批四边形(通过纹理页面更改渲染)并按 z 顺序(或反向)渲染它们。

注意我不需要 ZBuffer,我只想按 zDepth 的顺序渲染四边形。

现在我知道人们会说按顺序渲染它们,那么我按纹理页面分组渲染。然而,正如您可以想象的那样,在某些情况下,一个纹理页面的精灵需要出现在另一纹理页面的前面。当您仅在纹理页面排序上渲染时,这会导致问题。

所以我想知道如果我分配了四边形 az 顺序,OpenGL ES 会尊重这一点吗?

非常感谢任何帮助。

干杯 富有的

I was wondering if there was a way to make OpenGL ES render a batch of quads (rendered with texture page changes) and render them in z order (or reverse).

Note I don't want a ZBuffer, I just want quads rendered in order of zDepth.

Now I know people will say just render them in order, well I render grouped by texture page. However as you can imagine there are some cases where sprites from one texture page need to appear in front of another. When you only render on a texture page sort this causes a problem.

So I was wondering if I assigned the quads a z order would OpenGL ES respect this?

Any help greatfully received.

Cheers
Rich

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

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

发布评论

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

评论(3

っ〆星空下的拥抱 2024-08-20 12:01:24

如果没有 Z 缓冲区/深度缓冲区,您就无法实现您想要的目标。您所要求的是深度缓冲区在不启用它的情况下完成的工作!

当Z缓冲区启用时,每次OpenGL绘制到一个像素时,它都会检查该像素现有的Z值,然后决定是否绘制它。

当深度缓冲区未启用时,无论先前现有像素的 z 值是什么,它都会简单地进行覆盖。

You cannot achieve what you want without Z Buffer / Depth Buffer.. What you are asking is the Depth Buffer's work done without enabling it !!

When Z buffer is enabled,everytime OpenGL draws to a pixel.. it checks the pixels existing Z value and then decides on whether to draw it or not.

When Depth Buffer is not enabled it simply overwrites irrespective of what z value of previous existing pixel was.

赴月观长安 2024-08-20 12:01:24

是的,你绝对可以做到这一点,只要你

glEnable(GL_DEPTH_TEST);

,当然,做正确的其他事情。 (确保创建深度缓冲区,使用视锥体范围内的 z 值...)

yes, you can definitely do this, as long as you

glEnable(GL_DEPTH_TEST);

and, of course, get a bunch of other things right. (be sure you create a depth buffer, use z values that are in the range of your view frustum...)

倦话 2024-08-20 12:01:24

OpenGL ES 不会为你做这个。它将遵循您指定的顺序,即四边形来自绘制调用的顺序。如果您希望它们渲染按 Z 排序的四边形,则必须在发送到 OpenGL ES 之前自行对它们进行排序。

如果您使用索引缓冲区,显然可以仅对索引进行排序。但你仍然需要自己计算实际的 Z。

编辑:关于您的纹理问题,我应该补充一点,要同时使用不同的纹理,您应该考虑使用纹理图集(即,保存您想要在不同部分使用的各种纹理的单个纹理)。

OpenGL ES won't do this for you. It will respect the order you specify, i.e. the order in which the quads are from the draw call. If you want them to render your quads sorted by Z, you'll have to sort them yourself prior to sending to OpenGL ES.

If you're using an index buffer, you can obviously sort just the indices. But you still have to compute the actual Z yourself.

Edit: Regarding your texture concern, I should add that to use different textures at the same time, you should look at using texture atlases (that is, a single texture that holds the various textures you want to use in different parts).

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