OpenGL ES 2.0使用LibGDX以相反的深度顺序显示对象 [英] OpenGL ES 2.0 displaying objects in opposite depth order using LibGDX

查看:132
本文介绍了OpenGL ES 2.0使用LibGDX以相反的深度顺序显示对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LibGDX并渲染一些模型.这可以按预期工作,除了更远"的对象显示在更近"对象的前面".换句话说,深度顺序似乎与我的预期相反.

I am using LibGDX and rendering a few models. This works as expected, except objects that are "further away" are displayed "in front" of "closer" objects. In other words the depth order seems to be the opposite of what I intended for it to be.

奇怪的是,模型被远剪切平面以正确的顺序剪切. (大多数距离物体会先消失)

Strangely, the models are clipped in the correct order by the far clipping-plane. (Most distance objects disappear first)

我尝试启用GL_DEPTH_TEST,并且正在清除GL_DEPTH_BUFFER_BIT.

I have tried enabling GL_DEPTH_TEST, and I am clearing GL_DEPTH_BUFFER_BIT.

有人知道这是什么原因吗?

Does anyone know what could be causing this?

推荐答案

如果总是完全错误的顺序,请检查您是否已传递了对

If it's always exactly the wrong order, check that you've passed something meaningful for glDepthFunc. The default is the usually sensible GL_LESS; try GL_GREATER.

如果该订单似乎是您要发出绘图调用的订单,那么请检查您是否确实具有深度缓冲区.在不知道您使用的是哪个LibGDX后端的情况下,要更具体一点是很困难的,但是除非已分配了深度缓冲区,否则深度测试的操作无关紧要,因为缓冲区没有存储空间.

If the order appears to be the order you're issuing draw calls then check that you actually have a depth buffer. It's hard to be more specific without knowing which LibGDX backend you're using but unless a depth buffer has been allocated then it doesn't matter what you do with the depth test, there's no storage for the buffer regardless.

正确答案,根据下面的twiz的评论:

Correct answer, as per twiz's comment below:

我需要设置GL_LESS,但显然LibGDX在以下情况下不喜欢它 您使用glDepthFunc().我的自定义着色器实现了Shader类, 所以我不得不使用传递给begin()的RenderContext 方法.然后我添加了这一行:context.setDepthTest(GL20.GL_LESS);

I needed to set GL_LESS, but apparently LibGDX doesn't like it when you use glDepthFunc(). My custom shader implements the Shader class, so I had to use the RenderContext that is passed to the begin() method. Then I added this line: context.setDepthTest(GL20.GL_LESS);

我的猜测可能是LibGDX可能正在通过线程做一些聪明的事情,并且在调用着色器init之前未设置适当的上下文(或者,LibGDX严格希望您使用显式上下文而不是隐式上下文,并且因此,请不要设置任何东西-可能要考虑将来可以在何处线程化,并希望保持编码规则统一).当然,只是一个随机的猜测.

My guess would be that possibly LibGDX is doing something intelligent with threading and the appropriate context isn't set prior to calling the shader inits (or, possibly, LibGDX strictly wants you to use the explicit context rather than an implicit one and therefore goes out of its way not to have one be set — there's possibly a consideration of what can be threaded where in the future and a desire to keep the coding rules uniform). Just a random guess, of course.

这篇关于OpenGL ES 2.0使用LibGDX以相反的深度顺序显示对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