frustumM / setLookAtM in OpenGL ES 2.0 on Android

Kevin Gilbert picture Kevin Gilbert · Feb 28, 2012 · Viewed 7.3k times · Source

I am playing around with OpenGL on the Android platform using the OpenGL ES 2.0 tutorial as a basis. The code in question is:

public void onSurfaceChanged( GL10 unused, int width, int height )
{   GLES20.glViewport( 0, 0, width, height );

    float ratio = (float) width / height;
    Matrix.frustumM( mProjMatrix, 0, -ratio, ratio, -1, 1, 1,  9.9999f );

    Matrix.setLookAtM( mVMatrix, 0, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,  0.0f, 0.0f, 1.0f,  0.0f );

    muMVPMatrixHandle = GLES20.glGetUniformLocation( mProgram, "uMVPMatrix" );
}

In particular, the "far" parameter to frustumM. Whenever that parameter is 10 the image (a triangle) does not appear. Any other value is OK. Why?

I have done a fair bit of reading - all to no avail. Even my friend (aka Google) has not been able to help me.

Thanks in advance.

Answer

Erik picture Erik · Feb 29, 2012

When you calculate your projection matrix you specify the far plane to be at 9.9999f, which is why an eyeZ value of 10 or larger in the view matrix calculation will result in an empty image. You are looking outside of your frustum.

Please take a look at this article: http://www.lighthouse3d.com/tutorials/view-frustum-culling/