PDA

View Full Version : Why isn't my projection matrix working?



Rockinredross867
01-26-2016, 05:01 PM
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


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

shader source file


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


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();
}

GClements
01-26-2016, 08:28 PM
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:




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).

mhagain
01-27-2016, 02:59 AM
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.