Commit 42a153ba authored by Henrik Zimmer's avatar Henrik Zimmer
Browse files

added Vec4f color support and blending for LineNode (in segment mode)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13397 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c91c84c5
......@@ -114,13 +114,74 @@ draw(GLState& /* _state */ , const DrawModes::DrawMode& _drawMode)
{
ACG::GLState::disable(GL_LIGHTING);
if (line_mode_ == LineSegmentsMode)
// if (line_mode_ == LineSegmentsMode)
// glBegin(GL_LINES);
// else
// glBegin(GL_LINE_STRIP);
// first check if (new standard) 4-channel colors are specified
if ((line_mode_ == LineSegmentsMode) && (points_.size()/2 == colors4f_.size()) )
{
// enable blending of lines
GLboolean blendb;
glGetBooleanv( GL_BLEND, &blendb);
glEnable(GL_BLEND);
// blend func to blend alpha values of lines
GLint sblendfunc;
GLint dblendfunc;
glGetIntegerv( GL_BLEND_SRC_ALPHA, &sblendfunc );
glGetIntegerv( GL_BLEND_DST_ALPHA, &dblendfunc );
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// blend ontop of prev. drawn mesh
GLboolean depthmaskb;
glGetBooleanv( GL_DEPTH_WRITEMASK, &depthmaskb);
glDepthMask(GL_FALSE);
glBegin(GL_LINES);
else
glBegin(GL_LINE_STRIP);
if ((line_mode_ == LineSegmentsMode) && (points_.size()/2 == colors_.size()) )
ConstPointIter p_it=points_.begin(), p_end=points_.end();
ConstColor4fIter c_it=colors4f_.begin();
Color4f c(1.0f,1.0f,1.0f,1.0f);
if(c_it != colors4f_.end()) {
c = *c_it;
}
int cnt = 0;
for (; p_it!=p_end; ++p_it)
{
if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors4f_.end()) {
++c_it;
c = *c_it;
}
glColor(c);
glVertex(*p_it);
++cnt;
}
glEnd();
// disable blending of lines
if( blendb == GL_FALSE )
glDisable(GL_BLEND);
// reset blend func
glBlendFunc( sblendfunc, dblendfunc );
// enable depth mask
if( depthmaskb == GL_TRUE )
glDepthMask(GL_TRUE);
}
else if ((line_mode_ == LineSegmentsMode) && (points_.size()/2 == colors_.size()) )
{
glBegin(GL_LINES);
ConstPointIter p_it=points_.begin(), p_end=points_.end();
ConstColorIter c_it=colors_.begin();
......@@ -142,15 +203,18 @@ draw(GLState& /* _state */ , const DrawModes::DrawMode& _drawMode)
++cnt;
}
glEnd();
}
else
{
glBegin(GL_LINE_STRIP);
ConstPointIter p_it=points_.begin(), p_end=points_.end();
for (; p_it!=p_end; ++p_it)
glVertex(*p_it);
glEnd();
}
glEnd();
//glEnd();
}
}
......
......@@ -83,13 +83,17 @@ 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;
typedef std::vector<ACG::Vec3uc> ColorVector;
typedef ColorVector::iterator ColorIter;
typedef ColorVector::const_iterator ConstColorIter;
typedef ACG::Vec3uc Color;
typedef ACG::Vec4f Color4f;
typedef std::vector<Vec3d> PointVector;
typedef PointVector::iterator PointIter;
typedef PointVector::const_iterator ConstPointIter;
typedef std::vector<ACG::Vec3uc> ColorVector;
typedef ColorVector::iterator ColorIter;
typedef ColorVector::const_iterator ConstColorIter;
typedef std::vector<Color4f> Color4fVector;
typedef Color4fVector::iterator Color4fIter;
typedef Color4fVector::const_iterator ConstColor4fIter;
/// Line mode: draw line segments (every 2 points) or ONE polyline.
enum LineMode { LineSegmentsMode, PolygonMode };
......@@ -149,7 +153,7 @@ public:
/// clear points/lines
void clear_points() { points_.clear(); }
/// clear colors
void clear_colors() { colors_.clear(); }
void clear_colors() { colors_.clear(); colors4f_.clear(); }
/// Override material node's set color function in order to locally add color
void set_color(const Vec4f& _c) {
......@@ -171,6 +175,8 @@ public:
/// add color (only for LineMode == LineSegmentsMode)
void add_color(const ACG::Vec3uc& _c) { colors_.push_back(_c); }
/// add color 4f (only for LineMode == LineSegmentsMode)
void add_color(const Color4f _c) { colors4f_.push_back(_c); }
/// number of points
unsigned int n_points() const { return points_.size(); }
......@@ -194,8 +200,9 @@ public:
protected:
PointVector points_;
ColorVector colors_;
PointVector points_;
ColorVector colors_;
Color4fVector colors4f_;
LineMode line_mode_;
......
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