I've used orthographic perspective before, which drew everything properly. I used the following code during initialization:
glViewport(0, 0, WIDTH, HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WIDTH, HEIGHT, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
And this shader:
vec3 actualPos = inPos + cubeVert * (inMass * scale);
gl_Position = vec4(actualPos, 1.0);
Mass = inMass;
UV = cubeVert.xy + vec2(0.5, 0.5);
I've been trying to switch to using the MVP matrix inside my shader instead, but I get no output on my screen, other than the color I clear it with.
I build it with:
glm::mat4 model(1.f);
glm::mat4 projection(1.f);
projection = glm::perspective(glm::radians(30.f), (float)WIDTH / (float)HEIGHT, 0.1f, 100.f);
glm::mat4 view(1.f);
view = glm::lookAt(glm::vec3(-10.f, -10.f, -10.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 1.f, 0.f));
glm::mat4 MVP = projection * view * model;
And then apply it during initialization, after removing the old code:
glViewport(0, 0, WIDTH, HEIGHT);
glUniformMatrix4fv(glGetAttribLocation(program, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
And this is my current main drawing loop:
glClearColor(0.01f, 0.10f, 0.15f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(program);
glUniformMatrix4fv(glGetAttribLocation(program, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE0, texture);
glUniform1i(sampler, 0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, VBOcube);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, (void*)0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, AMOUNT * sizeof(Body), NULL, GL_STREAM_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, AMOUNT * sizeof(Body), bods);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Body), (void*)0);
glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, sizeof(Body), (void*)sizeof(glm::vec3));
glVertexAttribDivisor(0, 0);
glVertexAttribDivisor(1, 1);
glVertexAttribDivisor(2, 1);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, AMOUNT);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
I've tried to move the camera around, rotate it, in case the objects were being drawn outside of the view, but I'm not sure if anything is even being drawn at this point.
"MVP"
Is a uniform variable. To geht the location index of a uniform variable, you've to use glGetUniformLocation
rather than glGetAttribLocation
.
glLinkProgram(program);
GLint mvp_loc = glGetUniformLocation(program, "MVP"):
glUseProgram(program);
glUniformMatrix4fv(mvp_loc, 1, GL_FALSE, glm::value_ptr(MVP));