# OpenGL beginner. Following Tutorial - Got a bunch of questions

Greetings OpenGL-Community!

I am following the tutorial at opengl-tutorial .org at the moment, but using my own classes to implement what that tutorial is teaching. (I did use code from another tutorial for the shader creation that might be one of the reasons im getting different results?)

My progress so far can be found at:

1) Why do i have to define and create the VAO before creating a shader-program?

If i create the shader (main.cpp | line 53) before the VAO (main.cpp | lines 26-30),
my validate program gets a warning. (However the triangle still gets drawn).

2) Part three in the tutorial i linked talks about transformation matrices. I do understand the math part of it, however when it comes to the implementation, it doesn’t seem to work for me.

After the shader creation (main.cpp | line 53) I would add the following from the tutorial:

``````
// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
// Camera matrix
glm::mat4 View = glm::lookAt(
glm::vec3(4,3,3), // Camera is at (4,3,3), in World Space
glm::vec3(0,0,0), // and looks at the origin
glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
);
// Model matrix : an identity matrix (model will be at the origin)
glm::mat4 Model = glm::mat4(1.0f);* // Changes for each model !
// Our ModelViewProjection : multiplication of our 3 matrices
glm::mat4 MVP = Projection * View * Model; // Remember, matrix multiplication is the other way around

glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP);

``````

and change the vertex shader code to this:

``````
#version 330 core

layout(location = 0) in vec3 vertexPosition;
uniform mat4 MVP;

void main() {
vec4 v = vec4(vertexPosition, 1);
gl_Position = MVP * v;
}

``````

However i don’t get the result the tutorial does (The triangle isn’t visible at all).

I’d appreciate any help a lot!

Greetings, Robert

Result without transformation (GitHub Version):
[ATTACH=CONFIG]1015[/ATTACH]

Expected result with transformation:
[ATTACH=CONFIG]1013[/ATTACH]

Current result with transformation:
[ATTACH=CONFIG]1014[/ATTACH]

UPDATE:

I just tried to pass an identity matrix to the shader, but the triangle disappears.
Pushed the code that i used to github.

It seems like the matrix isn’t passed on correctly. Can somebody tell me what im doing wrong?

The error should be somewhere between main.cpp | line 55-61 and/or the basicShader.vertexshader file

EDIT:
By identifying what was wrong, then using google I found out what i was doing wrong.

I need to call the glUniform* after glUseProgram (in my case shader.Bind())

New result:
[ATTACH=CONFIG]1016[/ATTACH]

Why do i have to define and create the VAO before creating a shader-program?

If i create the shader (main.cpp | line 53) before the VAO (main.cpp | lines 26-30),
my validate program gets a warning. (However the triangle still gets drawn).

The glValidateProgram function answers the question, “Given the current state of the rendering pipeline, can I render with this program?” Since you’re not allowed to render without a VAO (in core OpenGL), the answer to that question is “no” if there’s no VAO bound.

Why do i have to define and create the VAO before creating a shader-program?

If i create the shader (main.cpp | line 53) before the VAO (main.cpp | lines 26-30),
my validate program gets a warning. (However the triangle still gets drawn).

The glValidateProgram function answers the question, “Given the current state of the rendering pipeline, can I render with this program?” Since you’re not allowed to render without a VAO (in core OpenGL), the answer to that question is “no” if there’s no VAO bound.

Ah thank you very much!

So to get the correct answer i check the program validation after i made all the “preps”.

Thank you very much!
Made a lot of progress today 