LineDrawable color by vertex #1842
-
Hello, How would I go about trying to use a LineDrawable to make a line with different sections having different colors? Say I have 20 points and each 5 point section I need to be a different color? I currently have some code that uses this format: LineDrawable* LineDrawn = new LineDrawable;
DrawnLine->setLineSmooth (true);
DrawnLine->setColor (osg::Vec4 (1, 0, 1, 1));
DrawnLine->pushVertex (osg::Vec3 (0, 0, 0));
DrawnLine->pushVertex (osg::Vec3 (10, 0, 20));
DrawnLine->dirty (); I understand that setColor has an overload that allows for an index to be used (int index, osg::Vec4), but in practice I was unable to get it to work. I if I tried to add 2 more vertices and wanted them to be a different color, how would I do that? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can use Another way of building the line would be something like... line->allocate(total_num_verts);
for(int i=0; i<total_num_verts; ++i) {
line->setVertex(i, value);
line->setColor(i, color);
....
} Hope this helps! |
Beta Was this translation helpful? Give feedback.
You can use
void setColor(unsigned i, const osg::Vec4& color)
to set the color at a specific index.Another way of building the line would be something like...
Hope this helps!