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)
ConstPointIter p_it=points_.begin(), p_end=points_.end();
ConstColorIter c_it=colors_.begin();
Color c((char)255, (char)255, (char)255);
if(c_it != colors_.end()) {
c = *c_it;
}
int cnt = 0;
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;
glColor(*c_it);
c = *c_it;
}
glColor(c);
glVertex(*p_it);
++cnt;
......
......@@ -83,6 +83,7 @@ class ACGDLLEXPORT LineNode : public MaterialNode
public:
// typedefs
typedef ACG::Vec3uc Color;
typedef std::vector<Vec3d> PointVector;
typedef PointVector::iterator PointIter;
typedef PointVector::const_iterator ConstPointIter;
......@@ -149,6 +150,14 @@ public:
void clear_points() { points_.clear(); }
/// clear colors
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)
......
Markdown is supported
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