android - When to call glMatrixMode() -


most opengl es tutorials android i've followed has onsurfacechanged() function 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, grouping here? must glmatrixmode() called after glviewport? , must glloadidentity() called right after glmatrixmode()?

i've been coding "full" openggl before, , in old codes first called glmatrixmode(), gluperspective , last glloadidentity(). if 1 first set matrix should used gluperspective() , last set glidentity() finish it.

what correct order calling glmatrixmode(), glidentity() , gluperspective() - , why? there differences between opengl , opengl es setting glmatrixmode()?

glviewport() independent of matrix transform stacks , can called @ time.

glloadidentity() typically called after matrix mode change starting "fresh" if will. matrix transforms such gluperspective(), glortho(), glfrustum(), glrotate(), glmultmatrix(), gltranslate() cumulative operations because aggregate allow describe complex 3d world space transforms or describe opengl viewing volume. example: if want cube translated in +x direction rotated around z axis issue glrotate() followed gltranslate().

glloadidentity() wipes out matrix (of current matrix mode) identity matrix following gluperspective() glloadidentity() equivalent single call glloadidentity(). in other words, sequence nonsensical.

reverse order of these because gluperspective() multiply current matrix perspective transform. if current matrix identity multiply result in gluperspective() matrix transform want projection matrix mode 99% of time when perspective viewing.

there no differences between opengl , opengl es respect behavior of glmatrixmode() or how these matrix functions modify gl matrix state.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -