I'm trying to change the code from the 22th tutorial at http://ogldev.atspace.co.uk/, using the GLM library, but the result seems wrong.
The problem is shown in the below picture:
While it should be:
This program displays a model onto the screen. The model is loaded using a library and I ensure that all of its vertices, normals, and texuture coordinates are loaded correctly. The problem seems to be at creating the Projection - model - view matrix. I searched for the use of GLM and use the below code to calcualate that matrix:
glm::vec3 Pos(3.0f, 7.0f, -10.0f);
glm::vec3 Target(0.0f, -0.2f, 1.0f);
glm::vec3 Up(0.0, 1.0f, 0.0f);
glm::mat4 viewMat = glm::lookAt(Pos, Target, Up);
glm::mat4 perMat = glm::perspective(60.0f, (float)WINDOW_WIDTH/WINDOW_HEIGHT, 1.0f, 100.0f);
glm::mat4 modelMat = glm::scale(glm::mat4(1.0f),glm::vec3(0.1f, 0.1f, 0.1f));
modelMat = glm::rotate(modelMat, m_scale, glm::vec3(0.0f, 1.0f, 0.0f));
modelMat = glm::translate(modelMat, glm::vec3(0.0f, 0.0f, 10.0f));
//FINAL MATRIX
glm::mat4 PVMMat = perMat * viewMat * modelMat;
After that, I supplied the matrix to the shader like this:
glUniformMatrix4fv(m_WVPLocation, 1, GL_TRUE, &PVMMat[0][0]);
Finally, in the shader, I calculate the gl_Position as below:
//vertex shader
void main()
{
gl_Position = gWVP * vec4(Position, 1.0);
TexCoord0 = TexCoord;
Normal0 = (gWorld * vec4(Normal, 0.0)).xyz;
WorldPos0 = (gWorld * vec4(Position, 1.0)).xyz;
}";
//Fragment shader
void main()
{
FragColor = texture2D(gSampler, TexCoord0.xy);
}";
I tried my best for a few days and I can't see any error in the way I use glm::lookAt and gml::perspective. This is exactly as in the manual on the GLM website. Could you suggest some reason for the problems I'm seeing, or some way for me to further investigate the error? Thanks so much. I hope to see your answer.