所以,这里是我的3D立方体代码:GL_DEPTH_TEST好好尝试一下工作
Mesh cube = new Mesh(false, 8, 36,
new VertexAttribute(VertexAttribute.POSITION, 3, ShaderProgram.POSITION_ATTRIBUTE),
new VertexAttribute(VertexAttribute.COLOR_PACKED, 4, ShaderProgram.COLOR_ATTRIBUTE)
);
float x = -100;
float y = -50;
float z = 250;
float w = 50;
float h = 50;
float l = 50;
float r = Color.RED.toFloatBits();
float g = Color.GREEN.toFloatBits();
float b = Color.BLUE.toFloatBits();
float[] vertices = {
-w/2f + x, y, l/2f + z, // 0
r,
-w/2f + x, h + y, l/2f + z, // 1
r,
w/2f + x, h + y, l/2f + z, // 2
b,
w/2f + x, y, l/2f + z, // 3
b,
w/2f + x, y, -l/2f + z, // 4
g,
w/2f + x, y + h, -l/2f + z, // 5
g,
-w/2f + x, y + h, -l/2f + z, // 6
r,
-w/2f + x, y, -l/2f + z, // 7
r
};
short[] indices = {
0, 1, 2, 2, 3, 0,
3, 2, 5, 5, 4, 3,
4, 5, 6, 6, 7, 4,
7, 6, 1, 1, 0, 7,
0, 3, 4, 4, 7, 0,
1, 6, 5, 5, 2, 1
};
cube.setIndices(indices);
cube.setVertices(vertices);
“原型”:
网类是LibGDX并且它是由我修改(不要太多)。所有的 首先,我打电话
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
在初始化(当然初始化上下文之后,)。
和渲染方法是这样的:
GLES20.glClearColor(0f, 0f, 0f, 1f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
shaderProgram.begin();
cube.render(shaderProgram, GLES20.GL_TRIANGLES, 0, 36);
shaderProgram.end();
而最终的结果是:
我也打了glDepthFunc,但我没有得到期望的结果。
我在做什么错?
你叫glEnable后得到一个错误? – TameHog
@TameHog nope .. –
znear和zfar的值是什么? – DanP