The issue is that I can't figure out how to properly draw two objects, because my another object isn't being drawn.
Here's the main code:
GLuint VertexArrayID; glGenVertexArrays(1, &VertexArrayID); glBindVertexArray(VertexArrayID); GLuint VertexArrayID2; glGenVertexArrays(1, &VertexArrayID2); glBindVertexArray(VertexArrayID2); GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" ); GLuint MatrixID = glGetUniformLocation(programID, "MVP"); GLuint MatrixID2 = glGetUniformLocation(programID, "MVP2"); glm::mat4 Projection = glm::perspective(45.0f, 5.0f / 4.0f, 0.1f, 100.0f); glm::mat4 View = glm::lookAt( glm::vec3(4*2,3*2,8*2), glm::vec3(0,0,0), glm::vec3(0,1,0) ); glm::mat4 Model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f)); glm::mat4 MVP = Projection * View * Model; glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); glm::mat4 Model2 = glm::translate(glm::mat4(1.0f), glm::vec3(-5.0f, 0.0f, 0.0f)); glm::mat4 MVP2 = Projection * View * Model2; glUniformMatrix4fv(MatrixID2, 1, GL_FALSE, &MVP2[0][0]); static const GLfloat g_vertex_buffer_data[] = { -1.0f,-1.0f,-1.0f, -1.0f,-1.0f, 1.0f, (plenty of floats) 1.0f,-1.0f, 1.0f }; static const GLfloat g_vertex_buffer_data2[] = { -1.0f, -1.0f, 3.0f, (plenty of floats) 0.0f, 1.0f, 2.0f, }; GLuint vertexbuffer; glGenBuffers(1, &vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); GLuint vertexbuffer2; glGenBuffers(1, &vertexbuffer2); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer2); glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data2), g_vertex_buffer_data2, GL_STATIC_DRAW); do{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(programID); glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); glUniformMatrix4fv(MatrixID2, 1, GL_FALSE, &MVP2[0][0]); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,(void*)0); glDrawArrays(GL_TRIANGLES, 0, 12*3); glEnableVertexAttribArray(2); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer2); glVertexAttribPointer(2,3,GL_FLOAT,GL_FALSE,0,(void*)0); glDrawArrays(GL_TRIANGLES, 0, 4*3); glDisableVertexAttribArray(0); glDisableVertexAttribArray(2); glfwSwapBuffers(window); glfwPollEvents(); }
And shader:
layout(location = 0) in vec3 vertexPosition_modelspace; layout(location = 2) in vec3 vertexPosition_modelspace2; uniform mat4 MVP; uniform mat4 MVP2; void main(){ gl_Position = MVP * vec4(vertexPosition_modelspace,1); gl_Position = MVP2 * vec4(vertexPosition_modelspace2,1); }
I have noticed that only last object is being drawn, so the issue is that 'gl_Position' overwrites it's values, but how should I figure it out?