直接上代码。
public static void glViewport(
int x,
int y,
int width,
int height
)
{
int surfaceHeight = mInfo.height;
float far = mViewPortZFar;
float near = mViewPortZNear;
float sx = width/2.0f;
float ox = sx + x;
float sy = height/2.0f;
float oy = sy + surfaceHeight - height - y;
float A = (far - near)/2.0f;
float B = (far + near)/2.0f;
// compute viewport matrix
float[][] f = new float[4][4];
f[0][0] = sx; f[0][1] = 0; f[0][2] = 0; f[0][3] = ox;
f[1][0] = 0; f[1][1] =-sy; f[1][2] = 0; f[1][3] = oy;
f[2][0] = 0; f[2][1] = 0; f[2][2] = A; f[2][3] = B;
f[3][0] = 0; f[3][1] = 0; f[3][2] = 0; f[3][3] = 1;
mCurrentViewPortMatrix = new M4();
mCurrentViewPortMatrix.m = f;
}
public static void glDepthRangef(
float zNear,
float zFar
){
mViewPortZNear = zNear;
mViewPortZFar = zFar;
}