Enabling OpenGL Multisampling for antialiasing

This commit is contained in:
brunoherbelin
2020-05-16 16:01:01 +02:00
parent 22a6dc63e9
commit 610e68c697
5 changed files with 34 additions and 20 deletions

View File

@@ -425,6 +425,9 @@ void Frame::draw(glm::mat4 modelview, glm::mat4 projection)
if(shadow_) if(shadow_)
shadow_->draw( modelview * transform_, projection); shadow_->draw( modelview * transform_, projection);
// enable antialiasing
glEnable(GL_MULTISAMPLE_ARB);
// right side // right side
float ar = scale_.x / scale_.y; float ar = scale_.x / scale_.y;
glm::vec3 s(1.f, 1.f, 1.f); 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; t.x = -t.x;
s.x = -s.x; s.x = -s.x;
ctm = modelview * GlmToolkit::transform(t, rotation_, s); 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_ ) { if ( visible_ ) {
// enable antialiasing
glEnable(GL_MULTISAMPLE_ARB);
// set color // set color
handle_->shader()->color = color; handle_->shader()->color = color;
@@ -485,47 +493,49 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 projection)
if ( type_ == RESIZE ) { if ( type_ == RESIZE ) {
// 4 corners // 4 corners
ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(ar, -1.f, 0.f) ); ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(ar, -1.f, 0.f) );
ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f;
handle_->draw( ctm, projection ); handle_->draw( ctm, projection );
ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(ar, +1.f, 0.f)); ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(ar, +1.f, 0.f));
ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f;
handle_->draw( ctm, projection ); handle_->draw( ctm, projection );
ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(-ar, -1.f, 0.f)); ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(-ar, -1.f, 0.f));
ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f;
handle_->draw( ctm, projection ); handle_->draw( ctm, projection );
ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(-ar, +1.f, 0.f)); ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(-ar, +1.f, 0.f));
ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f;
handle_->draw( ctm, projection ); handle_->draw( ctm, projection );
} }
else if ( type_ == RESIZE_H ){ else if ( type_ == RESIZE_H ){
// left and right // left and right
ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(ar, 0.f, 0.f) ); ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(ar, 0.f, 0.f) );
ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f;
handle_->draw( ctm, projection ); handle_->draw( ctm, projection );
ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(-ar, 0.f, 0.f)); ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(-ar, 0.f, 0.f));
ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f;
handle_->draw( ctm, projection ); handle_->draw( ctm, projection );
} }
else if ( type_ == RESIZE_V ){ else if ( type_ == RESIZE_V ){
// top and bottom // top and bottom
ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(0.f, +1.f, 0.f) ); ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(0.f, +1.f, 0.f) );
ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f;
handle_->draw( ctm, projection ); handle_->draw( ctm, projection );
ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(0.f, -1.f, 0.f)); ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(0.f, -1.f, 0.f));
ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f;
handle_->draw( ctm, projection ); handle_->draw( ctm, projection );
} }
else if ( type_ == ROTATE ){ else if ( type_ == ROTATE ){
// only once in upper top right corner // only once in upper top right corner
ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(ar + 0.06f, +1.06f, 0.f)); ctm = modelview * glm::translate(glm::identity<glm::mat4>(), glm::vec3(ar + 0.06f, +1.06f, 0.f));
ctm[0][0] = ctm[1][1] = ctm[2][2] = 1.f;
handle_->draw( ctm, projection ); handle_->draw( ctm, projection );
} }
glDisable(GL_MULTISAMPLE_ARB);
} }
} }

View File

@@ -251,10 +251,12 @@ void LineStrip::draw(glm::mat4 modelview, glm::mat4 projection)
init(); init();
glLineWidth(linewidth_); glLineWidth(linewidth_);
glEnable(GL_LINE_SMOOTH);
Primitive::draw(modelview, projection); Primitive::draw(modelview, projection);
glLineWidth(1); glLineWidth(1);
glDisable(GL_LINE_SMOOTH);
} }
void LineStrip::accept(Visitor& v) void LineStrip::accept(Visitor& v)

View File

