Commit d89f78c6 authored by Mike Kremer's avatar Mike Kremer
Browse files

Fixed rendering of line node in LineSegments mode. If the color was set via...

Fixed rendering of line node in LineSegments mode. If the color was set via MaterialNode::set_color() function, OpenFlipper crashed when rendering the line. This was due to the fact that one was supposed to set as many colors (via add_color()) as points. It was never checked whether we reached the end of the color vector. So I changed this such that as long as colors are set for the vertices, those are used. And as soon as we reach the end of the colors vector, the last used color is set for rendering the line. If no color is set at all, it defaults to white.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@11133 383ad7c9-94d9-4d36-a494-682f7c89f535
parent d310c456
...@@ -124,13 +124,20 @@ draw(GLState& /* _state */ , const DrawModes::DrawMode& _drawMode) ...@@ -124,13 +124,20 @@ draw(GLState& /* _state */ , const DrawModes::DrawMode& _drawMode)
ConstPointIter p_it=points_.begin(), p_end=points_.end(); ConstPointIter p_it=points_.begin(), p_end=points_.end();
ConstColorIter c_it=colors_.begin(); ConstColorIter c_it=colors_.begin();
Color c((char)255, (char)255, (char)255);
if(c_it != colors_.end()) {
c = *c_it;
}
int cnt = 0; int cnt = 0;
for (; p_it!=p_end; ++p_it) for (; p_it!=p_end; ++p_it)
{ {
if ((cnt > 0) && (cnt % 2 == 0)) if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors_.end()) {
++c_it; ++c_it;
c = *c_it;
glColor(*c_it); }
glColor(c);
glVertex(*p_it); glVertex(*p_it);
++cnt; ++cnt;
......
...@@ -83,6 +83,7 @@ class ACGDLLEXPORT LineNode : public MaterialNode ...@@ -83,6 +83,7 @@ class ACGDLLEXPORT LineNode : public MaterialNode
public: public:
// typedefs // typedefs
typedef ACG::Vec3uc Color;
typedef std::vector<Vec3d> PointVector; typedef std::vector<Vec3d> PointVector;
typedef PointVector::iterator PointIter; typedef PointVector::iterator PointIter;
typedef PointVector::const_iterator ConstPointIter; typedef PointVector::const_iterator ConstPointIter;
...@@ -149,6 +150,14 @@ public: ...@@ -149,6 +150,14 @@ public:
void clear_points() { points_.clear(); } void clear_points() { points_.clear(); }
/// clear colors /// clear colors
void clear_colors() { colors_.clear(); } void clear_colors() { colors_.clear(); }
/// Override material node's set color function in order to locally add color
void set_color(const Vec4f& _c) {
add_color(ACG::Vec3uc((char)(((int)_c[0])*255),
(char)(((int)_c[1])*255),
(char)(((int)_c[2])*255)));
MaterialNode::set_color(_c);
}
/// add point (for LineMode == PolygonMode) /// add point (for LineMode == PolygonMode)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment