Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Projection Matrix problem

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Oct 2011
    Posts
    52

    Post Projection Matrix problem

    Im just moving to the modern OpenGL. I set up the view-matrix(without projection) and it works OK. I added a minimalist projection matrix and it also works fine.
    Code :
            GLfloat projection_matrix[16] =                {                    1.0, 0.0,  0.0, 0.0,                    0.0, 1.0,  0.0, 0.0,                    0.0, 0.0,  1.0, 1.0,                    0.0, 0.0,  0.0, 0.0                };
    Then Ive tried to use a proper matrix and its not working out. That means, as I move the camera the movement and rotation seem like its mirrored.(I use a 90.0 perspective angle and 1.0 aspect ratio, to keep it simple.)
    Code :
        float        n = 0.5,        f = 100.0,        w2 = 0.5,       //width  / 2        h2 = 0.5;       //height / 2        GLfloat projection_matrix[16] =                {                    n/w2,   0.0,    0.0,             0.0,                    0.0,    n/h2,   0.0,             0.0,                    0.0,    0.0,    -((f+n)/(f-n)), -1.0,                    0.0,    0.0,    -(2*f*n)/(f-n),  0.0                };
    I got it from here: http://www.songho.ca/opengl/gl_projectionmatrix.html...but its the same in the OGL Programming Guide 8th, so I guess it should be correct.This is the shader source BTW:
    Code :
    #version 330 corelayout(location = 0) in vec3 vertex_pos;uniform mat4 V_trans;uniform mat4 V_rot;uniform mat4 P;void main(){    vec4 pos_HOM = vec4( vertex_pos, 1);	gl_Position = P * (V_rot * V_trans) * pos_HOM;}
    Im also wondering how can I set the near and far planes, ....as gluPerspective is for the "old" openGL I guess.Thanks!

  2. #2
    Intern Contributor
    Join Date
    Oct 2011
    Posts
    52
    Sorry, I copy-pasted the text and it got messed up. Strange

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2008
    Posts
    15
    Have a look at https://github.com/sphair/ClanLib/bl...re/Math/mat4.h (header) https://github.com/sphair/ClanLib/bl.../Math/mat4.cpp (source) used for the http://clanlib.org/index.html ClanLib SDK
    They generate the matrices in an OpenGL friendly way. Other libraries that do the same thing are freely available

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by Aliii View Post
    Sorry, I copy-pasted the text and it got messed up. Strange
    Then edit it. Or if the edit window has expired, post a new message with legible code.

  5. #5
    Intern Contributor
    Join Date
    Oct 2011
    Posts
    52
    Code :
            GLfloat projection_matrix[16] =                {                    1.0, 0.0,  0.0, 0.0,                    0.0, 1.0,  0.0, 0.0,                    0.0, 0.0,  1.0, 1.0,                    0.0, 0.0,  0.0, 0.0                };
    ...........
    Code :
        float        n = 0.5,        f = 100.0,        w2 = 0.5,       //width  / 2        h2 = 0.5;       //height / 2        GLfloat projection_matrix[16] =                {                    n/w2,   0.0,    0.0,             0.0,                    0.0,    n/h2,   0.0,             0.0,                    0.0,    0.0,    -((f+n)/(f-n)), -1.0,                    0.0,    0.0,    -(2*f*n)/(f-n),  0.0                };
    ........
    Code :
    #version 330 corelayout(location = 0) in vec3 vertex_pos;uniform mat4 V_trans;uniform mat4 V_rot;uniform mat4 P;void main(){    vec4 pos_HOM = vec4( vertex_pos, 1);    gl_Position = P * (V_rot * V_trans) * pos_HOM;}

  6. #6
    Intern Contributor
    Join Date
    Oct 2011
    Posts
    52
    Its not working. I give up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •