GLSL + OpenGL Moving away from state machine -
hey guys, started moving 1 of projects away fixed pipeline, try things out tried write shader pass opengl matrices , transform vertex , start calculating own once knew worked. thought simple task not work.
i started out shader normal fixed pipeline:
void main(void) { gl_position = gl_modelviewprojectionmatrix * gl_vertex; gl_texcoord[0] = gl_multitexcoord0; } i changed this:
uniform mat4 model_matrix; uniform mat4 projection_matrix; void main(void) { gl_position = model_matrix * projection_matrix * gl_vertex; gl_texcoord[0] = gl_multitexcoord0; } i retrieve opengl matrices , pass them shader code:
[material.shader bindshader]; glfloat modelmat[16]; glfloat projectionmat[16]; glgetfloatv(gl_modelview_matrix, modelmat); glgetfloatv(gl_projection_matrix, projectionmat); gluniformmatrix4fv([material.shader getuniformlocation:"model_matrix"], 1, gl_false, modelmat); gluniformmatrix4fv([material.shader getuniformlocation:"projection_matrix"], 1, gl_false, projectionmat ); ... draw stuff for reason not draw (i 95% positive matrices correct before pass them btw) ideas?
the problem order of matrix multiplication wrong. not aware operations not commutative.
the correct order should be:
projection * modelview * vertex thanks ltjax , doug65536
Comments
Post a Comment