@@ -87,9 +87,13 @@ bool Rendering::Init()
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
#endif #endif
Settings::WindowConfig winset = Settings::application.windows.front(); Settings::WindowConfig winset = Settings::application.windows.front();
// Create window with graphics context // Create window with graphics context
// GL Multisampling #3
glfwWindowHint(GLFW_SAMPLES, 3);
// do not show at creation
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
// glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
main_window_ = glfwCreateWindow(winset.w, winset.h, winset.name.c_str(), NULL, NULL); main_window_ = glfwCreateWindow(winset.w, winset.h, winset.name.c_str(), NULL, NULL);
@@ -139,9 +143,8 @@ bool Rendering::Init()
gst_init (NULL, NULL); gst_init (NULL, NULL);
// Antialiasing // Antialiasing
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); 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 // This hint can improve the speed of texturing when perspective-correct texture coordinate interpolation isn't needed
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
// This hint can improve the speed of shading when dFdx dFdy aren't needed in GLSL // This hint can improve the speed of shading when dFdx dFdy aren't needed in GLSL

View File

@@ -44,7 +44,7 @@ Source::Source(const std::string &name) : name_(name), initialized_(false)
groups_[View::GEOMETRY]->attach(frame); groups_[View::GEOMETRY]->attach(frame);
overlays_[View::GEOMETRY] = new Group; overlays_[View::GEOMETRY] = new Group;
overlays_[View::GEOMETRY]->translation_.z = 0.1; overlays_[View::GEOMETRY]->translation_.z = 0.15;
overlays_[View::GEOMETRY]->visible_ = false; overlays_[View::GEOMETRY]->visible_ = false;
groups_[View::GEOMETRY]->attach(overlays_[View::GEOMETRY]); 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 // extra overlays for geometry view
frame = new Frame(Frame::SHARP_LARGE); frame = new Frame(Frame::SHARP_LARGE);
frame->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); frame->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f);
frame->translation_.z = 0.1;
overlays_[View::GEOMETRY]->attach(frame); overlays_[View::GEOMETRY]->attach(frame);
resize_handle_ = new Handles(Handles::RESIZE); resize_handle_ = new Handles(Handles::RESIZE);
resize_handle_->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); 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_); overlays_[View::GEOMETRY]->attach(resize_handle_);
resize_H_handle_ = new Handles(Handles::RESIZE_H); 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_->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_); overlays_[View::GEOMETRY]->attach(resize_H_handle_);
resize_V_handle_ = new Handles(Handles::RESIZE_V); 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_->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_); overlays_[View::GEOMETRY]->attach(resize_V_handle_);
rotate_handle_ = new Handles(Handles::ROTATE); rotate_handle_ = new Handles(Handles::ROTATE);
rotate_handle_->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); 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_); overlays_[View::GEOMETRY]->attach(rotate_handle_);
} }

View File

@@ -253,13 +253,13 @@ void UserInterface::handleKeyboard()
Mixer::manager().setCurrentView(View::MIXING); Mixer::manager().setCurrentView(View::MIXING);
else if (ImGui::IsKeyPressed( GLFW_KEY_F2 )) else if (ImGui::IsKeyPressed( GLFW_KEY_F2 ))
Mixer::manager().setCurrentView(View::GEOMETRY); Mixer::manager().setCurrentView(View::GEOMETRY);
else if (ImGui::IsKeyPressed( GLFW_KEY_F12 )) else if (ImGui::IsKeyPressed( GLFW_KEY_F11 ))
Rendering::manager().ToggleFullscreen(); Rendering::manager().ToggleFullscreen();
else if (ImGui::IsKeyPressed( GLFW_KEY_ESCAPE )){ else if (ImGui::IsKeyPressed( GLFW_KEY_ESCAPE )){
if (Rendering::manager().IsFullscreen()) if (Rendering::manager().IsFullscreen())
Rendering::manager().ToggleFullscreen(); Rendering::manager().ToggleFullscreen();
} }
else if (ImGui::IsKeyPressed( GLFW_KEY_PRINT_SCREEN )) else if (ImGui::IsKeyPressed( GLFW_KEY_F12 ))
toolbox.StartScreenshot(); toolbox.StartScreenshot();
} }