问题描述
我正在使用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?
推荐答案
如果总是完全错误的顺序,请检查您是否已传递了对 glDepthFunc
.默认是通常明智的GL_LESS
;尝试GL_GREATER
.
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:
我的猜测可能是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以相反的深度顺序显示对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!