我正在用OpenGL ES 1.0编写一个2d游戏(如果适用的话,可以转换为1.1扩展)。我试图保持尽可能通用,以防我遗漏了一些显而易见的东西。
对于Android2.2 (Froyo)和Android2.3.3(姜饼)之间的深度测试,我有一个问题。目前,onCreate I有以下内容:
//this is called once only when the renderer is created
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0, mWidth, 0, mHeight, 1.0f, 320.0f);在使用OES_draw_texture扩展时,我成功地使用了深度缓冲区,这不是问题。然而,当为传统的顶点绘图指定Z值时,版本之间出现了奇怪的差异。
在2.2中,以下代码呈现在最前面(最上面):
//This array is used in the function glDrawArrays as a GL10.GL_TRIANGLE_STRIP.
//It works as intended. The specific positions are the Z positions of each point in
//the square (the triangle strips form a square).
vertices[2]=0.5f*(1+320)*-1;
vertices[5]=0.5f*(1+320)*-1;
vertices[8]=0.5f*(1+320)*-1;
vertices[11]=0.5f*(1+320)*-1; 现在,这是很好的工作,但在2.3.3中,这将进一步推回对象。要使用2.3.3获得正确的位置,我需要执行以下操作:
vertices[2]=-1;
vertices[5]=-1;
vertices[8]=-1;
vertices[11]=-1; 这将纠正这个问题。
我的问题有两方面:
我怀疑我可能遗漏了金格尔面包含蓄地假定的某个命令,而弗罗约却没有,但我不确定。任何帮助都将不胜感激。
发布于 2011-09-12 23:10:36
gl.glOrthof在ES2.0中没有作用,因为它不再有投影矩阵的概念。您可能希望使用android.opengl.Matrix.orthoM计算投影矩阵,然后在顶点着色器中将点乘以它,如下所示:
attribute vec3 position;
uniform mat4 projection;
void main() {
gl_Position = projection * vec4(position, 1.);
}分配给gl_Position的位置在“剪辑坐标”中,在每个维度的范围为-1..1。听起来,您是从顶点数据中分配gl_Position,而不是将其从想要的zNear..zFar扩展到-1..1。
https://stackoverflow.com/questions/7394848
复制相似问题