Android上的OpenGL深度缓冲区 [英] OpenGL depth buffer on Android
问题描述
我目前正在学习Android(2.1)上的OpenGL ES编程.我从必须旋转的立方体开始.它旋转的很好,但是我无法使深度缓冲正常工作.多边形始终按GL命令渲染它们的顺序显示.我在GL初始化期间执行此操作:
I'm currently learning OpenGL ES programming on Android (2.1). I started with the obligatory rotating cube. It's rotating fine but I can't get the depth buffer to work. The polygons are always displayed in the order the GL commands render them. I do this during initialization of GL:
gl.glClearColor(.5f, .5f, .5f, 1);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glClearDepthf(1f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
在表面变化上,我这样做:
On surface-change I do this:
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 100f);
当我启用背面剔除时,一切看起来都是正确的.但是背面剔除只是一种速度优化,因此它也应该仅适用于深度缓冲区吗?那么,这里缺少什么?
When I enable backface culling then everything looks correct. But backface culling is only a speed-optimization so it should also work with only the depth buffer or not? So what is missing here?
推荐答案
我自己找到了.不是GL代码,而是android代码:
Found it myself. It wasn't GL code, it was android code:
view.setEGLConfigChooser(false);
此行中的"false"明确表示不应分配Z缓冲区.将其切换为"true"后,效果很好.
The "false" in this line explicitly says that no Z-Buffer should be allocated. After switching it to "true" it worked perfectly.
这篇关于Android上的OpenGL深度缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!