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

  1. #1
    Intern Contributor
    Join Date
    Oct 2007
    Location
    persia,tabriz
    Posts
    71

    projection matrix

    hi

    at now i use gluPerspective for calculating projection matrix but at now i use OGL 3.2 and i want to calculate it manually.

    i read some articles about it and i try to implement, but i dosnt get any result.

    1. how can i calculate a projection matrix and save it in a float array

    2. which is faster: ModelViewMatrix * ProjectionMatrix on gpu
    or calculating this on cpu

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    748

    Re: projection matrix

    1. look at http://www.flashbang.se/ among other places

    2, technically on the cpu since you only have to do it once, but if you have separate projection and modelview matrices you might go with on the gpu since then you have more choices with your shader.

    Ultimatly it really doesn't matter though since were fillrate limited anyway you choose.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jan 2005
    Location
    Stockholm, Sweden
    Posts
    166

    Re: projection matrix

    Very nice explanation of projection matrix is available here

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2009
    Posts
    2

    Re: projection matrix

    MSDN help for glFrustum explains how the matrix is calculated, that might help.

  5. #5
    Intern Contributor
    Join Date
    Oct 2007
    Location
    persia,tabriz
    Posts
    71

    Re: projection matrix

    why it dosent work?

    Code :
    float h = 1.0f/tanf(m_fFov / 2);
     
     
    _elements[0][0] = h / m_fAspect;
    _elements[0][1] = 0;
    _elements[0][2] = 0;
    _elements[0][3] = 0;
     
    _elements[1][0] = 0;
    _elements[1][1] = h;
    _elements[1][2] = 0;
    _elements[1][3] = 0;
     
    _elements[2][0] = 0;
    _elements[2][1] = 0;
    _elements[2][2] = m_fFarZ / (m_fFarZ - m_fNearZ) ;
    _elements[2][3] = 1.0;
     
    _elements[3][0] = 0;
    _elements[3][1] = 0;
    _elements[3][2] = -m_fNearZ * m_fFarZ / (m_fFarZ - m_fNearZ); 
    _elements[3][3] = 0;

    and my shader:
    Code :
    #version 150 core 
    in vec3 in_Position;
    in vec3 in_Color;
    out vec3 ex_Color;
    uniform mat4 in_ProjectionMatrix;
    uniform mat4 in_ModelViewMatrix;
    void main(void)
    {
    gl_Position = in_ModelViewMatrix * in_ProjectionMatrix * vec4(in_Position, 1.0);
    ex_Color = in_Color;
    }

  6. #6
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: projection matrix

    That should be
    gl_Position = in_ProjectionMatrix * in_ModelViewMatrix * vec4(in_Position, 1.0);

    and in case anyone wants the source code
    http://www.opengl.org/wiki/GluPerspective_code
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

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