【发布时间】:2014-08-02 21:00:52
【问题描述】:
所以我目前正在为 android 开发一个 2D 游戏项目,并且我正在使用 Opengl ES 2.0。我猜我有一个默认范围从 0.0 到 1.0 的深度缓冲区,但我想将它扩展到 0.0 - 100.0。我尝试使用 GLES20.glDepthRangef,但它似乎对我不起作用。 Z 值超出范围的图像:0.0 - 1.0 不会显示在屏幕上。我想念什么吗?我将不胜感激!
private final float[] mtrxProjection = new float[16];
private final float[] mtrxView = new float[16];
private final float[] mtrxProjectionAndView = new float[16];
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
//current width and height.
swp = width;
shp = height;
// Redo the Viewport, making it fullscreen.
GLES20.glViewport(0, 0, (int)swp, (int)shp);
// Clear our matrices
for(int i=0;i<16;i++)
{
mtrxProjection[i] = 0.0f;
mtrxView[i] = 0.0f;
mtrxProjectionAndView[i] = 0.0f;
}
// Setup our screen width and height for normal sprite translation.
Matrix.orthoM(mtrxProjection, 0, 0f, swp, 0.0f, shp, 0, 100);
// Depth testing
GLES20.glEnable( GLES20.GL_DEPTH_TEST );
GLES20.glDepthFunc( GLES20.GL_LEQUAL );
GLES20.glDepthMask( true );
GLES20.glDepthRangef(0, 100);
// Set the camera position (View matrix)
Matrix.setLookAtM(mtrxView, 0, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
// Calculate the projection and view transformation
Matrix.multiplyMM(mtrxProjectionAndView, 0, mtrxProjection, 0, mtrxView, 0);
}
这是我的顶点着色器:
public static final String vs_Image =
"uniform mat4 u_MVPMatrix;" + // u_MVPMatrix is the mtrxProjectionAndView calculated above
"attribute vec4 a_position;" +
"attribute vec2 a_texCoord;" +
"varying vec2 v_texCoord;" +
"void main() {" +
" gl_Position = u_MVPMatrix * a_position;" +
" v_texCoord = a_texCoord;" +
"}";
【问题讨论】: