OpenGL ES的深度缓冲的Andr​​oid,不能去上班 [英] OpenGL ES depth buffer android, can't get to work

查看:419
本文介绍了OpenGL ES的深度缓冲的Andr​​oid,不能去上班的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法得到深​​度缓冲Android上的OpenGL ES 2.0的正常工作。不管我做什么,对象总是呈现在所提供的订单,完全忽略了深度缓冲。

I'm unable to get the depth buffer working correctly on Android OpenGL ES 2.0. Regardless of what I do, the objects are always render in the order provided and completely ignore the depth buffer.

从我读过,默认的设置应该有一个深度缓冲,但我仍然尝试了我能想到得到它的工作的每一个功能:

From what I've read, the default setup should have a depth buffer, but I've nonetheless tried every function I could think of to get it working:

//setup
setEGLContextClientVersion(2);
setEGLConfigChooser( true );

GLES20.glEnable( GLES20.GL_DEPTH_TEST );
GLES20.glDepthFunc( GLES20.GL_LEQUAL );
GLES20.glDepthMask( true );

//render
GLES20.glClearColor(0.8f, 0.5f, 0.8f, 1.0f);
GLES20.glClearDepthf(1.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

我将物体在0.5,0.0,-0.5在z轴。我可以验证这个工程,因为如果我使用的透视图,将正确地改变对象的大小(远的小) - 我的顶点着色器不只是应用视图矩阵。如果我是正确的,我不能改变片段着色器都在ES的深度,这样就不会有错。

I am placing objects at 0.5, 0.0, -0.5 in the z-axis. I can verify that this works since if I use a perspective view it will correctly alter the sizes of the objects (distant ones smaller) -- my vertex shader does nothing but apply the view matrix. If I'm correct I can't alter the depth in the fragment shader at all in ES, so that can't be wrong.

我难倒。我真的不知道我可以检查什么。每个搜索怎么办?(在网上,或在这里)给出了似乎并没有解决问题(尽管它表明人们有其他原因的问题)的答案。在ES 2.0的大多数例子实际上并不具备足够的对象来测试深度缓存,所以我不能肯定的样品code是正确的无论是。

I'm stumped. I really have no idea what else I could check. Every search I do (in the web, or here) gives answers that don't seem to solve the problem (though it indicates people have had the problem for other reasons). Most examples in ES 2.0 don't actually have enough objects to test the depth buffer, so I can't be positive the sample code is correct either.

要评论:我的设置部分称为只需要打一个电话后,超级我的派生GLSurfaceView里面,之前设置的渲染器。在渲染部分被先叫我renderes内部onDrawFrame。

To comment: My "setup" section is called just after a call to "super" inside my derived GLSurfaceView, prior to setting the renderer. The "render" part is called first inside my renderes "onDrawFrame".

推荐答案

harism的评论是正确的答案。一旦你有一个渲染上下文下面的三个功能只能做。我把它们放在onSurfaceCreated方法和它的作品。你也可以把他们在的onDraw方法,如果您在渲染过程中改变它们。

harism's comment was the correct answer. The below three functions can only be done once you have a rendering context. I put them in the onSurfaceCreated method and it works. You can also put them in the onDraw method if you change them during rendering.

GLES20.glEnable( GLES20.GL_DEPTH_TEST );
GLES20.glDepthFunc( GLES20.GL_LEQUAL );
GLES20.glDepthMask( true );

这篇关于OpenGL ES的深度缓冲的Andr​​oid,不能去上班的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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