I can see my first "OpenGL 3.2 core profile triangle"
but somehow it disappears when adding perspective.
Here is my code... not much so I hope someone can help me...
Back-face culling and depth test are disabled.
#version 150 coreuniform mat4 ModelViewProjectionMatrix;in vec3 in_Position;void main(void){ gl_Position= ModelViewProjectionMatrix * vec4(in_Position, 1.0);}
#version 150 coreout vec4 out_Color;void main(void){ out_Color = vec4(1.0, 0.0, 0.0, 1.0); }
// setup projection matrixProjectionMatrix= glm::mat4(1.0f);ProjectionMatrix*= glm::perspective(45.0f, 1024.0f / 768.0f, 0.1f, 200.0f);// setup modelview matrix (look down the negative z-axis)ModelViewMatrix= glm::mat4(1.0f); ModelViewMatrix*= glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, 1.0f, 0.0f));// create and upload modelviewprojection matrixModelViewProjectionMatrix= ProjectionMatrix * ModelViewMatrix;glUniformMatrix4fv(glGetUniformLocation(m_handle, "ModelViewProjectionMatrix"), 1, false, glm::value_ptr(ModelViewProjectionMatrix));// setup triangle using VBO and VAOfloat* vert = new float[9];vert[0] = 0.0; vert[1] = 1.0; vert[2]= -10.0;vert[3] =-1.0; vert[4] =-1.0; vert[5]= -10.0;vert[6] = 1.0; vert[7] =-1.0; vert[8]= -10.0;unsigned int m_vaoID; glGenVertexArrays(1, &m_vaoID);glBindVertexArray(m_vaoID); glGenBuffers(1, &m_vboID);glBindBuffer(GL_ARRAY_BUFFER, m_vboID);glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), vert, GL_STATIC_DRAW);glVertexAttribPointer((GLuint)ATTRIBUTE_LOCATION_WORLDVERTEX, 3, GL_FLOAT, GL_FALSE, 0, 0);glEnableVertexAttribArray(ATTRIBUTE_LOCATION_WORLDVERTEX);// renderglDrawArrays(GL_TRIANGLES, 0, 3);// cleanupglBindVertexArray(0);delete[] vert;glBindBuffer(GL_ARRAY_BUFFER, 0);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);glDeleteBuffers(1, &m_vboID);glDeleteVertexArrays(1, &m_vaoID);
I can see this triangle when I apply the
following changes to the code above:
glUniformMatrix4fv(glGetUniformLocation(m_handle, "ModelViewProjectionMatrix"), 1, false, glm::value_ptr(glm::mat4(1.0f)/*ModelViewProjectionMatrix*/));vert[0] = 0.0; vert[1] = 1.0; vert[2]= -1.0;vert[3] =-1.0; vert[4] =-1.0; vert[5]= -1.0;vert[6] = 1.0; vert[7] =-1.0; vert[8]= -1.0;
So basically I upload an identity (no projection) matrix for the
modelviewprojection matrix and display the triangle at z == -1.0f
instead of -10.0f.
Where is my mistake? I can't get the triangle to work
with perspective. I'm really stuck :(
Help is very appreciated!