OpenGL ES 2.0 displaying objects in opposite depth order using LibGDX

夙愿已清 提交于 2019-12-25 02:27:05

问题


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)

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

Does anyone know what could be causing this?


回答1:


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.

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.

Correct answer, as per twiz's comment below:

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);

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.



来源:https://stackoverflow.com/questions/25070612/opengl-es-2-0-displaying-objects-in-opposite-depth-order-using-libgdx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!