I'm working on my university OpenGL project and as a base of it I'm trying to combine several OpenGL tutorials, mainly tutorials from http://ogldev.atspace.co.uk/.
The problem I have is that models I'm rendering are not rendered properly. I don't want to create a post with a wall of code so I'm just supplying a screenshot and main rendering loop, hope that some of you recognize where the error might be or have some guesses. If you need any particular part of the code please let me know.
I am using OpenGL 3.3 and SDL2 for window management.
Rendering loop:
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
glm::mat4 world_matrix = glm::scale(glm::vec3(1, 1, 1));
world_matrix *= glm::rotate(world_matrix, 90.0f, glm::vec3(1.0, 0.0, 0.0));
world_matrix *= glm::translate(glm::vec3(i * 50, j * 50, 0));
//set methods of m_pEffect object set uniform values for the shader.
m_pEffect->SetModel(world_matrix);
m_pEffect->SetView(view);
m_pEffect->SetProjection(projection);
m_pMesh->Render();
}
}
Vertex shader:
#version 330
layout (location = 0) in vec3 Position;
layout (location = 1) in vec2 TexCoord;
layout (location = 2) in vec3 Normal;
uniform mat4 mProjection;
uniform mat4 mView;
uniform mat4 mModel;
out vec2 TexCoord0;
out vec3 Normal0;
out vec3 WorldPos0;
void main()
{
gl_Position = mProjection * mView * mModel * vec4(Position, 1.0);
TexCoord0 = TexCoord;
Normal0 = (mModel * vec4(Normal, 0.0)).xyz;
WorldPos0 = (mModel * vec4(Position, 1.0)).xyz;
}
mProjection * mView * mModel
try usingmModel * mView * mProjection
or to achieve the same result , transpose the matrices before you callsetView/setProjections/...
– Raxvan Dec 19 '13 at 13:15gl_Position = mProjection * mView * mModel * vec4(Position, 1.0);
togl_Position = vec4(Position, 1.0) * mModel * mView * mProjection;
and it worked. As I've said I dont understand why, because in other examples I used first matrix multiplication order and it was correct there. – Maksim Borisov Dec 19 '13 at 13:52