Most OpenGL ES tutorials for Android I've followed has its onSurfaceChanged() function like this:
public void onSurfaceChanged( GL10 gl, int width, int height ) {
gl.glViewport( 0, 0, width, height );
gl.glMatrixMode( GL10.GL_PROJECTION );
gl.glLoadIdentity();
GLU.gluPerspective( gl, 45.0f, ( ( float )width / ( float )height ), 0.1f, 100.0f );
gl.glMatrixMode( GL10.GL_MODELVIEW );
gl.glLoadIdentity();
}
However, what is the grouping here? Must glMatrixMode() be called after glViewport? And must a glLoadIdentity() be called right after glMatrixMode()?
I've been coding for "full" OpengGL before, and in my old codes I first called glMatrixMode(), then gluPerspective and last glLoadIdentity(). As if one first set what matrix should be used for gluPerspective() and last set glIdentity() to finish it.
What is the correct order for calling glMatrixMode(), glIdentity() and gluPerspective() - and why? Are there differences between OpenGL and OpenGL ES for setting up glMatrixMode()?