From 610e68c697cd979de21485350a2ee5c27a73bd78 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Sat, 16 May 2020 16:01:01 +0200 Subject: [PATCH] Enabling OpenGL Multisampling for antialiasing --- Mesh.cpp | 30 ++++++++++++++++++++---------- Primitives.cpp | 2 ++ RenderingManager.cpp | 7 +++++-- Source.cpp | 11 +++++------ UserInterfaceManager.cpp | 4 ++-- 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/Mesh.cpp b/Mesh.cpp index 72a042e..955017d 100644 --- a/Mesh.cpp +++ b/Mesh.cpp @@ -425,6 +425,9 @@ void Frame::draw(glm::mat4 modelview, glm::mat4 projection) if(shadow_) shadow_->draw( modelview * transform_, projection); + // enable antialiasing + glEnable(GL_MULTISAMPLE_ARB); + // right side float ar = scale_.x / scale_.y; glm::vec3 s(1.f, 1.f, 1.f); @@ -440,9 +443,11 @@ void Frame::draw(glm::mat4 modelview, glm::mat4 projection) t.x = -t.x; s.x = -s.x; ctm = modelview * GlmToolkit::transform(t, rotation_, s); - border_->draw( ctm, projection ); +// border_->draw( ctm, projection ); } + // enable antialiasing + glDisable(GL_MULTISAMPLE_ARB); } } @@ -476,6 +481,9 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 projection) } if ( visible_ ) { + // enable antialiasing + glEnable(GL_MULTISAMPLE_ARB); + // set color handle_->shader()->color = color; @@ -485,47 +493,49 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 projection) if ( type_ == RESIZE ) { // 4 corners ctm = modelview * glm::translate(glm::identity(), glm::vec3(ar, -1.f, 0.f) ); - ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f; + handle_->draw( ctm, projection ); ctm = modelview * glm::translate(glm::identity(), glm::vec3(ar, +1.f, 0.f)); - ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f; + handle_->draw( ctm, projection ); ctm = modelview * glm::translate(glm::identity(), glm::vec3(-ar, -1.f, 0.f)); - ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f; + handle_->draw( ctm, projection ); ctm = modelview * glm::translate(glm::identity(), glm::vec3(-ar, +1.f, 0.f)); - ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f; + handle_->draw( ctm, projection ); } else if ( type_ == RESIZE_H ){ // left and right ctm = modelview * glm::translate(glm::identity(), glm::vec3(ar, 0.f, 0.f) ); - ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f; + handle_->draw( ctm, projection ); ctm = modelview * glm::translate(glm::identity(), glm::vec3(-ar, 0.f, 0.f)); - ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f; + handle_->draw( ctm, projection ); } else if ( type_ == RESIZE_V ){ // top and bottom ctm = modelview * glm::translate(glm::identity(), glm::vec3(0.f, +1.f, 0.f) ); - ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f; + handle_->draw( ctm, projection ); ctm = modelview * glm::translate(glm::identity(), glm::vec3(0.f, -1.f, 0.f)); - ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f; + handle_->draw( ctm, projection ); } else if ( type_ == ROTATE ){ // only once in upper top right corner ctm = modelview * glm::translate(glm::identity(), glm::vec3(ar + 0.06f, +1.06f, 0.f)); - ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f; + handle_->draw( ctm, projection ); } + + glDisable(GL_MULTISAMPLE_ARB); } } diff --git a/Primitives.cpp b/Primitives.cpp index aa6e484..696040a 100644 --- a/Primitives.cpp +++ b/Primitives.cpp @@ -251,10 +251,12 @@ void LineStrip::draw(glm::mat4 modelview, glm::mat4 projection) init(); glLineWidth(linewidth_); + glEnable(GL_LINE_SMOOTH); Primitive::draw(modelview, projection); glLineWidth(1); + glDisable(GL_LINE_SMOOTH); } void LineStrip::accept(Visitor& v) diff --git a/RenderingManager.cpp b/RenderingManager.cpp index 6956528..3fc1196 100644 --- a/RenderingManager.cpp +++ b/RenderingManager.cpp @@ -87,9 +87,13 @@ bool Rendering::Init() glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac #endif + Settings::WindowConfig winset = Settings::application.windows.front(); // Create window with graphics context + // GL Multisampling #3 + glfwWindowHint(GLFW_SAMPLES, 3); + // do not show at creation glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); main_window_ = glfwCreateWindow(winset.w, winset.h, winset.name.c_str(), NULL, NULL); @@ -139,9 +143,8 @@ bool Rendering::Init() gst_init (NULL, NULL); // Antialiasing - glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); + glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); // This hint can improve the speed of texturing when perspective-correct texture coordinate interpolation isn't needed glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); // This hint can improve the speed of shading when dFdx dFdy aren't needed in GLSL diff --git a/Source.cpp b/Source.cpp index a2564fc..051a58c 100644 --- a/Source.cpp +++ b/Source.cpp @@ -44,7 +44,7 @@ Source::Source(const std::string &name) : name_(name), initialized_(false) groups_[View::GEOMETRY]->attach(frame); overlays_[View::GEOMETRY] = new Group; - overlays_[View::GEOMETRY]->translation_.z = 0.1; + overlays_[View::GEOMETRY]->translation_.z = 0.15; overlays_[View::GEOMETRY]->visible_ = false; groups_[View::GEOMETRY]->attach(overlays_[View::GEOMETRY]); @@ -145,23 +145,22 @@ MediaSource::MediaSource(const std::string &name) : Source(name), path_("") // extra overlays for geometry view frame = new Frame(Frame::SHARP_LARGE); frame->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); - frame->translation_.z = 0.1; overlays_[View::GEOMETRY]->attach(frame); resize_handle_ = new Handles(Handles::RESIZE); resize_handle_->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); - resize_handle_->translation_.z = 0.15; + resize_handle_->translation_.z = 0.1; overlays_[View::GEOMETRY]->attach(resize_handle_); resize_H_handle_ = new Handles(Handles::RESIZE_H); resize_H_handle_->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); - resize_H_handle_->translation_.z = 0.15; + resize_H_handle_->translation_.z = 0.1; overlays_[View::GEOMETRY]->attach(resize_H_handle_); resize_V_handle_ = new Handles(Handles::RESIZE_V); resize_V_handle_->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); - resize_V_handle_->translation_.z = 0.15; + resize_V_handle_->translation_.z = 0.1; overlays_[View::GEOMETRY]->attach(resize_V_handle_); rotate_handle_ = new Handles(Handles::ROTATE); rotate_handle_->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); - rotate_handle_->translation_.z = 0.15; + rotate_handle_->translation_.z = 0.1; overlays_[View::GEOMETRY]->attach(rotate_handle_); } diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index f6c15b6..d7f816d 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -253,13 +253,13 @@ void UserInterface::handleKeyboard() Mixer::manager().setCurrentView(View::MIXING); else if (ImGui::IsKeyPressed( GLFW_KEY_F2 )) Mixer::manager().setCurrentView(View::GEOMETRY); - else if (ImGui::IsKeyPressed( GLFW_KEY_F12 )) + else if (ImGui::IsKeyPressed( GLFW_KEY_F11 )) Rendering::manager().ToggleFullscreen(); else if (ImGui::IsKeyPressed( GLFW_KEY_ESCAPE )){ if (Rendering::manager().IsFullscreen()) Rendering::manager().ToggleFullscreen(); } - else if (ImGui::IsKeyPressed( GLFW_KEY_PRINT_SCREEN )) + else if (ImGui::IsKeyPressed( GLFW_KEY_F12 )) toolbox.StartScreenshot(); }