RobertW

04-19-2015, 03:33 AM

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:

GitHub Link (https://github.com/rjwestman/thi_openglmac)

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

GLuint MatrixID = glGetUniformLocation(shader.getShaderProgramID(), "MVP");

glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);

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):

1753

Expected result with transformation:

1751

Current result with transformation:

1752

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:

GitHub Link (https://github.com/rjwestman/thi_openglmac)

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

GLuint MatrixID = glGetUniformLocation(shader.getShaderProgramID(), "MVP");

glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);

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):

1753

Expected result with transformation:

1751

Current result with transformation:

1752