From f3bee81e7aaea55f7228ee463dafa2ddc482949f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 3 Mar 2004 11:17:21 +0000 Subject: [PATCH] From Ruben, Added osgpointsprite examples. --- examples/osgpointsprite/GNUmakefile | 18 ++++ examples/osgpointsprite/GNUmakefile.inst | 14 ++++ examples/osgpointsprite/osgpointsprite.cpp | 96 ++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 examples/osgpointsprite/GNUmakefile create mode 100644 examples/osgpointsprite/GNUmakefile.inst create mode 100755 examples/osgpointsprite/osgpointsprite.cpp diff --git a/examples/osgpointsprite/GNUmakefile b/examples/osgpointsprite/GNUmakefile new file mode 100644 index 000000000..4c597781e --- /dev/null +++ b/examples/osgpointsprite/GNUmakefile @@ -0,0 +1,18 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgpointsprite.cpp\ + +LIBS += -losgProducer -lProducer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +INSTFILES = \ + $(CXXFILES)\ + GNUmakefile.inst=GNUmakefile + +EXEC = osgpointsprite + +INC += $(X_INC) + +include $(TOPDIR)/Make/makerules + diff --git a/examples/osgpointsprite/GNUmakefile.inst b/examples/osgpointsprite/GNUmakefile.inst new file mode 100644 index 000000000..b56ee434d --- /dev/null +++ b/examples/osgpointsprite/GNUmakefile.inst @@ -0,0 +1,14 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgpointsprite.cpp\ + +LIBS += -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +EXEC = osgpointsprite + +INC += $(PRODUCER_INCLUDE_DIR) $(X_INC) +LDFLAGS += $(PRODUCER_LIB_DIR) + +include $(TOPDIR)/Make/makerules diff --git a/examples/osgpointsprite/osgpointsprite.cpp b/examples/osgpointsprite/osgpointsprite.cpp new file mode 100755 index 000000000..84152436e --- /dev/null +++ b/examples/osgpointsprite/osgpointsprite.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +osg::Geode *makeGalaxy(unsigned nvertices) +{ + osg::Geode *geode = new osg::Geode(); + osg::Geometry *galaxy = new osg::Geometry(); + osg::Vec3Array *vertices = new osg::Vec3Array(); + osg::Vec4Array *colors = new osg::Vec4Array(); + osg::Vec4 ini(1,1,0,1); + osg::Vec4 fin(0,0,1,1); + + /** Formula for the two spirals */ + for (unsigned i=0;ipush_back(osg::Vec3(cos(val)*val+modx1, sin(val)*val+mody1, modz1)); + vertices->push_back(osg::Vec3(-cos(val)*val+modx2, -sin(val)*val+mody2, modz2)); + + colors->push_back(ini+(fin-ini)*(i*2/(float)nvertices)); + colors->push_back(ini+(fin-ini)*(i*2/(float)nvertices)); + } + galaxy->setVertexArray(vertices); + galaxy->setColorArray(colors); + galaxy->setColorBinding(osg::Geometry::BIND_PER_VERTEX); + galaxy->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, nvertices)); + geode->addDrawable(galaxy); + return geode; +} + +osg::StateSet* makeStateSet(float size) +{ + osg::StateSet *set = new osg::StateSet(); + + /// Setup cool blending + set->setMode(GL_BLEND, osg::StateAttribute::ON); + osg::BlendFunc *fn = new osg::BlendFunc(); + fn->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::DST_ALPHA); + set->setAttributeAndModes(fn, osg::StateAttribute::ON); + + /// Setup the point sprites + osg::PointSprite *sprite = new osg::PointSprite(); + set->setTextureAttributeAndModes(0, sprite, osg::StateAttribute::ON); + + /// Give some size to the points to be able to see the sprite + osg::Point *point = new osg::Point(); + point->setSize(size); + set->setAttributeAndModes(point, osg::StateAttribute::ON); + + /// Disable depth test to avoid sort problems and Lighting + set->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); + set->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + + /// The texture for the sprites + osg::Texture2D *tex = new osg::Texture2D(); + tex->setImage(osgDB::readImageFile("Images/particle.rgb")); + set->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON); + + return set; +} + +int main(int, char *[]) +{ + osgProducer::Viewer viewer; + + /// Make the galaxy of points + osg::Node *node = makeGalaxy(5000); + + node->setStateSet(makeStateSet(10.0f)); + + viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); + viewer.setSceneData(node); + + viewer.realize(); + while (!viewer.done()) + { + viewer.sync(); + viewer.update(); + viewer.frame(); + } +} +