diff -r 4c41bfe2ec6e -r 1de2b8d64e9f src/gl/partrenderer.cpp --- a/src/gl/partrenderer.cpp Sun Jan 26 14:29:30 2020 +0200 +++ b/src/gl/partrenderer.cpp Tue Jan 28 23:34:49 2020 +0200 @@ -46,7 +46,6 @@ } this->compiler->initialize(); this->compiler->build(this->model, this->documents); - this->initializeLighting(); this->initialized = true; this->modelQuaternion = glm::angleAxis(glm::radians(30.0f), glm::vec3{-1, 0, 0}); this->modelQuaternion *= glm::angleAxis(glm::radians(225.0f), glm::vec3{-0, 1, 0}); @@ -55,22 +54,6 @@ this->update(); } -void PartRenderer::initializeLighting() -{ - GLfloat materialShininess[] = {5.0}; - GLfloat lightPosition[] = {1.0, 1.0, 1.0, 0.0}; - GLfloat ambientLightingLevel[] = {0.5, 0.5, 0.5, 1.0}; - glShadeModel(GL_SMOOTH); - glMaterialfv(GL_FRONT, GL_SHININESS, materialShininess); - glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLightingLevel); - glLightfv(GL_LIGHT0, GL_DIFFUSE, ambientLightingLevel); - glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_COLOR_MATERIAL); - glEnable(GL_DEPTH_TEST); -} - void PartRenderer::resizeGL(int width, int height) { glViewport(0, 0, width, height); @@ -79,6 +62,7 @@ static_cast(width) / static_cast(height), 0.1f, 10000.f); + this->compiler->setUniformMatrix("projectionMatrix", this->projectionMatrix); } static GLenum getGlTypeForArrayClass(const gl::ArrayClass vboClass) @@ -128,7 +112,6 @@ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); break; } - this->compiler->setUniformMatrix("CameraTransformation", this->projectionMatrix * this->viewMatrix * glm::mat4_cast(this->modelQuaternion)); // Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering. renderVao(gl::ArrayClass::Triangles); renderVao(gl::ArrayClass::Quads); @@ -141,12 +124,13 @@ // I'm not quite sure why using the exponent function on the zoom factor causes linear zoom behavior const double z = 2 * std::exp(this->zoom) * (1 + this->compiler->modelDistance()); this->viewMatrix = glm::lookAt(glm::vec3{0, 0, z}, {0, 0, 0}, {0, -1, 0}); + this->compiler->setUniformMatrix("viewMatrix", this->viewMatrix); } void PartRenderer::renderVao(const gl::ArrayClass arrayClass) { this->compiler->bindVertexArray(arrayClass); - const std::size_t vertexCount = this->compiler->vboSize(arrayClass) / gl::FLOATS_PER_VERTEX; + const std::size_t vertexCount = this->compiler->vertexCount(arrayClass); glDrawArrays(getGlTypeForArrayClass(arrayClass), 0, static_cast(vertexCount)); this->compiler->releaseVertexArray(arrayClass); this->checkForGLErrors(); @@ -185,6 +169,7 @@ const glm::quat q_x = glm::angleAxis(scalar * move_x, glm::vec3{0, -1, 0}); const glm::quat q_y = glm::angleAxis(scalar * move_y, glm::vec3{-1, 0, 0}); this->modelQuaternion = q_x * q_y * this->modelQuaternion; + this->compiler->setUniformMatrix("modelMatrix", glm::mat4_cast(this->modelQuaternion)); this->update(); } this->lastMousePosition = pointToPointF(event->pos());