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 3 of 3

Thread: Why isn't my projection matrix working?

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2015
    Posts
    26

    Question Why isn't my projection matrix working?

    Everything works and when I start adding the projection matrix everything fails to load. I just want to know what is causing the problem everything seems to be fine. I'm adding it in my shaders. I load a 4x4 matrix to the uniform. I also create the projection matrix. I don't know what else I'm doing wrong.

    vertShader

    Code :
    gl_Position = projectionMatrix * transformationMatrix * vec4(position, 1.0f);

    shader source file

    Code :
    void StaticShader::getAllUniformLocations()
    	{
    		m_LocationTransformMatrix = super::getUniformLocation("transformationMatrix");
    		m_LocationProjectionMatrix = super::getUniformLocation("projectionMatrix");
    	}
     
    void StaticShader::loadProjectionMatrix(glm::mat4& projection)
    	{
    		super::loadMatrix(m_LocationProjectionMatrix, projection);
    	}

    renderer source file

    NEAR_PLANE is a static constant float and same goes for FAR_PLANE

    Code :
    Renderer::Renderer(shader::StaticShader& shader)
    	{
    		glm::mat4 projectionMatrix = projectionMatrix = glm::perspective(70.0f, 800.0f / 700.0f, NEAR_PLANE, FAR_PLANE);
    		shader.enable();
    		shader.loadProjectionMatrix(projectionMatrix);
    		shader.disable();
    	}

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,522
    Quote Originally Posted by Rockinredross867 View Post
    Everything works and when I start adding the projection matrix everything fails to load.
    Can you clarify what "fails to load" means?

    Also: probably not related to this, but:
    Quote Originally Posted by Rockinredross867 View Post
    Code :
    glm::mat4 projectionMatrix = projectionMatrix = glm::perspective(70.0f, 800.0f / 700.0f, NEAR_PLANE, FAR_PLANE);
    Unless you're using a rather old version of GLM, the above specifies a field-of-view angle of 70 radians (~4011 degrees. That will probably work by coincidence (producing the same matrix as an angle of 0.885 radians = 50.7 degrees), but other values (which would be sensible if in degrees) can result in a projection matrix with a negative scale factor (rotating the scene 180 degrees about the centre of the view).

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,728
    Quote Originally Posted by Rockinredross867 View Post
    NEAR_PLANE is a static constant float and same goes for FAR_PLANE
    And what values do they have? A near plane of 0 will cause things to fail to draw.

Tags for this Thread

Posting Permissions

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