Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to change the code from the 22th tutorial at, 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));

    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.

share|improve this question

The problem is solved. I changed glUniformMatrix4fv(m_WVPLocation, 1, GL_TRUE, &PVMMat[0][0]); to glUniformMatrix4fv(m_WVPLocation, 1, GL_FALSE, &PVMMat[0][0]); AND glFrontFace(GL_CW); to glFrontFace(GL_CCW);

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.