From: Diane Trout Date: Wed, 11 Oct 2006 00:06:25 +0000 (+0000) Subject: use lines if a quad would be smaller than a pixel X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=4db52f646d31d4f078e145c0b23eb6fab6693d43 use lines if a quad would be smaller than a pixel closes ticket:147 Mussa looks nicer when there's a minimum width to segments connecting tracks. --- diff --git a/alg/glseqbrowser.cpp b/alg/glseqbrowser.cpp index 79acb40..3342042 100644 --- a/alg/glseqbrowser.cpp +++ b/alg/glseqbrowser.cpp @@ -1,6 +1,7 @@ #include "alg/glseqbrowser.hpp" #include "mussa_exceptions.hpp" +#include #include #include #include @@ -223,6 +224,15 @@ float GlSeqBrowser::right() const } } +float GlSeqBrowser::get_pixel_width() const +{ + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); + GLint vp_width = viewport[3]; // grab the viewport width + + return round((cur_ortho.right-cur_ortho.left)/vp_width); +} + void GlSeqBrowser::setViewportCenter(float x) { update_viewport(x, zoom_level); @@ -650,6 +660,8 @@ void GlSeqBrowser::draw_segments() const glEnable(GL_BLEND); glDepthMask(GL_FALSE); const float zdepth = -1.0; + const float min_segment_width = max((float)(1.0), get_pixel_width()); + // each vector contains path_segment_maps of all the connections // between this track and the next path_segment_map_vector::const_iterator psmv_i; @@ -695,10 +707,10 @@ void GlSeqBrowser::draw_segments() const + track_container[path_index]->x(); float seq_end_x = s.end.x + track_container[path_index+1]->x(); - if (s.length <= 1) { - // use lines for elements of length <=1. + if (s.length <= min_segment_width) { + // use lines for elements of length <=1 or < 1 pixel. // and try to center the line - const float offset = 0.5; + const float offset = s.length * 0.5; glBegin(GL_LINES); glVertex3f(seq_start_x+offset, s.start.y, -1); glVertex3f(seq_end_x +offset, s.end.y, -1); diff --git a/alg/glseqbrowser.hpp b/alg/glseqbrowser.hpp index 9b2e16f..40f158b 100644 --- a/alg/glseqbrowser.hpp +++ b/alg/glseqbrowser.hpp @@ -36,6 +36,8 @@ public: float left() const; //! max world right coordinate float right() const; + // return how wide is a pixel in world coordinates? + float get_pixel_width() const; void setViewportCenter(float x); //! return world coordinate of the left side of the viewport