I am trying to learn OpenGL in the following way: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/
Until they begin to transfer matrices to the vertex shader to translate the triangle in which we drew the drawing.
This is a shader program in which it starts to make mistakes:
#version 330 core layout(location = 0) in vec3 vertexPosition_modelspace; uniform mat4 MVP; void main(){ vec4 v = vec4(vertexPosition_modelspace,1);
If I use the code with comments instead of the line gl_Position = MVP * v; , everything works. A triangle is drawn on the screen. I can also change to M matrix to move the triangle around and scale it.
To simplify things as much as possible, I just pass the vertex shader of the identity matrix into the MVP field. The code is as follows:
mat4x4 MVP; mat4x4_identity(MVP); int i,j; for(i=0; i<4; ++i) { for(j=0; j<4; ++j) printf("%f, ", MVP[i][j]); printf("\n"); } GLuint MatrixID = glGetUniformLocation(programID, "MVP");
I use linmath.h instead of glm ( https://github.com/datenwolf/linmath.h ). The cycle prints:
1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000,
And it confirms that MVP is indeed a unit matrix. However, when I run the program, I do not see a triangle on the screen. Background only (blue).
Here you can see a little more of the main program: https://gist.github.com/avwhite/68580376ddf9a7ec9cb7
If necessary, I can also provide all the source code for the main program, vertex and fragment shader.
I think this has something to do with how the MVP matrix is ββpassed to the shader program, but I'm completely new to OpenGL, so I really don't know what is going on.