opengl - Incorrect order of matrix values in glm? -


first of all, i'm not expert opengl. started using glm library mathematics operations on opengl 3 , glsl. need orthographic projection draw 2d graphics, writed simple code:

glm::mat4 projection(1.0); projection = glm::ortho( 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 500.0f); 

printing on screen values glm::ortho has created get:

 0.00313   0.00000   0.00000   0.00000  0.00000  -0.00417   0.00000   0.00000  0.00000   0.00000  -0.00200   0.00000 -1.00000   1.00000  -1.00000   1.00000 

as know not correct order values in opengl, because multiplying matrix position vector ignore translation values.

i tested matrix shader , primitives , blank screen. if modify hand matrix follows works ok:

 0.00313   0.00000   0.00000  -1.00000  0.00000  -0.00417   0.00000   1.00000  0.00000   0.00000  -0.00200  -1.00000  0.00000   0.00000   0.00000   1.00000 

moreover, looking @ function "ortho" in "glm/gtc/matrix_transform.inl" file:

template <typename valtype> inline detail::tmat4x4<valtype> ortho(     valtype const & left,     valtype const & right,     valtype const & bottom,     valtype const & top,     valtype const & znear,     valtype const & zfar) {     detail::tmat4x4<valtype> result(1);     result[0][0] = valtype(2) / (right - left);     result[1][1] = valtype(2) / (top - bottom);     result[2][2] = - valtype(2) / (zfar - znear);     result[3][0] = - (right + left) / (right - left);     result[3][1] = - (top + bottom) / (top - bottom);     result[3][2] = - (zfar + znear) / (zfar - znear);     return result; } 

i have replaced last 3 initialization lines following code , worked ok:

    result[0][3] = - (right + left) / (right - left);     result[1][3] = - (top + bottom) / (top - bottom);     result[2][3] = - (zfar + znear) / (zfar - znear); 

this minimal vertex shader i'm using test (note @ moment uni_mvp projection matrix explained above):

uniform mat4 uni_mvp;  in  vec2 in_position;  void main(void) {   gl_position = uni_mvp * vec4(in_position.xy,0.0, 1.0); } 

i thik not bug, because functions works same way. maybe issue of c++ compiler inverts order of multidimensional arrays? how can solve without modifying glm source code?

i'm using last version of glm library (0.9.1) code::blocks , mingw running on windows vista.

thanks help!

first, it's called transposition, not inversion. inversion means different. second, how it's supposed be. opengl accesses matrices in column major order, i.e. matrix elements have following indices:

 0  4  8  12  1  5  9  13  2  6 10  14  3  7 11  15 

however usual c/c++ multidimensional arrays number this:

 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 

i.e. row , column indices transposed. older versions of opengl sported extension allows supply matrices in transposed form, spare people rewriting code. it's called gl_arb_transpose_matrix http://www.opengl.org/registry/specs/arb/transpose_matrix.txt

with shaders it's easier having use new functions. gluniformmatrix has parameter glboolean transpose, you've got 3 guesses does.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -