Hi everyone,
I have a very weird situation. The image below show the correct rendered image which my opengl with GLSL should draw
however, this is the problem:
when I add perspective projection matrix and my camera matrix to my GLSL, this will be the rendered problem
the following is my projection GLSL code: ( I got this from song ha)
float tangent = tanf(m_persProj.FOV /2 * DEG2RAD); // tangent of half fovY
float height = m_persProj.zNear * tangent; // half height of near plane
float width = height * (m_persProj.Width/ m_persProj.Height ) ; // half width of near plane
m[0] = 2 * m_persProj.zNear / (m_persProj.Width- (-m_persProj.Width));
m[2] = (m_persProj.Width + (-m_persProj.Width)) / (m_persProj.Width - (-m_persProj.Width));
m[5] = 2 * m_persProj.zNear / (m_persProj.Height- (-m_persProj.Height));
m[6] = (m_persProj.Height + (-m_persProj.Height)) / (m_persProj.Height -(-m_persProj.Height));
m[10] = -(m_persProj.zFar + m_persProj.zNear) / (m_persProj.zFar - m_persProj.zNear);
m[11] = -(2 * m_persProj.zFar* m_persProj.zNear) / (m_persProj.zFar - m_persProj.zNear);
m[14] = -1;
m[15] = 0;
.
.
In my main GLSL code :
#version 330 core
layout(location = 0) in vec4 vertexPosition_modelspace;
uniform mat4 gProjectionMatrix;
uniform float gScale;
uniform mat4 gCameraMatrix;
void main(void)
{
vec4 scolumn1,scolumn2,scolumn3,scolumn4;
scolumn1.xyz=vec3(gScale,0.0,0.0);
scolumn1.w=0.0;
scolumn2.xyz=vec3(0.0,gScale,0.0);
scolumn2.w=0.0;
scolumn3.xyz=vec3(0.0,0.0,gScale);
scolumn3.w=0.0;
scolumn4.xyz=vec3(0.0,0.0,0.0);
scolumn4.w=1.0;
mat4 mScale;
mScale=mat4(
scolumn1,
scolumn2,
scolumn3,
scolumn4
);
gl_Position =gProjectionMatrixgCameraMatrixmScale* vertexPosition_modelspace;
}";
Later I substitute my projection code using :
glUniformMatrix4fv(locProjMatrix , 1, GL_FALSE, p->GetTrans());
If I do not use any camera matrix or projection matrix , this is my output:
as you can see from the image ALL the MESH are rendered at the same coordinate.
does anyone has any idea how to solve this?
Thank you in advance