Hello,
I have an array of 3d points that I want to render in a scene. I want to render them as circles, centered on each point coordinates, with a given radius and a color that is given by a color array I have in memory.
For now, I am creating a node for each point, that consists of a PrimitiveSet (polygon) that I iterate around the point center. (Check code below).
Now I know this can be done with Shaders. I can draw the circle directly in the fragment shader with this example (
http://www.geeks3d.com/20130705/shader-library-circle-disc-fake-sphere-in-glsl-opengl-glslhacker/).
But I need to pass the vertex centers and respective colors. Is it possible to pass a osg::Vec3Array* with vertex centers and a osg::Vec4Array* of colors directly to a Shader, so that I can , in a single compiled Shader program, handle all point positions and colors?
Here is teh code for drawing the circle, I use this for each vertex:
osg::Vec3Array* getArray(const float radius, const int points, const osg::Vec3& center) {
auto array = new osg::Vec3Array();
const float ratio = (float(2.0*osg::PI) / float(points));
for (int i = 0; i < points; i++) {
const float angle = float(i) * ratio;
array->push_back(osg::Vec3(
center.x() + radius*cosf( angle ),
center.y() + radius*sinf( angle ),
center.z())
);
}
return array;
}
osg::Geometry* getGeometry(const float radius, const int points, const osg::Vec3& center) {
osg::Geometry* geom = new osg::Geometry();
geom->setVertexArray(getArray(radius, points, center));
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, 0, points));
return geom;
}