diff --git a/examples/osganimate/osganimate.cpp b/examples/osganimate/osganimate.cpp index d3c1346e8..b6cf5eb86 100644 --- a/examples/osganimate/osganimate.cpp +++ b/examples/osganimate/osganimate.cpp @@ -38,46 +38,46 @@ osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime) { - // set up the animation path + // set up the animation path osg::AnimationPath* animationPath = new osg::AnimationPath; animationPath->setLoopMode(osg::AnimationPath::LOOP); - + int numSamples = 40; float yaw = 0.0f; float yaw_delta = 2.0f*osg::PI/((float)numSamples-1.0f); float roll = osg::inDegrees(30.0f); - + double time=0.0f; double time_delta = looptime/(double)numSamples; for(int i=0;iinsert(time,osg::AnimationPath::ControlPoint(position,rotation)); yaw += yaw_delta; time += time_delta; } - return animationPath; + return animationPath; } osg::Node* createBase(const osg::Vec3& center,float radius) { - + int numTilesX = 10; int numTilesY = 10; - + float width = 2*radius; float height = 2*radius; - + osg::Vec3 v000(center - osg::Vec3(width*0.5f,height*0.5f,0.0f)); osg::Vec3 dx(osg::Vec3(width/((float)numTilesX),0.0,0.0f)); osg::Vec3 dy(osg::Vec3(0.0f,height/((float)numTilesY),0.0f)); - + // fill in vertices for grid, note numTilesX+1 * numTilesY+1... osg::Vec3Array* coords = new osg::Vec3Array; int iy; @@ -88,15 +88,15 @@ osg::Node* createBase(const osg::Vec3& center,float radius) coords->push_back(v000+dx*(float)ix+dy*(float)iy); } } - + //Just two colours - black and white. osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); // white colors->push_back(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); // black - + osg::ref_ptr whitePrimitives = new osg::DrawElementsUShort(GL_QUADS); osg::ref_ptr blackPrimitives = new osg::DrawElementsUShort(GL_QUADS); - + int numIndicesPerRow=numTilesX+1; for(iy=0;iysetVertexArray(coords); - - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET); - - geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); - + + geom->setColorArray(colors, osg::Array::BIND_PER_PRIMITIVE_SET); + + geom->setNormalArray(normals, osg::Array::BIND_OVERALL); + geom->addPrimitiveSet(whitePrimitives.get()); geom->addPrimitiveSet(blackPrimitives.get()); - + osg::Geode* geode = new osg::Geode; geode->addDrawable(geom); - + return geode; } @@ -151,16 +149,16 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) positioned->setMatrix(osg::Matrix::translate(-bs.center())* osg::Matrix::scale(size,size,size)* osg::Matrix::rotate(osg::inDegrees(-90.0f),0.0f,0.0f,1.0f)); - + positioned->addChild(glider); - - osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform; + + osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform; xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0,1.0)); xform->addChild(positioned); model->addChild(xform); } - + osg::Node* cessna = osgDB::readNodeFile("cessna.osgt"); if (cessna) { @@ -172,16 +170,16 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius) positioned->setMatrix(osg::Matrix::translate(-bs.center())* osg::Matrix::scale(size,size,size)* osg::Matrix::rotate(osg::inDegrees(180.0f),0.0f,0.0f,1.0f)); - + positioned->addChild(cessna); - + osg::MatrixTransform* xform = new osg::MatrixTransform; xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0f,2.0)); xform->addChild(positioned); model->addChild(xform); } - + return model; } @@ -207,10 +205,10 @@ osg::Node* createModel(bool overlay, osgSim::OverlayNode::OverlayTechnique techn } else { - + root->addChild(baseModel); } - + root->addChild(movingModel); return root; @@ -219,16 +217,16 @@ osg::Node* createModel(bool overlay, osgSim::OverlayNode::OverlayTechnique techn int main( int argc, char **argv ) { - + bool overlay = false; osg::ArgumentParser arguments(&argc,argv); while (arguments.read("--overlay")) overlay = true; - + osgSim::OverlayNode::OverlayTechnique technique = osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; while (arguments.read("--object")) { technique = osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; overlay=true; } while (arguments.read("--ortho") || arguments.read("--orthographic")) { technique = osgSim::OverlayNode::VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; overlay=true; } while (arguments.read("--persp") || arguments.read("--perspective")) { technique = osgSim::OverlayNode::VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY; overlay=true; } - + // initialize the viewer. osgViewer::Viewer viewer; @@ -239,7 +237,7 @@ int main( int argc, char **argv ) { return 1; } - + // tilt the scene so the default eye position is looking down on the model. osg::MatrixTransform* rootnode = new osg::MatrixTransform; rootnode->setMatrix(osg::Matrix::rotate(osg::inDegrees(30.0f),1.0f,0.0f,0.0f)); @@ -248,7 +246,7 @@ int main( int argc, char **argv ) // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize(rootnode); - + // set the scene to render viewer.setSceneData(rootnode); @@ -259,17 +257,17 @@ int main( int argc, char **argv ) #if 0 // use of custom simulation time. - + viewer.realize(); - + double simulationTime = 0.0; - + while (!viewer.done()) { viewer.frame(simulationTime); simulationTime += 0.001; } - + return 0; #else diff --git a/examples/osganimationnode/osganimationnode.cpp b/examples/osganimationnode/osganimationnode.cpp index bf7d6632a..2ded576e6 100644 --- a/examples/osganimationnode/osganimationnode.cpp +++ b/examples/osganimationnode/osganimationnode.cpp @@ -1,14 +1,14 @@ -/* -*-c++-*- +/* -*-c++-*- * Copyright (C) 2008 Cedric Pinson * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ @@ -27,7 +27,7 @@ class AnimtkUpdateCallback : public osg::NodeCallback public: META_Object(osgAnimation, AnimtkUpdateCallback); - AnimtkUpdateCallback() + AnimtkUpdateCallback() { _sampler = new osgAnimation::Vec3CubicBezierSampler; _playing = false; @@ -46,9 +46,9 @@ public: /** Callback method called by the NodeVisitor when visiting a node.*/ virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) - { - if (nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR && - nv->getFrameStamp() && + { + if (nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR && + nv->getFrameStamp() && nv->getFrameStamp()->getFrameNumber() != _lastUpdate) { _lastUpdate = nv->getFrameStamp()->getFrameNumber(); @@ -89,7 +89,7 @@ class AnimtkStateSetUpdateCallback : public osg::StateSet::Callback public: META_Object(osgAnimation, AnimtkStateSetUpdateCallback); - AnimtkStateSetUpdateCallback() + AnimtkStateSetUpdateCallback() { _sampler = new osgAnimation::Vec4LinearSampler; _playing = false; @@ -109,20 +109,20 @@ public: /** Callback method called by the NodeVisitor when visiting a node.*/ virtual void operator()(osg::StateSet* state, osg::NodeVisitor* nv) - { - if (state && - nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR && - nv->getFrameStamp() && - nv->getFrameStamp()->getFrameNumber() != _lastUpdate) + { + if (state && + nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR && + nv->getFrameStamp() && + nv->getFrameStamp()->getFrameNumber() != _lastUpdate) { _lastUpdate = nv->getFrameStamp()->getFrameNumber(); _currentTime = osg::Timer::instance()->tick(); - if (_playing && _sampler.get() && _sampler->getKeyframeContainer()) + if (_playing && _sampler.get() && _sampler->getKeyframeContainer()) { osg::Material* material = dynamic_cast(state->getAttribute(osg::StateAttribute::MATERIAL)); - if (material) + if (material) { osg::Vec4 result; float t = osg::Timer::instance()->delta_s(_startTime, _currentTime); @@ -149,7 +149,7 @@ public: osg::Geode* createAxis() { - osg::Geode* geode = new osg::Geode; + osg::Geode* geode = new osg::Geode; osg::ref_ptr geometry (new osg::Geometry()); osg::ref_ptr vertices (new osg::Vec3Array()); @@ -168,9 +168,7 @@ osg::Geode* createAxis() colors->push_back (osg::Vec4 (0.0f, 1.0f, 0.0f, 1.0f)); colors->push_back (osg::Vec4 (0.0f, 0.0f, 1.0f, 1.0f)); colors->push_back (osg::Vec4 (0.0f, 0.0f, 1.0f, 1.0f)); - geometry->setColorArray (colors.get()); - - geometry->setColorBinding (osg::Geometry::BIND_PER_VERTEX); + geometry->setColorArray (colors.get(), osg::Array::BIND_PER_VERTEX); geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6)); geode->addDrawable( geometry.get() ); @@ -217,7 +215,7 @@ osg::MatrixTransform* setupAnimtkNode() osgAnimation::Vec3CubicBezierKeyframeContainer* keys = callback->_sampler->getOrCreateKeyframeContainer(); keys->push_back(osgAnimation::Vec3CubicBezierKeyframe(0, osgAnimation::Vec3CubicBezier( v[0], // pos - v[0] + (v[0] - v[3]), // p1 + v[0] + (v[0] - v[3]), // p1 v[1] - (v[1] - v[0]) // p2 ))); keys->push_back(osgAnimation::Vec3CubicBezierKeyframe(2, osgAnimation::Vec3CubicBezier( @@ -254,7 +252,7 @@ int main (int argc, char* argv[]) osgGA::TrackballManipulator* manipulator = new osgGA::TrackballManipulator(); viewer.setCameraManipulator(manipulator); - + osg::Group* root = new osg::Group; root->setInitialBound(osg::BoundingSphere(osg::Vec3(10,0,10), 30)); root->addChild(createAxis()); @@ -266,7 +264,7 @@ int main (int argc, char* argv[]) viewer.setSceneData( root ); viewer.realize(); - while (!viewer.done()) + while (!viewer.done()) { viewer.frame(); } diff --git a/examples/osgautotransform/osgautotransform.cpp b/examples/osgautotransform/osgautotransform.cpp index 02184ac77..0d1c1bb9e 100644 --- a/examples/osgautotransform/osgautotransform.cpp +++ b/examples/osgautotransform/osgautotransform.cpp @@ -37,7 +37,7 @@ osg::Node* createLabel(const osg::Vec3& pos, float size, const std::string& label, osgText::Text::AxisAlignment axisAlignment) { osg::Geode* geode = new osg::Geode(); - + std::string timesFont("fonts/arial.ttf"); { @@ -50,17 +50,17 @@ osg::Node* createLabel(const osg::Vec3& pos, float size, const std::string& labe text->setAxisAlignment(axisAlignment); text->setAlignment(osgText::Text::CENTER_CENTER); text->setText(label); - + } - - return geode; + + return geode; } osg::Node* createLabel3(const osg::Vec3& pos, float size, const std::string& label) { osg::Geode* geode = new osg::Geode(); - + std::string timesFont("fonts/arial.ttf"); { @@ -75,10 +75,10 @@ osg::Node* createLabel3(const osg::Vec3& pos, float size, const std::string& lab text->setAutoRotateToScreen(true); text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT); text->setText(label); - + } - - return geode; + + return geode; } osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps, osg::AutoTransform::AutoRotateMode autoRotateMode, osgText::Text::AxisAlignment axisAlignment, const std::string& str) @@ -113,8 +113,7 @@ osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps, osg:: osg::Geometry* geom = new osg::Geometry; geom->setVertexArray(vertices); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size())); osg::Geode* geode = new osg::Geode; @@ -140,8 +139,7 @@ osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps, osg:: osg::Geometry* geom = new osg::Geometry; geom->setVertexArray(vertices); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size())); osg::Geode* geode = new osg::Geode; @@ -149,7 +147,7 @@ osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps, osg:: group->addChild(geode); } - + return group; } @@ -169,25 +167,25 @@ osg::Node* createAutoScale(const osg::Vec3& position, float characterSize, const osg::AutoTransform* at = new osg::AutoTransform; at->addChild(geode); - + at->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN); at->setAutoScaleToScreen(true); at->setMinimumScale(minScale); at->setMaximumScale(maxScale); at->setPosition(position); - + return at; } osg::Node* createScene() { osg::Group* root = new osg::Group; - + // int numReps = 3333; int numReps = 10; root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(1000.0,0.0,0.0),numReps,osg::AutoTransform::ROTATE_TO_CAMERA,osgText::Text::XY_PLANE, "ROTATE_TO_CAMERA")); root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,1000.0,0.0),numReps,osg::AutoTransform::ROTATE_TO_SCREEN,osgText::Text::XY_PLANE, "ROTATE_TO_SCREEN")); - root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,0.0,1000.0),numReps,osg::AutoTransform::NO_ROTATION,osgText::Text::XZ_PLANE, "NO_ROTATION")); + root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,0.0,1000.0),numReps,osg::AutoTransform::NO_ROTATION,osgText::Text::XZ_PLANE, "NO_ROTATION")); root->addChild(createAutoScale(osg::Vec3(500.0,500.0,500.0), 25.0, "AutoScale with no min, max limits")); root->addChild(createAutoScale(osg::Vec3(500.0,500.0,300.0), 25.0, "AutoScale with minScale = 1, maxScale = 2.0 ", 1, 2.0)); @@ -202,7 +200,7 @@ int main(int, char**) // set the scene to render viewer.setSceneData(createScene()); - + // run the viewers frame loop return viewer.run(); } diff --git a/examples/osgbillboard/osgbillboard.cpp b/examples/osgbillboard/osgbillboard.cpp index 632000be0..ef111d6df 100644 --- a/examples/osgbillboard/osgbillboard.cpp +++ b/examples/osgbillboard/osgbillboard.cpp @@ -6,7 +6,7 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: -* +* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -34,7 +34,7 @@ #include // -// A simple demo demonstrating different texturing modes, +// A simple demo demonstrating different texturing modes, // including using of texture extensions. // @@ -59,9 +59,8 @@ osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3Array* norms = new osg::Vec3Array(1); (*norms)[0] = width^height; (*norms)[0].normalize(); - - geom->setNormalArray(norms); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); + + geom->setNormalArray(norms, osg::Array::BIND_OVERALL); osg::Vec2Array* tcoords = new osg::Vec2Array(4); (*tcoords)[0].set(0.0f,0.0f); @@ -69,9 +68,9 @@ osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const (*tcoords)[2].set(1.0f,1.0f); (*tcoords)[3].set(0.0f,1.0f); geom->setTexCoordArray(0,tcoords); - + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); - + if (image) { osg::StateSet* stateset = new osg::StateSet; @@ -80,7 +79,7 @@ osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); geom->setStateSet(stateset); } - + return geom; } @@ -110,19 +109,18 @@ osg::Drawable* createAxis(const osg::Vec3& corner,const osg::Vec3& xdir,const os (*color)[3] = y_color; (*color)[4] = z_color; (*color)[5] = z_color; - - geom->setColorArray(color); - geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); - + + geom->setColorArray(color, osg::Array::BIND_PER_VERTEX); + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6)); - + osg::StateSet* stateset = new osg::StateSet; osg::LineWidth* linewidth = new osg::LineWidth(); linewidth->setWidth(4.0f); stateset->setAttributeAndModes(linewidth,osg::StateAttribute::ON); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); geom->setStateSet(stateset); - + return geom; } @@ -138,7 +136,7 @@ osg::Node* createModel() center->addDrawable( createSquare(osg::Vec3(-0.5f,0.0f,-0.5f),osg::Vec3(1.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f),osgDB::readImageFile("Images/reflect.rgb")), osg::Vec3(0.0f,0.0f,0.0f)); - + osg::Billboard* x_arrow = new osg::Billboard(); x_arrow->setMode(osg::Billboard::AXIAL_ROT); x_arrow->setAxis(osg::Vec3(1.0f,0.0f,0.0f)); @@ -182,7 +180,7 @@ int main(int, char**) { // construct the viewer osgViewer::Viewer viewer; - + // set the scene to render viewer.setSceneData(createModel()); diff --git a/examples/osgdelaunay/osgdelaunay.cpp b/examples/osgdelaunay/osgdelaunay.cpp index ad064abe0..72a8ff466 100644 --- a/examples/osgdelaunay/osgdelaunay.cpp +++ b/examples/osgdelaunay/osgdelaunay.cpp @@ -836,8 +836,7 @@ osg::Geometry *WallConstraint::makeWallGeometry() const gm->setVertexArray(getWall(height)); gm->addPrimitiveSet(makeWall()); gm->setTexCoordArray(0,getWallTexcoords(height)); - gm->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); - gm->setNormalArray(getWallNormals()); // this creates normals to walls + gm->setNormalArray(getWallNormals(), osg::Array::BIND_PER_VERTEX); // this creates normals to walls return gm.release(); } diff --git a/examples/osgdepthpartition/osgdepthpartition.cpp b/examples/osgdepthpartition/osgdepthpartition.cpp index 3d18ed944..14f1da2cc 100644 --- a/examples/osgdepthpartition/osgdepthpartition.cpp +++ b/examples/osgdepthpartition/osgdepthpartition.cpp @@ -46,7 +46,7 @@ osg::Node* createScene() osg::Geode* earth_geode = new osg::Geode; earth_geode->setName("EarthGeode"); earth_geode->addDrawable(earth_sd); - + // Create the Sun, in yellow osg::ShapeDrawable *sun_sd = new osg::ShapeDrawable; osg::Sphere* sun_sphere = new osg::Sphere; @@ -63,13 +63,12 @@ osg::Node* createScene() osg::PositionAttitudeTransform *pat = new osg::PositionAttitudeTransform; pat->setPosition(osg::Vec3d(0.0, AU, 0.0)); pat->addChild(sun_geode); - + osg::Geometry * unitCircle = new osg::Geometry(); { osg::Vec4Array * colours = new osg::Vec4Array(1); (*colours)[0] = osg::Vec4d(1.0,1.0,1.0,1.0); - unitCircle->setColorArray(colours); - unitCircle->setColorBinding(osg::Geometry::BIND_OVERALL); + unitCircle->setColorArray(colours, osg::Array::BIND_OVERALL); const unsigned int n_points = 1024; osg::Vec3Array * coords = new osg::Vec3Array(n_points); const double dx = 2.0*osg::PI/n_points; @@ -88,8 +87,7 @@ osg::Node* createScene() { osg::Vec4Array *colours = new osg::Vec4Array(1); (*colours)[0] = osg::Vec4d(1.0,0.0,0.0,1.0); - axes->setColorArray(colours); - axes->setColorBinding(osg::Geometry::BIND_OVERALL); + axes->setColorArray(colours, osg::Array::BIND_OVERALL); osg::Vec3Array *coords = new osg::Vec3Array(6); (*coords)[0].set(osg::Vec3d(0.0, 0.0, 0.0)); (*coords)[1].set(osg::Vec3d(0.5, 0.0, 0.0)); @@ -101,25 +99,25 @@ osg::Node* createScene() axes->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); axes->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6)); } - + // Earth orbit osg::Geode * earthOrbitGeode = new osg::Geode; earthOrbitGeode->addDrawable(unitCircle); earthOrbitGeode->addDrawable(axes); earthOrbitGeode->setName("EarthOrbitGeode"); - + osg::PositionAttitudeTransform * earthOrbitPAT = new osg::PositionAttitudeTransform; earthOrbitPAT->setScale(osg::Vec3d(AU,AU,AU)); earthOrbitPAT->setPosition(osg::Vec3d(0.0, AU, 0.0)); earthOrbitPAT->addChild(earthOrbitGeode); earthOrbitPAT->setName("EarthOrbitPAT"); - + osg::Group* scene = new osg::Group; scene->setName("SceneGroup"); scene->addChild(earth_geode); scene->addChild(pat); scene->addChild(earthOrbitPAT); - + return scene; } @@ -144,9 +142,9 @@ int main( int argc, char **argv ) osg::ref_ptr scene = osgDB::readNodeFiles(arguments); // if one hasn't been loaded create an earth and sun test model. - if (!scene) + if (!scene) { - scene = createScene(); + scene = createScene(); needToSetHomePosition = true; } // pass the loaded scene graph to the viewer. @@ -158,7 +156,7 @@ int main( int argc, char **argv ) { viewer.getCameraManipulator()->setHomePosition(osg::Vec3d(0.0,-5.0*r_earth,0.0),osg::Vec3d(0.0,0.0,0.0),osg::Vec3d(0.0,0.0,1.0)); } - + double zNear=1.0, zMid=10.0, zFar=1000.0; if (arguments.read("--depth-partition",zNear, zMid, zFar)) { @@ -175,7 +173,7 @@ int main( int argc, char **argv ) // set up depth partitioning with default settings viewer.setUpDepthPartition(); } - + return viewer.run(); } diff --git a/examples/osgdepthpeeling/DePee.cpp b/examples/osgdepthpeeling/DePee.cpp index 059e74363..c3c4ab405 100644 --- a/examples/osgdepthpeeling/DePee.cpp +++ b/examples/osgdepthpeeling/DePee.cpp @@ -27,48 +27,48 @@ DePee::DePee(osg::Group* parent, osg::Group* subgraph, unsigned width, unsigned height) { _renderToFirst = false; - + _isSketchy =false; _isColored = false; _isEdgy = true; _isCrayon = false; - + _normalDepthMapProgram = Utility::createProgram("shaders/depthpeel_normaldepthmap.vert","shaders/depthpeel_normaldepthmap.frag"); _colorMapProgram = Utility::createProgram("shaders/depthpeel_colormap.vert","shaders/depthpeel_colormap.frag" ); _edgeMapProgram = Utility::createProgram("shaders/depthpeel_edgemap.vert", "shaders/depthpeel_edgemap.frag"); - + _parent = new osg::Group; parent->addChild(_parent.get()); _subgraph = subgraph; - + _width = width; _height = height; _texWidth = width; _texHeight = height; - + assert(parent); assert(subgraph); _fps = 0; _colorCamera = 0; - + _sketchy = new osg::Uniform("sketchy", false); _colored = new osg::Uniform("colored", false); _edgy = new osg::Uniform("edgy", true); _sketchiness = new osg::Uniform("sketchiness", (float) 1.0); - + _normalDepthMap0 = Utility::newColorTexture2D(_texWidth, _texHeight, 32); _normalDepthMap1 = Utility::newColorTexture2D(_texWidth, _texHeight, 32); _edgeMap = Utility::newColorTexture2D(_texWidth, _texHeight, 8); _colorMap = Utility::newColorTexture2D(_texWidth, _texHeight, 8); - + //create a noise map...this doesn't end up in a new rendering pass (void) createMap(NOISE_MAP); //the viewport aligned quad _quadGeode = Utility::getCanvasQuad(_width, _height); - - + + //!!!Getting problems if assigning unit to texture in depth peeling subgraph and removing depth peeling steps!!! //That's why it is done here osg::StateSet* stateset = _parent->getOrCreateStateSet(); @@ -77,12 +77,12 @@ DePee::DePee(osg::Group* parent, osg::Group* subgraph, unsigned width, unsigned stateset->setTextureAttributeAndModes(3, _edgeMap.get(), osg::StateAttribute::ON); stateset->setTextureAttributeAndModes(4, _colorMap.get(), osg::StateAttribute::ON); stateset->setTextureAttributeAndModes(5, _noiseMap.get(), osg::StateAttribute::ON); - + // render the final thing (void) createFinal(); - + //take one step initially - addDePeePass(); + addDePeePass(); //render head up display (void) createHUD(); @@ -111,7 +111,7 @@ void DePee::setSketchiness(double sketchiness) { _sketchiness->set((float)sketchiness); } - + void DePee::setColored(bool colored) { if(colored == !_isColored) @@ -128,20 +128,20 @@ void DePee::setColored(bool colored) _isColored = colored; } } - + void DePee::setEdgy(bool edgy) { - + if(edgy != _isEdgy) { - + _isEdgy = edgy; unsigned int n = 0; while(remDePeePass()) { ++n; } - + if(edgy) { (void) createMap(EDGE_MAP,_dePeePasses.size() == 1); @@ -150,7 +150,7 @@ void DePee::setEdgy(bool edgy) { _dePeePasses.back()->remRenderPass(EDGE_MAP); } - + for(unsigned int i=0; i < n; i++) { addDePeePass(); @@ -158,8 +158,8 @@ void DePee::setEdgy(bool edgy) } _edgy->set(edgy); } - - + + void DePee::setFPS(double* fps) { @@ -177,29 +177,29 @@ unsigned int DePee::getNumberOfRenderPasses() bool DePee::addDePeePass() { - + if(_isColored) { //remove previous color pass _dePeePasses.back()->remRenderPass(COLOR_MAP); } - + _dePeePasses.push_back(new DePeePass()); _parent->addChild(_dePeePasses.back()->root.get()); - + //need to create a depth map in every case (void) createMap(NORMAL_DEPTH_MAP, _dePeePasses.size() == 1); - + if(_isEdgy) { (void) createMap(EDGE_MAP,_dePeePasses.size() == 1); } - + if(_isColored) { (void) createMap(COLOR_MAP, false); } - + return true; } @@ -213,12 +213,12 @@ bool DePee::remDePeePass() _dePeePasses.pop_back(); _renderToFirst = !_renderToFirst; - + if(_isColored) { (void) createMap(COLOR_MAP, false); } - + return true; } @@ -234,11 +234,11 @@ bool DePee::createNoiseMap() _noiseMap->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); stateset->setTextureAttributeAndModes(5, _noiseMap.get(), osg::StateAttribute::ON); } - + osg::Image* image = new osg::Image; unsigned char* data = new unsigned char[_width*_height]; unsigned char* tmpData = new unsigned char[_width*_height]; - + int random=rand() % 5000; for(unsigned y=0; y < _height; y++) for(unsigned x=0; x < _width; x++) @@ -258,10 +258,10 @@ bool DePee::createNoiseMap() data[y*_width + x] = (unsigned char)Utility::smoothNoise(_width, _height, x,y, tmpData); } } - - image->setImage(_width, _height, 1, - 1, GL_LUMINANCE, GL_UNSIGNED_BYTE, - data, + + image->setImage(_width, _height, 1, + 1, GL_LUMINANCE, GL_UNSIGNED_BYTE, + data, osg::Image::USE_NEW_DELETE); _noiseMap->setImage(image); return true; @@ -270,24 +270,24 @@ bool DePee::createNoiseMap() bool DePee::createHUD() { osg::Geode* geode = new osg::Geode(); - + std::string timesFont("fonts/arial.ttf"); // turn lighting off for the text and disable depth test to ensure its always ontop. osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - + stateset->setTextureAttributeAndModes(1, _normalDepthMap0.get(), osg::StateAttribute::OFF); stateset->setTextureAttributeAndModes(2, _normalDepthMap1.get(), osg::StateAttribute::OFF); stateset->setTextureAttributeAndModes(3, _edgeMap.get(), osg::StateAttribute::OFF); stateset->setTextureAttributeAndModes(4, _colorMap.get(), osg::StateAttribute::OFF); stateset->setTextureAttributeAndModes(5, _noiseMap.get(), osg::StateAttribute::OFF); - + osg::Vec3 position(5.0f,7.0f,0.0f); osg::Vec3 delta(0.0f,-120.0f,0.0f); _hudText = new osgText::Text; - + { geode->addDrawable( _hudText ); _hudText->setDataVariance(osg::Object::DYNAMIC); @@ -298,16 +298,16 @@ bool DePee::createHUD() _hudText->setCharacterSize(20.0); position += delta; } - + { osg::BoundingBox bb; for(unsigned int i=0;igetNumDrawables();++i) { bb.expandBy(geode->getDrawable(i)->getBound()); } - + osg::Geometry* geom = new osg::Geometry; - + osg::Vec3Array* vertices = new osg::Vec3Array; float depth = bb.zMin()-0.1; vertices->push_back(osg::Vec3(bb.xMin(),bb.yMax(),depth)); @@ -315,24 +315,22 @@ bool DePee::createHUD() vertices->push_back(osg::Vec3(bb.xMax(),bb.yMin(),depth)); vertices->push_back(osg::Vec3(bb.xMax(),bb.yMax(),depth)); geom->setVertexArray(vertices); - + osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,0.0f,1.0f)); - geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); - + geom->setNormalArray(normals, osg::Array::BIND_OVERALL); + osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(0.0f,0.0,0.0f,0.3f)); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); - + geom->setColorArray(colors, osg::Array::BIND_OVERALL); + geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); - + osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setMode(GL_BLEND,osg::StateAttribute::ON); - + stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - + //geode->addDrawable(geom); } @@ -341,7 +339,7 @@ bool DePee::createHUD() // set the projection matrix camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); - // set the view matrix + // set the view matrix camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setViewMatrix(osg::Matrix::identity()); @@ -352,19 +350,19 @@ bool DePee::createHUD() camera->setRenderOrder(osg::Camera::POST_RENDER); camera->addChild(geode); - + _parent->addChild(camera); - + return true; } - + // then create the first camera node to do the render to texture // render normal and depth map color map bool DePee::createMap(MapMode mapMode, bool first) - { + { switch(mapMode) { case EDGE_MAP: @@ -377,13 +375,13 @@ bool DePee::createMap(MapMode mapMode, bool first) default: std::cerr << "mapMode not recognized!!!\n"; return false; - } + } } bool DePee::createFinal() { osg::Projection* screenAlignedProjectionMatrix = new osg::Projection; - + screenAlignedProjectionMatrix->setMatrix(osg::Matrix::ortho2D(0,_width,0,_height)); screenAlignedProjectionMatrix->setCullingActive(false); @@ -393,20 +391,20 @@ bool DePee::createFinal() // Make sure the model view matrix is not affected by any transforms // above it in the scene graph: screenAlignedModelViewMatrix->setReferenceFrame(osg::Transform::ABSOLUTE_RF); - - // new we need to add the texture to the Drawable, we do so by creating a + + // new we need to add the texture to the Drawable, we do so by creating a // StateSet to contain the Texture StateAttribute. osg::StateSet* stateset = new osg::StateSet; - + stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); - + _quadGeode->setStateSet(stateset); - + _parent->addChild(screenAlignedProjectionMatrix); screenAlignedProjectionMatrix->addChild(screenAlignedModelViewMatrix); screenAlignedModelViewMatrix->addChild(_quadGeode.get()); - + //setup shader std::string vertSource; if(!Utility::readFile("shaders/depthpeel_final.vert", vertSource)) @@ -414,82 +412,82 @@ bool DePee::createFinal() printf("shader source not found\n"); return false; } - + std::string fragSource; if(!Utility::readFile("shaders/depthpeel_final.frag", fragSource)) { printf("shader source not found\n"); return false; } - + osg::ref_ptr program = new osg::Program; program->addShader( new osg::Shader( osg::Shader::VERTEX, vertSource.c_str() ) ); program->addShader( new osg::Shader( osg::Shader::FRAGMENT, fragSource.c_str() ) ); - + //choose map to display stateset->addUniform( new osg::Uniform("normalDepthMap0", 1)); stateset->addUniform( new osg::Uniform("normalDepthMap1", 2)); stateset->addUniform(new osg::Uniform("edgeMap", 3)); stateset->addUniform( new osg::Uniform("colorMap", 4)); stateset->addUniform( new osg::Uniform("noiseMap", 5)); - + stateset->addUniform(_sketchy); stateset->addUniform(_colored); stateset->addUniform(_edgy); stateset->addUniform(_sketchiness); - + stateset->setAttributeAndModes( program.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); - + //switch lighting off - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF); + stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF); return true; } bool DePee::createEdgeMap(bool first) //create the edge map of the first normal and depth map -{ +{ _dePeePasses.back()->newRenderPass(EDGE_MAP); - - + + // set up the background color and clear mask. _dePeePasses.back()->Cameras[EDGE_MAP]->setClearColor(osg::Vec4(0.3,0.3f,0.3f,1.0f)); _dePeePasses.back()->Cameras[EDGE_MAP]->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - + const osg::BoundingSphere& bs = _quadGeode->getBound(); if (!bs.valid()) { return false; } - + float znear = 1.0f*bs.radius(); float zfar = 3.0f*bs.radius(); - + znear *= 0.9f; zfar *= 1.1f; - - + + // set up projection. //_dePeePasses.back()->Cameras.top()->setProjectionMatrixAsFrustum(-proj_right,proj_right,-proj_top,proj_top,znear,zfar); _dePeePasses.back()->Cameras[EDGE_MAP]->setProjectionMatrixAsOrtho(0,_width,0,_height,znear,zfar); - + //set view _dePeePasses.back()->Cameras[EDGE_MAP]->setReferenceFrame(osg::Transform::ABSOLUTE_RF); - + _dePeePasses.back()->Cameras[EDGE_MAP]->setViewMatrixAsLookAt(osg::Vec3(0.0f,0.0f,2.0f)*bs.radius(), osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0f,1.0f,0.0f)); - + // set viewport _dePeePasses.back()->Cameras[EDGE_MAP]->setViewport(0,0,_texWidth,_texHeight); - + // set the camera to render before the main camera. _dePeePasses.back()->Cameras[EDGE_MAP]->setRenderOrder(osg::Camera::PRE_RENDER); // tell the camera to use OpenGL frame buffer object _dePeePasses.back()->Cameras[EDGE_MAP]->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER); - + //switch lighting off osg::ref_ptr stateset = new osg::StateSet; - - + + if(_renderToFirst) { stateset->addUniform(new osg::Uniform("normalDepthMap", 1)); @@ -501,14 +499,14 @@ bool DePee::createEdgeMap(bool first) _dePeePasses.back()->Cameras[EDGE_MAP]->attach(osg::Camera::COLOR_BUFFER, _edgeMap.get()); stateset->addUniform( new osg::Uniform("edgeMap", 3)); - - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE | + + stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF); //setup shader stateset->setAttributeAndModes(_edgeMapProgram.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); stateset->addUniform(new osg::Uniform("width", (float) _width)); stateset->addUniform(new osg::Uniform("height", (float) _height)); - + if(first) { stateset->addUniform(new osg::Uniform("first", (float)1.0)); @@ -518,12 +516,12 @@ bool DePee::createEdgeMap(bool first) stateset->addUniform(new osg::Uniform("first", (float)0.0)); } _dePeePasses.back()->settingNodes[EDGE_MAP]->setStateSet(stateset.get()); - + // add subgraph to render assert(_dePeePasses.size() > 0); - + _dePeePasses.back()->settingNodes[EDGE_MAP]->addChild(_quadGeode.get()); - + return true; } @@ -531,13 +529,13 @@ bool DePee::createEdgeMap(bool first) bool DePee::createNormalDepthColorMap(MapMode mapMode, bool first) { DePeePass* pass; - + pass = _dePeePasses.back(); - + pass->newRenderPass(mapMode); - + // - // setup camera + // setup camera // // set up the background color and clear mask @@ -549,23 +547,23 @@ bool DePee::createNormalDepthColorMap(MapMode mapMode, bool first) { return false; } - + float znear = 1.0f*bs.radius(); float zfar = 3.0f*bs.radius(); - + // 2:1 aspect ratio as per flag geometry below. float projTop = 0.25f*znear; float projRight = projTop * ((double)_width/(double)_height); - + znear *= 0.9f; zfar *= 1.1f; - + // set up projection. pass->Cameras[mapMode]->setProjectionMatrixAsFrustum(-projRight,projRight,-projTop,projTop, znear,zfar); - + // setup view pass->Cameras[mapMode]->setReferenceFrame(osg::Transform::ABSOLUTE_RF); - + pass->Cameras[mapMode]->setViewMatrixAsLookAt(bs.center()-osg::Vec3(0.0f,2.0f,0.0f)*bs.radius(), bs.center(), osg::Vec3(0.0f,0.0f,1.0f)); @@ -574,24 +572,24 @@ bool DePee::createNormalDepthColorMap(MapMode mapMode, bool first) // set the camera to render before the main camera. pass->Cameras[mapMode]->setRenderOrder(osg::Camera::PRE_RENDER); - + pass->Cameras[mapMode]->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - + // // setup stateset // //switch lighting off osg::ref_ptr stateset = new osg::StateSet; - - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE | + + stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF); - + switch(mapMode) { case NORMAL_DEPTH_MAP: - + _renderToFirst = !_renderToFirst; - + if(_renderToFirst) { pass->Cameras[mapMode]->attach(osg::Camera::COLOR_BUFFER, _normalDepthMap0.get()); @@ -602,17 +600,17 @@ bool DePee::createNormalDepthColorMap(MapMode mapMode, bool first) pass->Cameras[mapMode]->attach(osg::Camera::COLOR_BUFFER, _normalDepthMap1.get()); stateset->addUniform(new osg::Uniform("normalDepthMap", 1)); } - + stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF); stateset->setAttributeAndModes(_normalDepthMapProgram.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); break; - + case COLOR_MAP: - + assert(pass == _dePeePasses.back()); pass->Cameras[mapMode]->attach(osg::Camera::COLOR_BUFFER, _colorMap.get()); - - + + if(_renderToFirst) { stateset->addUniform(new osg::Uniform("normalDepthMap", 1)); @@ -626,26 +624,26 @@ bool DePee::createNormalDepthColorMap(MapMode mapMode, bool first) stateset->setMode(GL_BLEND, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); stateset->setAttributeAndModes(_colorMapProgram.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); stateset->addUniform(new osg::Uniform("tex", 0)); - + break; default: return false; }; - + // add subgraph to render - + pass->settingNodes[mapMode]->addChild(_subgraph.get()); - + stateset->addUniform(new osg::Uniform("first", first)); - + stateset->addUniform(new osg::Uniform("width", (float) _width)); stateset->addUniform(new osg::Uniform("height", (float) _height)); stateset->addUniform(new osg::Uniform("znear", znear)); stateset->addUniform(new osg::Uniform("zfar", zfar)); - + pass->settingNodes[mapMode]->setStateSet(stateset.get()); - + return true; } @@ -665,7 +663,7 @@ bool DePee::updateHUDText() + (_isSketchy ? "+" : "-") + "(S)ketchy " + + (_isColored ? "+" : "-") + "(C)olored " + + "-> "+Utility::toString(getNumberOfRenderPasses())+ " Rendering Passes " - + "@ " + + "@ " + tmp + " fps"); return true; } diff --git a/examples/osgdepthpeeling/Utility.cpp b/examples/osgdepthpeeling/Utility.cpp index cb68edfe1..f5b9cd282 100644 --- a/examples/osgdepthpeeling/Utility.cpp +++ b/examples/osgdepthpeeling/Utility.cpp @@ -19,7 +19,7 @@ bool Utility::readFile(const char* fName, std::string& s) { std::string foundFile = osgDB::findDataFile(fName); if (foundFile.empty()) return false; - + osgDB::ifstream is;//(fName); is.open(foundFile.c_str()); if (is.fail()) @@ -53,7 +53,7 @@ osg::Program* Utility::createProgram(std::string vs, std::string fs) printf("shader source not found\n"); return 0; } - + std::string fragSource; if(!readFile((char*)fs.c_str(), fragSource)) { @@ -61,7 +61,7 @@ osg::Program* Utility::createProgram(std::string vs, std::string fs) return 0; } - + osg::Program* program = new osg::Program; program->addShader( new osg::Shader( osg::Shader::VERTEX, vertSource.c_str() ) ); program->addShader( new osg::Shader( osg::Shader::FRAGMENT, fragSource.c_str() ) ); @@ -80,28 +80,28 @@ double Utility::getNoise(unsigned x, unsigned y, unsigned random) double Utility::smoothNoise(unsigned width, unsigned height, unsigned x, unsigned y, unsigned char* noise) { assert(noise); - - if(x==0 || x > width -2 + + if(x==0 || x > width -2 || y==0 || y > height -2) return noise[x + y*width]; - + double corners = (noise[x-1 + (y-1) *width] +noise[x+1 + (y-1)*width] +noise[x-1 + (y+1) * width] +noise[x+1 + (y+1) * width]) / 16.0; - double sides = (noise[x-1 + y*width] - +noise[x+1 + y*width] - +noise[x + (y-1)*width] + double sides = (noise[x-1 + y*width] + +noise[x+1 + y*width] + +noise[x + (y-1)*width] +noise[x + (y+1)*width]) / 8.0; double center = noise[x + y*width] / 4.0; - + return corners + sides + center; } osg::Texture2D* Utility::newColorTexture2D(unsigned width, unsigned height, unsigned accuracy) { osg::Texture2D* texture2D = new osg::Texture2D; - + texture2D->setTextureSize(width, height); if(accuracy == 32) { @@ -124,30 +124,29 @@ osg::Geode* Utility::getCanvasQuad(unsigned width, unsigned height, double depth osg::Vec2Array* texCoords = new osg::Vec2Array; vertices->push_back(osg::Vec3(0,0,depth)); texCoords->push_back(osg::Vec2(0,0)); - + vertices->push_back(osg::Vec3(width,0,depth)); texCoords->push_back(osg::Vec2(1,0)); - + vertices->push_back(osg::Vec3(0,height,depth)); texCoords->push_back(osg::Vec2(0,1)); - + vertices->push_back(osg::Vec3(width,height,depth)); texCoords->push_back(osg::Vec2(1,1)); - + osg::Geometry* quad = new osg::Geometry; quad->setVertexArray(vertices); quad->setTexCoordArray(1,texCoords); - + quad->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,vertices->size())); - + osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); - quad->setColorArray(colors); - quad->setColorBinding(osg::Geometry::BIND_OVERALL); - + quad->setColorArray(colors, osg::Array::BIND_OVERALL); + osg::Geode* geode = new osg::Geode(); geode->addDrawable(quad); - + return geode; - + } diff --git a/examples/osgdistortion/osgdistortion.cpp b/examples/osgdistortion/osgdistortion.cpp index ea26cf7bb..6d589308b 100644 --- a/examples/osgdistortion/osgdistortion.cpp +++ b/examples/osgdistortion/osgdistortion.cpp @@ -55,16 +55,16 @@ using namespace osg; osg::Node* createDistortionSubgraph(osg::Node* subgraph, const osg::Vec4& clearColour) { osg::Group* distortionNode = new osg::Group; - + unsigned int tex_width = 1024; unsigned int tex_height = 1024; - + osg::Texture2D* texture = new osg::Texture2D; texture->setTextureSize(tex_width, tex_height); texture->setInternalFormat(GL_RGBA); texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); - + // set up the render to texture camera. { osg::Camera* camera = new osg::Camera; @@ -92,10 +92,10 @@ osg::Node* createDistortionSubgraph(osg::Node* subgraph, const osg::Vec4& clearC // add subgraph to render camera->addChild(subgraph); - + distortionNode->addChild(camera); } - + // set up the hud camera { // create the quad to visualize. @@ -141,8 +141,7 @@ osg::Node* createDistortionSubgraph(osg::Node* subgraph, const osg::Vec4& clearC // pass the created vertex array to the points geometry object. polyGeom->setVertexArray(vertices); - polyGeom->setColorArray(colors); - polyGeom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); + polyGeom->setColorArray(colors, osg::Array::BIND_PER_VERTEX); polyGeom->setTexCoordArray(0,texcoords); @@ -159,7 +158,7 @@ osg::Node* createDistortionSubgraph(osg::Node* subgraph, const osg::Vec4& clearC } - // new we need to add the texture to the Drawable, we do so by creating a + // new we need to add the texture to the Drawable, we do so by creating a // StateSet to contain the Texture StateAttribute. osg::StateSet* stateset = polyGeom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); @@ -181,7 +180,7 @@ osg::Node* createDistortionSubgraph(osg::Node* subgraph, const osg::Vec4& clearC // add subgraph to render camera->addChild(geode); - + distortionNode->addChild(camera); } return distortionNode; @@ -189,9 +188,9 @@ osg::Node* createDistortionSubgraph(osg::Node* subgraph, const osg::Vec4& clearC void setDomeFaces(osgViewer::Viewer& viewer, osg::ArgumentParser& arguments) { - + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - if (!wsi) + if (!wsi) { osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."< camera = new osg::Camera; @@ -297,7 +296,7 @@ void setDomeFaces(osgViewer::Viewer& viewer, osg::ArgumentParser& arguments) viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-180.0f), 1.0,0.0,0.0)); } - + viewer.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); viewer.assignSceneDataToCameras(); @@ -314,15 +313,15 @@ osg::Geometry* createDomeDistortionMesh(const osg::Vec3& origin, const osg::Vec3 osg::Vec3d center(0.0,0.0,0.0); osg::Vec3d eye(0.0,0.0,0.0); - + double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); if (arguments.read("--distance", distance)) {} - + bool centerProjection = false; osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance); - - + + osg::notify(osg::NOTICE)<<"Projector position = "<windowDecoration = false; traits->doubleBuffer = true; traits->sharedContext = 0; - - + + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); if (!gc) @@ -485,8 +483,8 @@ void setDomeCorrection(osgViewer::Viewer& viewer, osg::ArgumentParser& arguments texture->setInternalFormat(GL_RGB); texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); - -#if 0 + +#if 0 osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; GLenum buffer = GL_FRONT; #else @@ -512,7 +510,7 @@ void setDomeCorrection(osgViewer::Viewer& viewer, osg::ArgumentParser& arguments viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); } - + // top face { osg::ref_ptr camera = new osg::Camera; @@ -608,7 +606,7 @@ void setDomeCorrection(osgViewer::Viewer& viewer, osg::ArgumentParser& arguments viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0,0.0,0.0)); } - + viewer.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); @@ -618,7 +616,7 @@ void setDomeCorrection(osgViewer::Viewer& viewer, osg::ArgumentParser& arguments osg::Geode* geode = new osg::Geode(); geode->addDrawable(createDomeDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), arguments)); - // new we need to add the texture to the mesh, we do so by creating a + // new we need to add the texture to the mesh, we do so by creating a // StateSet to contain the Texture StateAttribute. osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); @@ -636,18 +634,18 @@ void setDomeCorrection(osgViewer::Viewer& viewer, osg::ArgumentParser& arguments camera->setAllowEventFocus(false); //camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); - + camera->setProjectionMatrixAsOrtho2D(0,width,0,height); camera->setViewMatrix(osg::Matrix::identity()); // add subgraph to render camera->addChild(geode); - + camera->setName("DistortionCorrectionCamera"); viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); } - + viewer.getCamera()->setNearFarRatio(0.0001f); } @@ -665,23 +663,23 @@ int main(int argc, char** argv) // if not loaded assume no arguments passed in, try use default mode instead. if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt"); - + if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; } - + if (arguments.read("--dome") || arguments.read("--puffer") ) - { + { setDomeCorrection(viewer, arguments); - + viewer.setSceneData( loadedModel ); } else if (arguments.read("--faces")) - { + { setDomeFaces(viewer, arguments); @@ -697,7 +695,7 @@ int main(int argc, char** argv) { viewer.setLightingMode(osg::View::SKY_LIGHT); } - + if (viewer.getLightingMode()==osg::View::HEADLIGHT) { viewer.getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); @@ -726,7 +724,7 @@ int main(int argc, char** argv) while (arguments.read("-p",pathfile)) { osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); - if (apm || !apm->valid()) + if (apm || !apm->valid()) { unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); @@ -742,7 +740,7 @@ int main(int argc, char** argv) // add the state manipulator viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); - + // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); diff --git a/examples/osgforest/osgforest.cpp b/examples/osgforest/osgforest.cpp index e59024366..ba92df763 100644 --- a/examples/osgforest/osgforest.cpp +++ b/examples/osgforest/osgforest.cpp @@ -143,9 +143,9 @@ public: osg::Node* createShaderGraph(Cell* cell,osg::StateSet* stateset); osg::Node* createGeometryShaderGraph(Cell* cell, osg::StateSet* stateset); - + osg::Node* createTextureBufferGraph(Cell* cell, osg::Geometry* templateGeometry); - + void CollectTreePositions(Cell* cell, std::vector< osg::Vec3 >& positions); osg::Node* createHUDWithText(const std::string& text); @@ -474,8 +474,7 @@ osg::Geode* ForestTechniqueManager::createTerrain(const osg::Vec3& origin, const } geometry->setVertexArray(&v); - geometry->setColorArray(&color); - geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + geometry->setColorArray(&color, osg::Array::BIND_OVERALL); geometry->setTexCoordArray(0,&t); for(r=0;rsetTexCoordArray( 0, &t ); - geom->setColorArray( &c ); - geom->setColorBinding( osg::Geometry::BIND_OVERALL ); + geom->setColorArray( &c, osg::Array::BIND_OVERALL ); geom->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4) ); @@ -618,8 +616,7 @@ osg::Geometry* ForestTechniqueManager::createOrthogonalQuads( const osg::Vec3& p geom->setTexCoordArray( 0, &t ); - geom->setColorArray( &c ); - geom->setColorBinding( osg::Geometry::BIND_OVERALL ); + geom->setColorArray( &c, osg::Array::BIND_OVERALL ); geom->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,8) ); @@ -1025,10 +1022,10 @@ osg::Node* ForestTechniqueManager::createTextureBufferGraph(Cell* cell, osg::Geo primSet->setNumInstances( cell->_trees.size() ); geode = new osg::Geode; geode->addDrawable(geometry); - + osg::ref_ptr treeParamsImage = new osg::Image; treeParamsImage->allocateImage( 3*cell->_trees.size(), 1, 1, GL_RGBA, GL_FLOAT ); - + unsigned int i=0; for(TreeList::iterator itr=cell->_trees.begin(); itr!=cell->_trees.end(); @@ -1369,7 +1366,7 @@ osg::Node* ForestTechniqueManager::createScene(unsigned int numTreesToCreates, u _techniqueSwitch->addChild(group); std::cout<<"done."<addUniform(baseTextureSampler); - + osg::Uniform* dataBufferSampler = new osg::Uniform("dataBuffer",1); stateset->addUniform(dataBufferSampler); } - + osg::ref_ptr templateGeometry = createOrthogonalQuadsNoColor(osg::Vec3(0.0f,0.0f,0.0f),1.0f,1.0f); templateGeometry->setUseVertexBufferObjects(true); templateGeometry->setUseDisplayList(false); @@ -1434,10 +1431,10 @@ osg::Node* ForestTechniqueManager::createScene(unsigned int numTreesToCreates, u group->addChild(createHUDWithText("Using geometry instancing to create a forest\n\nPress left cursor key to select osg::Vertex/Geometry/FragmentProgram based forest\nPress right cursor key to select osg::Billboard based forest")); _techniqueSwitch->addChild(group); - + std::cout<<"done."<setSingleChildOn(_currentTechnique); @@ -1462,13 +1459,13 @@ int main( int argc, char **argv ) unsigned int numTreesToCreate = 10000; arguments.read("--trees",numTreesToCreate); - + unsigned int maxNumTreesPerCell = sqrtf(static_cast(numTreesToCreate)); - + arguments.read("--trees-per-cell",maxNumTreesPerCell); osg::ref_ptr ttm = new ForestTechniqueManager; - + // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); diff --git a/examples/osgfxbrowser/Frame.cpp b/examples/osgfxbrowser/Frame.cpp index 00234c103..68558a838 100644 --- a/examples/osgfxbrowser/Frame.cpp +++ b/examples/osgfxbrowser/Frame.cpp @@ -23,7 +23,7 @@ namespace osgfxbrowser { Frame::Frame() -: osg::Geode(), +: osg::Geode(), bgcolor_(0.5f, 0.5f, 0.5f, 1.0f), rect_(0, 0, 100, 100), caption_("Frame") @@ -108,8 +108,7 @@ osg::Geometry *Frame::build_quad(const Rect &rect, const osg::Vec4 &color, bool clr->push_back(osg::Vec4(black, 0)); } - geo->setColorArray(clr.get()); - geo->setColorBinding(osg::Geometry::BIND_PER_VERTEX); + geo->setColorArray(clr.get(), osg::Array::BIND_PER_VERTEX); geo->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, shadow? 12: 4)); diff --git a/examples/osggameoflife/GameOfLifePass.cpp b/examples/osggameoflife/GameOfLifePass.cpp index 78456ec8d..0cab6f16f 100644 --- a/examples/osggameoflife/GameOfLifePass.cpp +++ b/examples/osggameoflife/GameOfLifePass.cpp @@ -27,10 +27,10 @@ ProcessPass::ProcessPass(osg::TextureRectangle *in_tex, _TextureHeight(height) { _RootGroup = new osg::Group; - + _InTexture = in_tex; _OutTexture = out_tex; - + _Camera = new osg::Camera; setupCamera(); _Camera->addChild(createTexturedQuad().get()); @@ -47,7 +47,7 @@ ProcessPass::~ProcessPass() osg::ref_ptr ProcessPass::createTexturedQuad() { osg::ref_ptr top_group = new osg::Group; - + osg::ref_ptr quad_geode = new osg::Geode; osg::ref_ptr quad_coords = new osg::Vec3Array; // vertex coords @@ -72,19 +72,18 @@ osg::ref_ptr ProcessPass::createTexturedQuad() quad_geom->setVertexArray(quad_coords.get()); quad_geom->setTexCoordArray(0, quad_tcoords.get()); quad_geom->addPrimitiveSet(quad_da.get()); - quad_geom->setColorArray(quad_colors.get()); - quad_geom->setColorBinding(osg::Geometry::BIND_OVERALL); + quad_geom->setColorArray(quad_colors.get(), osg::Array::BIND_OVERALL); _StateSet = quad_geom->getOrCreateStateSet(); _StateSet->setMode(GL_LIGHTING,osg::StateAttribute::OFF); _StateSet->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); - + _StateSet->setTextureAttributeAndModes(0, _InTexture.get(), osg::StateAttribute::ON); - + _StateSet->addUniform(new osg::Uniform("textureIn", 0)); - + quad_geode->addDrawable(quad_geom.get()); - + top_group->addChild(quad_geode.get()); return top_group; @@ -94,7 +93,7 @@ void ProcessPass::setupCamera() { // clearing _Camera->setClearMask(GL_DEPTH_BUFFER_BIT); - + // projection and view _Camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1,0,1)); _Camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); @@ -118,7 +117,7 @@ void ProcessPass::setShader(std::string filename) return; } - osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT ); + osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT ); fshader->loadShaderSourceFromFile(foundFile); _FragmentProgram = 0; @@ -135,7 +134,7 @@ GameOfLifePass::GameOfLifePass(osg::Image *in_image) { _TextureWidth = in_image->s(); _TextureHeight = in_image->t(); - + _RootGroup = new osg::Group; _BranchSwith[0] = new osg::Switch; @@ -149,11 +148,11 @@ GameOfLifePass::GameOfLifePass(osg::Image *in_image) createOutputTextures(); _InOutTextureLife[0]->setImage(in_image); - + _ProcessPass[0] = new ProcessPass(_InOutTextureLife[0].get(), _InOutTextureLife[1].get(), _TextureWidth, _TextureHeight); - + // For the other pass, the input/output textures are flipped _ProcessPass[1] = new ProcessPass(_InOutTextureLife[1].get(), _InOutTextureLife[0].get(), @@ -194,7 +193,7 @@ void GameOfLifePass::createOutputTextures() { for (int i=0; i<2; i++) { _InOutTextureLife[i] = new osg::TextureRectangle; - + _InOutTextureLife[i]->setTextureSize(_TextureWidth, _TextureHeight); _InOutTextureLife[i]->setInternalFormat(GL_RGBA); _InOutTextureLife[i]->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST); diff --git a/examples/osggameoflife/osggameoflife.cpp b/examples/osggameoflife/osggameoflife.cpp index 83a1e8cfa..097f8c921 100644 --- a/examples/osggameoflife/osggameoflife.cpp +++ b/examples/osggameoflife/osggameoflife.cpp @@ -46,10 +46,10 @@ osg::Node* createScene(osg::Image *start_im) // create quad to display image on osg::ref_ptr geode = new osg::Geode(); - + // each geom will contain a quad osg::ref_ptr da = new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4); - + osg::ref_ptr colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); @@ -58,7 +58,7 @@ osg::Node* createScene(osg::Image *start_im) tcoords->push_back(osg::Vec2(width, 0)); tcoords->push_back(osg::Vec2(width, height)); tcoords->push_back(osg::Vec2(0, height)); - + osg::ref_ptr vcoords = new osg::Vec3Array; // vertex coords osg::ref_ptr geom = new osg::Geometry; @@ -67,25 +67,24 @@ osg::Node* createScene(osg::Image *start_im) vcoords->push_back(osg::Vec3d(width, 0, 0)); vcoords->push_back(osg::Vec3d(width, 0, height)); vcoords->push_back(osg::Vec3d(0, 0, height)); - + geom->setVertexArray(vcoords.get()); geom->setTexCoordArray(0,tcoords.get()); geom->addPrimitiveSet(da.get()); - geom->setColorArray(colors.get()); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors.get(), osg::Array::BIND_OVERALL); geomss = geom->getOrCreateStateSet(); geomss->setMode(GL_LIGHTING, osg::StateAttribute::OFF); geode->addDrawable(geom.get()); - + topnode->addChild(geode.get()); - + // create the ping pong processing passes golpass = new GameOfLifePass(start_im); topnode->addChild(golpass->getRoot().get()); // attach the output of the processing to the geom - geomss->setTextureAttributeAndModes(0, + geomss->setTextureAttributeAndModes(0, golpass->getOutputTexture().get(), osg::StateAttribute::ON); return topnode; @@ -119,14 +118,14 @@ int main(int argc, char *argv[]) // load the image osg::ref_ptr startIm = osgDB::readImageFile(startName); - + if (!startIm) { std::cout << "Could not load start image.\n"; return(1); } osg::Node* scene = createScene(startIm.get()); - + // construct the viewer. osgViewer::Viewer viewer; viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); @@ -145,7 +144,7 @@ int main(int argc, char *argv[]) // flip the textures after we've completed a frame golpass->flip(); // attach the proper output to view - geomss->setTextureAttributeAndModes(0, + geomss->setTextureAttributeAndModes(0, golpass->getOutputTexture().get(), osg::StateAttribute::ON); } diff --git a/examples/osggeometry/osggeometry.cpp b/examples/osggeometry/osggeometry.cpp index 81460cbbd..0c12309a0 100644 --- a/examples/osggeometry/osggeometry.cpp +++ b/examples/osggeometry/osggeometry.cpp @@ -573,15 +573,13 @@ osg::Node* createBackground() osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); - polyGeom->setColorArray(colors); - polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); + polyGeom->setColorArray(colors, osg::Array::BIND_OVERALL); // set the normal in the same way color. osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); - polyGeom->setNormalArray(normals); - polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); + polyGeom->setNormalArray(normals, osg::Array::BIND_OVERALL); osg::Vec2 myTexCoords[] = { diff --git a/examples/osggeometryshaders/osggeometryshaders.cpp b/examples/osggeometryshaders/osggeometryshaders.cpp index 4212980df..27df86946 100644 --- a/examples/osggeometryshaders/osggeometryshaders.cpp +++ b/examples/osggeometryshaders/osggeometryshaders.cpp @@ -141,8 +141,7 @@ public: SomePoints() { osg::Vec4Array* cAry = new osg::Vec4Array; - setColorArray( cAry ); - setColorBinding( osg::Geometry::BIND_OVERALL ); + setColorArray( cAry, osg::Array::BIND_OVERALL ); cAry->push_back( osg::Vec4(1,1,1,1) ); osg::Vec3Array* vAry = new osg::Vec3Array; diff --git a/examples/osggpx/osggpx.cpp b/examples/osggpx/osggpx.cpp index 747be6e58..d8834444a 100644 --- a/examples/osggpx/osggpx.cpp +++ b/examples/osggpx/osggpx.cpp @@ -395,8 +395,7 @@ osg::Node* createTrackModel(Track* track, const osg::Vec4& colour) osg::ref_ptr colours = new osg::Vec4Array; colours->push_back(colour); - geometry->setColorArray(colours.get()); - geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + geometry->setColorArray(colours.get(), osg::Array::BIND_OVERALL); geometry->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, points.size())); diff --git a/examples/osghangglide/base.cpp b/examples/osghangglide/base.cpp index b7bc49d84..c8cd5119a 100644 --- a/examples/osghangglide/base.cpp +++ b/examples/osghangglide/base.cpp @@ -44,7 +44,7 @@ Node *makeBase( void ) c = 0; (*coords)[c].set(0.0f,0.0f,0.0f); (*tcoords)[c].set(0.0f,0.0f); - + for( i = 0; i <= 18; i++ ) { theta = osg::DegreesToRadians((float)i * 20.0); @@ -61,8 +61,7 @@ Node *makeBase( void ) geom->setTexCoordArray( 0, tcoords ); - geom->setColorArray( colors ); - geom->setColorBinding( Geometry::BIND_OVERALL ); + geom->setColorArray( colors, Array::BIND_OVERALL ); geom->addPrimitiveSet( new DrawArrays(PrimitiveSet::TRIANGLE_FAN,0,19) ); @@ -81,7 +80,7 @@ Node *makeBase( void ) // clear the depth to the far plane. osg::Depth* depth = new osg::Depth; depth->setFunction(osg::Depth::ALWAYS); - depth->setRange(1.0,1.0); + depth->setRange(1.0,1.0); dstate->setAttributeAndModes(depth,StateAttribute::ON ); dstate->setRenderBinDetails(-1,"RenderBin"); diff --git a/examples/osghangglide/sky.cpp b/examples/osghangglide/sky.cpp index b5ad1da2e..3a23f53a4 100644 --- a/examples/osghangglide/sky.cpp +++ b/examples/osghangglide/sky.cpp @@ -58,8 +58,8 @@ Node *makeSky( void ) Vec3Array& coords = *(new Vec3Array(19*nlev)); Vec4Array& colors = *(new Vec4Array(19*nlev)); Vec2Array& tcoords = *(new Vec2Array(19*nlev)); - - + + int ci = 0; for( i = 0; i < nlev; i++ ) @@ -104,12 +104,11 @@ Node *makeSky( void ) geom->addPrimitiveSet(drawElements); } - + geom->setVertexArray( &coords ); geom->setTexCoordArray( 0, &tcoords ); - geom->setColorArray( &colors ); - geom->setColorBinding( Geometry::BIND_PER_VERTEX ); + geom->setColorArray( &colors, Array::BIND_PER_VERTEX ); Texture2D *tex = new Texture2D; @@ -121,12 +120,12 @@ Node *makeSky( void ) dstate->setTextureAttribute(0, new TexEnv ); dstate->setMode( GL_LIGHTING, StateAttribute::OFF ); dstate->setMode( GL_CULL_FACE, StateAttribute::ON ); - + // clear the depth to the far plane. osg::Depth* depth = new osg::Depth; depth->setFunction(osg::Depth::ALWAYS); - depth->setRange(1.0,1.0); + depth->setRange(1.0,1.0); dstate->setAttributeAndModes(depth,StateAttribute::ON ); dstate->setRenderBinDetails(-2,"RenderBin"); diff --git a/examples/osghangglide/terrain.cpp b/examples/osghangglide/terrain.cpp index 7aff52cd0..36e366650 100644 --- a/examples/osghangglide/terrain.cpp +++ b/examples/osghangglide/terrain.cpp @@ -94,7 +94,7 @@ Node *makeTerrain( void ) Vec3Array& v = *(new Vec3Array(m*n)); Vec2Array& t = *(new Vec2Array(m*n)); Vec4Array& col = *(new Vec4Array(1)); - + col[0][0] = col[0][1] = col[0][2] = col[0][3] = 1.0f; for( i = 0; i < m * n; i++ ) @@ -112,8 +112,7 @@ Node *makeTerrain( void ) geom->setVertexArray( &v ); geom->setTexCoordArray( 0, &t ); - geom->setColorArray( &col ); - geom->setColorBinding( Geometry::BIND_OVERALL ); + geom->setColorArray( &col, Array::BIND_OVERALL ); for( i = 0; i < m-2; i++ ) { diff --git a/examples/osghangglide/trees.cpp b/examples/osghangglide/trees.cpp index 4ce0a8a9b..600b38251 100644 --- a/examples/osghangglide/trees.cpp +++ b/examples/osghangglide/trees.cpp @@ -198,8 +198,7 @@ static Geometry *makeTree( _tree *tree, StateSet *dstate ) geom->setTexCoordArray( 0, &t ); - geom->setColorArray( &l ); - geom->setColorBinding( Geometry::BIND_OVERALL ); + geom->setColorArray( &l, Array::BIND_OVERALL ); geom->addPrimitiveSet( new DrawArrays(PrimitiveSet::QUADS,0,4) ); @@ -238,7 +237,7 @@ Node *makeTrees( void ) tex->setImage(osgDB::readImageFile("Images/tree0.rgba")); StateSet *dstate = new StateSet; - + dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON ); dstate->setTextureAttribute(0, new TexEnv ); @@ -249,7 +248,7 @@ Node *makeTrees( void ) dstate->setAttributeAndModes( alphaFunc, StateAttribute::ON ); dstate->setMode( GL_LIGHTING, StateAttribute::OFF ); - + dstate->setRenderingHint( StateSet::TRANSPARENT_BIN ); int tt[] = { 15, 30, 45, 58, 72, 75, 93, 96, 105, -1 }; diff --git a/examples/osghud/osghud.cpp b/examples/osghud/osghud.cpp index 11b81bb24..a5aa4e29d 100644 --- a/examples/osghud/osghud.cpp +++ b/examples/osghud/osghud.cpp @@ -46,7 +46,7 @@ osg::Camera* createHUD() // set the projection matrix camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); - // set the view matrix + // set the view matrix camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setViewMatrix(osg::Matrix::identity()); @@ -58,7 +58,7 @@ osg::Camera* createHUD() // we don't want the camera to grab event focus from the viewers main camera(s). camera->setAllowEventFocus(false); - + // add to this camera a subgraph to render @@ -84,7 +84,7 @@ osg::Camera* createHUD() text->setText("Head Up Displays are simple :-)"); position += delta; - } + } { @@ -96,7 +96,7 @@ osg::Camera* createHUD() text->setText("All you need to do is create your text in a subgraph."); position += delta; - } + } { @@ -109,7 +109,7 @@ osg::Camera* createHUD() "to create an orthographic projection.\n"); position += delta; - } + } { osgText::Text* text = new osgText::Text; @@ -121,7 +121,7 @@ osg::Camera* createHUD() "it remains independent from any external model view matrices."); position += delta; - } + } { osgText::Text* text = new osgText::Text; @@ -132,7 +132,7 @@ osg::Camera* createHUD() text->setText("And set the Camera's clear mask to just clear the depth buffer."); position += delta; - } + } { osgText::Text* text = new osgText::Text; @@ -144,7 +144,7 @@ osg::Camera* createHUD() "to make sure it's drawn last."); position += delta; - } + } { @@ -166,13 +166,11 @@ osg::Camera* createHUD() osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,0.0f,1.0f)); - geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); + geom->setNormalArray(normals, osg::Array::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0,0.8f,0.2f)); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); @@ -196,14 +194,14 @@ struct SnapImage : public osg::Camera::DrawCallback _filename(filename), _snapImage(false) { - _image = new osg::Image; + _image = new osg::Image; } virtual void operator () (osg::RenderInfo& renderInfo) const { if (!_snapImage) return; - + osg::notify(osg::NOTICE)<<"Camera callback"< _snapImage; }; @@ -273,11 +271,11 @@ int main( int argc, char **argv ) // read the scene from the list of file specified commandline args. osg::ref_ptr scene = osgDB::readNodeFiles(arguments); - + // if not loaded assume no arguments passed in, try use default model instead. if (!scene) scene = osgDB::readNodeFile("dumptruck.osgt"); - - + + if (!scene) { osg::notify(osg::NOTICE)<<"No model loaded"<setGraphicsContext(windows[0]); hudCamera->setViewport(0,0,windows[0]->getTraits()->width, windows[0]->getTraits()->height); @@ -327,21 +325,21 @@ int main( int argc, char **argv ) view->setCameraManipulator(new osgGA::TrackballManipulator); // now create the HUD camera's view - + osgViewer::Viewer::Windows windows; viewer.getWindows(windows); - + if (windows.empty()) return 1; - + osg::Camera* hudCamera = createHUD(); - + // set up cameras to render on the first window available. hudCamera->setGraphicsContext(windows[0]); hudCamera->setViewport(0,0,windows[0]->getTraits()->width, windows[0]->getTraits()->height); - + osgViewer::View* hudView = new osgViewer::View; hudView->setCamera(hudCamera); - + viewer.addView(hudView); return viewer.run(); @@ -351,18 +349,18 @@ int main( int argc, char **argv ) { // construct the viewer. osgViewer::Viewer viewer; - + SnapImage* postDrawCallback = new SnapImage("PostDrawCallback.png"); - viewer.getCamera()->setPostDrawCallback(postDrawCallback); + viewer.getCamera()->setPostDrawCallback(postDrawCallback); viewer.addEventHandler(new SnapeImageHandler('p',postDrawCallback)); - + SnapImage* finalDrawCallback = new SnapImage("FinalDrawCallback.png"); - viewer.getCamera()->setFinalDrawCallback(finalDrawCallback); + viewer.getCamera()->setFinalDrawCallback(finalDrawCallback); viewer.addEventHandler(new SnapeImageHandler('f',finalDrawCallback)); osg::ref_ptr group = new osg::Group; - // add the HUD subgraph. + // add the HUD subgraph. if (scene.valid()) group->addChild(scene.get()); group->addChild(createHUD()); @@ -371,5 +369,5 @@ int main( int argc, char **argv ) return viewer.run(); } - + } diff --git a/examples/osglight/osglight.cpp b/examples/osglight/osglight.cpp index 25b3eda92..593d095a0 100644 --- a/examples/osglight/osglight.cpp +++ b/examples/osglight/osglight.cpp @@ -50,34 +50,34 @@ class ModelTransformCallback : public osg::NodeCallback _period = 4.0f; _range = bs.radius()*0.5f; } - + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) { osg::PositionAttitudeTransform* pat = dynamic_cast(node); const osg::FrameStamp* frameStamp = nv->getFrameStamp(); if (pat && frameStamp) { - if (_firstTime==0.0) + if (_firstTime==0.0) { _firstTime = frameStamp->getSimulationTime(); } - + double phase = (frameStamp->getSimulationTime()-_firstTime)/_period; phase -= floor(phase); phase *= (2.0 * osg::PI); - + osg::Quat rotation; rotation.makeRotate(phase,1.0f,1.0f,1.0f); - - pat->setAttitude(rotation); - + + pat->setAttitude(rotation); + pat->setPosition(osg::Vec3(0.0f,0.0f,sin(phase))*_range); } - - // must traverse the Node's subgraph + + // must traverse the Node's subgraph traverse(node,nv); } - + double _firstTime; double _period; double _range; @@ -88,7 +88,7 @@ class ModelTransformCallback : public osg::NodeCallback osg::Node* createLights(osg::BoundingBox& bb,osg::StateSet* rootStateSet) { osg::Group* lightGroup = new osg::Group; - + float modelSize = bb.radius(); // create a spot light. @@ -101,13 +101,13 @@ osg::Node* createLights(osg::BoundingBox& bb,osg::StateSet* rootStateSet) myLight1->setSpotExponent(50.0f); myLight1->setDirection(osg::Vec3(1.0f,1.0f,-1.0f)); - osg::LightSource* lightS1 = new osg::LightSource; + osg::LightSource* lightS1 = new osg::LightSource; lightS1->setLight(myLight1); - lightS1->setLocalStateSetModes(osg::StateAttribute::ON); + lightS1->setLocalStateSetModes(osg::StateAttribute::ON); lightS1->setStateSetModes(*rootStateSet,osg::StateAttribute::ON); lightGroup->addChild(lightS1); - + // create a local light. osg::Light* myLight2 = new osg::Light; @@ -119,15 +119,15 @@ osg::Node* createLights(osg::BoundingBox& bb,osg::StateSet* rootStateSet) myLight2->setLinearAttenuation(2.0f/modelSize); myLight2->setQuadraticAttenuation(2.0f/osg::square(modelSize)); - osg::LightSource* lightS2 = new osg::LightSource; + osg::LightSource* lightS2 = new osg::LightSource; lightS2->setLight(myLight2); - lightS2->setLocalStateSetModes(osg::StateAttribute::ON); + lightS2->setLocalStateSetModes(osg::StateAttribute::ON); lightS2->setStateSetModes(*rootStateSet,osg::StateAttribute::ON); - + osg::MatrixTransform* mt = new osg::MatrixTransform(); { - // set up the animation path + // set up the animation path osg::AnimationPath* animationPath = new osg::AnimationPath; animationPath->insert(0.0,osg::AnimationPath::ControlPoint(bb.corner(0))); animationPath->insert(1.0,osg::AnimationPath::ControlPoint(bb.corner(1))); @@ -139,30 +139,30 @@ osg::Node* createLights(osg::BoundingBox& bb,osg::StateSet* rootStateSet) animationPath->insert(7.0,osg::AnimationPath::ControlPoint(bb.corner(7))); animationPath->insert(8.0,osg::AnimationPath::ControlPoint(bb.corner(0))); animationPath->setLoopMode(osg::AnimationPath::SWING); - + mt->setUpdateCallback(new osg::AnimationPathCallback(animationPath)); } - + // create marker for point light. osg::Geometry* marker = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array; vertices->push_back(osg::Vec3(0.0,0.0,0.0)); marker->setVertexArray(vertices); marker->addPrimitiveSet(new osg::DrawArrays(GL_POINTS,0,1)); - + osg::StateSet* stateset = new osg::StateSet; osg::Point* point = new osg::Point; point->setSize(4.0f); stateset->setAttribute(point); - + marker->setStateSet(stateset); - + osg::Geode* markerGeode = new osg::Geode; markerGeode->addDrawable(marker); - + mt->addChild(lightS2); mt->addChild(markerGeode); - + lightGroup->addChild(mt); return lightGroup; @@ -173,57 +173,56 @@ osg::Geometry* createWall(const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec // create a drawable for occluder. osg::Geometry* geom = new osg::Geometry; - + geom->setStateSet(stateset); unsigned int noXSteps = 100; unsigned int noYSteps = 100; - + osg::Vec3Array* coords = new osg::Vec3Array; coords->reserve(noXSteps*noYSteps); - - + + osg::Vec3 dx = (v2-v1)/((float)noXSteps-1.0f); osg::Vec3 dy = (v3-v1)/((float)noYSteps-1.0f); - + unsigned int row; osg::Vec3 vRowStart = v1; for(row=0;rowpush_back(v); v += dx; } vRowStart+=dy; } - + geom->setVertexArray(coords); - + osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); - - + geom->setColorArray(colors, osg::Array::BIND_OVERALL); + + for(row=0;rowreserve(noXSteps*2); - for(unsigned int col=0;colpush_back((row+1)*noXSteps+col); quadstrip->push_back(row*noXSteps+col); - } + } geom->addPrimitiveSet(quadstrip); } - - // create the normals. + + // create the normals. osgUtil::SmoothingVisitor::smooth(*geom); - + return geom; - + } @@ -240,12 +239,12 @@ osg::Node* createRoom(osg::Node* loadedModel) osg::PositionAttitudeTransform* pat = new osg::PositionAttitudeTransform(); pat->setPivotPoint(loaded_bs.center()); - + pat->setUpdateCallback(new ModelTransformCallback(loaded_bs)); pat->addChild(loadedModel); - + bs = pat->getBound(); - + root->addChild(pat); } @@ -263,7 +262,7 @@ osg::Node* createRoom(osg::Node* loadedModel) osg::StateSet* wall = new osg::StateSet; wall->setMode(GL_CULL_FACE,osg::StateAttribute::ON); - + osg::StateSet* floor = new osg::StateSet; floor->setMode(GL_CULL_FACE,osg::StateAttribute::ON); @@ -271,7 +270,7 @@ osg::Node* createRoom(osg::Node* loadedModel) roof->setMode(GL_CULL_FACE,osg::StateAttribute::ON); osg::Geode* geode = new osg::Geode; - + // create front side. geode->addDrawable(createWall(bb.corner(0), bb.corner(4), @@ -308,12 +307,12 @@ osg::Node* createRoom(osg::Node* loadedModel) roof)); root->addChild(geode); - + root->addChild(createLights(bb,rootStateSet)); return root; - -} + +} int main( int argc, char **argv ) { @@ -325,20 +324,20 @@ int main( int argc, char **argv ) // load the nodes from the commandline arguments. osg::Node* loadedModel = osgDB::readNodeFiles(arguments); - + // if not loaded assume no arguments passed in, try use default mode instead. if (!loadedModel) loadedModel = osgDB::readNodeFile("glider.osgt"); - + // create a room made of foor walls, a floor, a roof, and swinging light fitting. osg::Node* rootnode = createRoom(loadedModel); // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize(rootnode); - + // add a viewport to the viewer and attach the scene graph. viewer.setSceneData( rootnode ); - + // create the windows and run the threads. viewer.realize(); diff --git a/examples/osglogo/osglogo.cpp b/examples/osglogo/osglogo.cpp index cbc1f0fe5..bc5e11cfe 100644 --- a/examples/osglogo/osglogo.cpp +++ b/examples/osglogo/osglogo.cpp @@ -43,13 +43,13 @@ class MyBillboardTransform : public osg::PositionAttitudeTransform { public: - + MyBillboardTransform(): _axis(0.0f,0.0f,1.0f), _normal(0.0f,-1.0f,0.0f) { } - + bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const { osg::Quat billboardRotation; @@ -75,15 +75,15 @@ class MyBillboardTransform : public osg::PositionAttitudeTransform } - + void setAxis(const osg::Vec3& axis) { _axis = axis; } void setNormal(const osg::Vec3& normal) { _normal = normal; } - + protected: - + virtual ~MyBillboardTransform() {} - + osg::Vec3 _axis; osg::Vec3 _normal; }; @@ -99,18 +99,18 @@ osg::Geometry* createWing(const osg::Vec3& left, const osg::Vec3& nose, const os osg::Vec3 left_to_right = right-left; osg::Vec3 mid = (right+left)*0.5f; osg::Vec3 mid_to_nose = (nose-mid)*chordRatio*0.5f; - + osg::Vec3Array* vertices = new osg::Vec3Array; vertices->push_back(left); //vertices->push_back(mid+mid_to_nose); - + unsigned int noSteps = 40; for(unsigned int i=1;ipush_back(left + left_to_right*ratio + mid_to_nose* (cosf((ratio-0.5f)*osg::PI*2.0f)+1.0f)); } - + vertices->push_back(right); vertices->push_back(nose); @@ -119,23 +119,21 @@ osg::Geometry* createWing(const osg::Vec3& left, const osg::Vec3& nose, const os osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(normal); - geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); - - + geom->setNormalArray(normals, osg::Array::BIND_OVERALL); + + osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(color); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); - + geom->setColorArray(colors, osg::Array::BIND_OVERALL); + geom->addPrimitiveSet(new osg::DrawArrays(GL_POLYGON,0,vertices->getNumElements())); - + osgUtil::Tessellator tessellator; tessellator.retessellatePolygons(*geom); return geom; - + } osg:: Node* createTextBelow(const osg::BoundingBox& bb, const std::string& label, const std::string&) @@ -172,7 +170,7 @@ osg:: Node* createTextLeft(const osg::BoundingBox& bb, const std::string& label, std::string font("fonts/arial.ttf"); osgText::Text* text = new osgText::Text; - + text->setFont(font); text->setFontResolution(110,120); text->setAlignment(osgText::Text::RIGHT_CENTER); @@ -191,7 +189,7 @@ osg:: Node* createTextLeft(const osg::BoundingBox& bb, const std::string& label, // text->setBackdropImplementation(osgText::Text::NO_DEPTH_BUFFER); // text->setBackdropImplementation(osgText::Text::DEPTH_RANGE); // text->setBackdropImplementation(osgText::Text::STENCIL_BUFFER); - + text->setBackdropOffset(0.05f); text->setBackdropColor(osg::Vec4(0.0f, 0.0f, 0.5f, 1.0f)); #endif @@ -227,7 +225,7 @@ osg:: Node* createTextLeft(const osg::BoundingBox& bb, const std::string& label, geode->addDrawable( subscriptText ); } - + return geode; } @@ -244,7 +242,7 @@ osg:: Node* createGlobe(const osg::BoundingBox& bb,float ratio, const std::strin osg::MatrixTransform* positioner = new osg::MatrixTransform; positioner->setMatrix(osg::Matrix::translate(-bs.center())*osg::Matrix::scale(s,s,s)*osg::Matrix::translate(bb.center())); positioner->addChild(bluemarble); - + xform->addChild(positioner); } else @@ -264,14 +262,14 @@ osg:: Node* createGlobe(const osg::BoundingBox& bb,float ratio, const std::strin } osg::Material* material = new osg::Material; - stateset->setAttribute(material); + stateset->setAttribute(material); // the globe geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(bb.center(),bb.radius()*ratio))); xform->addChild(geode); } - + return xform; } @@ -287,7 +285,7 @@ osg:: Node* createBox(const osg::BoundingBox& bb,float chordRatio) geode->addDrawable(createWing(bb.corner(4),bb.corner(5),bb.corner(1),chordRatio,white)); geode->addDrawable(createWing(bb.corner(1),bb.corner(0),bb.corner(4),chordRatio,white)); - + geode->addDrawable(createWing(bb.corner(1),bb.corner(5),bb.corner(7),chordRatio,white)); geode->addDrawable(createWing(bb.corner(7),bb.corner(3),bb.corner(1),chordRatio,white)); @@ -314,7 +312,7 @@ osg:: Node* createBoxNo5(const osg::BoundingBox& bb,float chordRatio) geode->addDrawable(createWing(bb.corner(4),bb.corner(6),bb.corner(7),chordRatio,white)); geode->addDrawable(createWing(bb.corner(1),bb.corner(0),bb.corner(4),chordRatio,white)); - + geode->addDrawable(createWing(bb.corner(7),bb.corner(3),bb.corner(1),chordRatio,white)); // back faces @@ -346,7 +344,7 @@ osg:: Node* createBoxNo5No2(const osg::BoundingBox& bb,float chordRatio) geode->addDrawable(createWing(bb.corner(4),bb.corner(6),bb.corner(7),chordRatio,red)); geode->addDrawable(createWing(bb.corner(1),bb.corner(0),bb.corner(4),chordRatio,green)); - + geode->addDrawable(createWing(bb.corner(7),bb.corner(3),bb.corner(1),chordRatio,blue)); return geode; @@ -373,27 +371,25 @@ osg:: Node* createBackdrop(const osg::Vec3& corner,const osg::Vec3& top,const os osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(normal); - geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); + geom->setNormalArray(normals, osg::Array::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,vertices->getNumElements())); osg::Geode* geode = new osg::Geode(); geode->addDrawable(geom); - - return geode; + + return geode; } osg::Node* createLogo(const std::string& filename, const std::string& label, const std::string& subscript) { osg::BoundingBox bb(osg::Vec3(0.0f,0.0f,0.0f),osg::Vec3(100.0f,100.0f,100.0f)); - float chordRatio = 0.5f; - float sphereRatio = 0.6f; + float chordRatio = 0.5f; + float sphereRatio = 0.6f; // create a group to hold the whole model. osg::Group* logo_group = new osg::Group; @@ -429,14 +425,14 @@ osg::Node* createLogo(const std::string& filename, const std::string& label, con // add the text to the group. //group->addChild(createTextBelow(bb)); logo_group->addChild(createTextLeft(bb, label, subscript)); - - + + // create the backdrop to render the shadow to. osg::Vec3 corner(-900.0f,150.0f,-100.0f); osg::Vec3 top(0.0f,0.0f,300.0f); top += corner; osg::Vec3 right(1100.0f,0.0f,0.0f); right += corner; - - + + // osg::Group* backdrop = new osg::Group; // backdrop->addChild(createBackdrop(corner,top,right)); @@ -462,9 +458,9 @@ int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); - + osg::DisplaySettings::instance()->setMinimumNumAlphaBits(8); - + // construct the viewer. osgViewer::Viewer viewer; @@ -474,23 +470,23 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->write(std::cout); return 1; } - + std::string label = "OpenSceneGraph"; std::string subscript = ""; bool showVersion = false; - while (arguments.read("--version")) { showVersion = true; } + while (arguments.read("--version")) { showVersion = true; } if( showVersion ) { label += " "; label += osgGetVersion(); } - while (arguments.read("--label", label)) {} - while (arguments.read("--subscript", subscript)) {} - + while (arguments.read("--label", label)) {} + while (arguments.read("--subscript", subscript)) {} + osg::ref_ptr node; - + if (arguments.argc()>1) node = createLogo(arguments[1], label, subscript); else node = createLogo("", label, subscript); diff --git a/examples/osgmultiplemovies/osgmultiplemovies.cpp b/examples/osgmultiplemovies/osgmultiplemovies.cpp index d265c8fd8..c81ac68cd 100644 --- a/examples/osgmultiplemovies/osgmultiplemovies.cpp +++ b/examples/osgmultiplemovies/osgmultiplemovies.cpp @@ -52,9 +52,9 @@ public: , _lastDataTimeStamp(0) { } - + void setImageStream(osg::ImageStream* is) { _imageStream = is; } - + virtual void update(osg::NodeVisitor* nv, osg::Drawable*) { if (_text.valid() && _imageStream.valid()) @@ -62,14 +62,14 @@ public: if (_imageStream->data() != _lastData) { double dt = nv->getFrameStamp()->getReferenceTime() - _lastDataTimeStamp; - + _fps = 0.9 * _fps + 0.1 * (1 / dt); _fps = osg::round(10 * _fps) / 10.0; - + _lastDataTimeStamp = nv->getFrameStamp()->getReferenceTime(); _lastData = _imageStream->data(); } - + std::ostringstream ss; ss << _imageStream->s() << "x" << _imageStream->t() << " | " << _fps << "fps"; ss << " | len: " << osg::round(_imageStream->getLength()*10) / 10.0; @@ -93,15 +93,15 @@ public: _text->setText(ss.str()); } } - - + + private: osg::observer_ptr _text; osg::observer_ptr _imageStream; float _fps; unsigned char* _lastData; double _lastDataTimeStamp; - + }; class MovieEventHandler : public osgGA::GUIEventHandler @@ -126,7 +126,7 @@ protected: { if (!geo) return; - + osg::Vec4Array* c = dynamic_cast(geo->getColorArray()); if (c) (*c)[0] = color; geo->dirtyDisplayList(); @@ -141,10 +141,6 @@ protected: }; - - - - bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv) { switch(ea.getEventType()) @@ -158,10 +154,10 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction } } break; - + case(osgGA::GUIEventAdapter::RELEASE): { - + osgViewer::View* view = dynamic_cast(&aa); osgUtil::LineSegmentIntersector::Intersections intersections; bool foundIntersection = view==0 ? false : view->computeIntersections(ea, intersections); @@ -172,7 +168,7 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction const osgUtil::LineSegmentIntersector::Intersection& intersection = *(intersections.begin()); osg::Drawable* drawable = intersection.drawable.get(); osg::Geometry* geometry = drawable ? drawable->asGeometry() : 0; - + if (geometry) { osg::Texture* tex = geometry->getStateSet() ? dynamic_cast(geometry->getStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE)) : NULL; if (tex) { @@ -183,7 +179,7 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction _currentGeometry = geometry; setColor(_currentGeometry.get(), osg::Vec4(1,1,1,1)); _currentImageStream = is; - + if (is->getStatus() == osg::ImageStream::PLAYING) { is->pause(); @@ -192,19 +188,19 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction { is->play(); } - + } } } } - + break; } case(osgGA::GUIEventAdapter::KEYDOWN): { if (!_currentImageStream.valid()) return false; - + if (ea.getKey()=='p') { osg::ImageStream::StreamStatus playToggle = _currentImageStream->getStatus(); @@ -232,7 +228,7 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction { std::cout << _currentImageStream.get() << " Seeking"<seek(_currentImageStream->getCurrentTime() + 1.0); - + return true; } else if (ea.getKey()=='L') @@ -255,7 +251,7 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction tm += 0.1; _currentImageStream->setTimeMultiplier(tm); std::cout << _currentImageStream.get() << " Increase speed rate "<< _currentImageStream->getTimeMultiplier() << std::endl; - + return true; } else if (ea.getKey()=='-') @@ -264,13 +260,13 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction tm -= 0.1; _currentImageStream->setTimeMultiplier(tm); std::cout << _currentImageStream.get() << " Decrease speed rate "<< _currentImageStream->getTimeMultiplier() << std::endl; - + return true; } else if (ea.getKey()=='o') { std::cout<< _currentImageStream.get() << " Frame rate "<< _currentImageStream->getFrameRate() <getTextureTarget() == GL_TEXTURE_2D) ? 1 : img->s(); float b = (_tex->getTextureTarget() == GL_TEXTURE_2D) ? 1 : img->t(); - + /* if (img->getOrigin() == osg::Image::TOP_LEFT) std::swap(t, b); */ - + osg::Vec2Array* tex_coords = dynamic_cast(_geo->getTexCoordArray(0)); if (tex_coords) { - + (*tex_coords)[0].set(l,t); (*tex_coords)[1].set(l,b); (*tex_coords)[2].set(r,b); @@ -358,47 +354,47 @@ public: } } } - + private: osg::observer_ptr _tex; osg::observer_ptr _geo; }; static osg::Node* readImageStream(const std::string& file_name, osg::Vec3& p, float desired_height, osgDB::Options* options) -{ +{ osg::ref_ptr obj = osgDB::readObjectFile(file_name, options); osg::ref_ptr tex = dynamic_cast(obj.get()); osg::Geometry* geo(NULL); float w(0); - + if (!tex) { osg::ref_ptr img_stream = dynamic_cast(obj.get()); - + // try readImageFile if readObjectFile failed if (!img_stream) { img_stream = dynamic_cast(osgDB::readImageFile(file_name, options)); } - + if (img_stream) { tex = new osg::Texture2D(img_stream.get()); tex->setResizeNonPowerOfTwoHint(false); - + } } - + // create textured quad if(tex) { osg::Geode* geode = new osg::Geode(); - + osg::ref_ptr img = dynamic_cast(tex->getImage(0)); if (img) { w = (img->t() > 0) ? img->s() * desired_height / img->t() : 0; - + osgText::Text* text = new osgText::Text(); text->setFont("arial.ttf"); text->setDataVariance(osg::Object::DYNAMIC); @@ -408,7 +404,7 @@ static osg::Node* readImageStream(const std::string& file_name, osg::Vec3& p, fl text->setAxisAlignment(osgText::TextBase::XZ_PLANE); geode->addDrawable (text); } - + if (w == 0) { // hmm, imagestream with no width? @@ -416,26 +412,25 @@ static osg::Node* readImageStream(const std::string& file_name, osg::Vec3& p, fl } float tex_s = (tex->getTextureTarget() == GL_TEXTURE_2D) ? 1 : img->s(); float tex_t = (tex->getTextureTarget() == GL_TEXTURE_2D) ? 1 : img->t(); - + if (img->getOrigin() == osg::Image::TOP_LEFT) geo = osg::createTexturedQuadGeometry(p, osg::Vec3(w, 0, 0), osg::Vec3(0, 0, desired_height), 0, tex_t, tex_s, 0); else geo = osg::createTexturedQuadGeometry(p, osg::Vec3(w, 0, 0), osg::Vec3(0, 0, desired_height), 0, 0, tex_s, tex_t); - + geode->addDrawable(geo); geo->getOrCreateStateSet()->setTextureAttributeAndModes(0, tex.get()); - + osg::Vec4Array* colors = new osg::Vec4Array(); colors->push_back(osg::Vec4(0.7, 0.7, 0.7, 1)); - - geo->setColorArray(colors); - geo->setColorBinding(osg::Geometry::BIND_OVERALL); - + + geo->setColorArray(colors, osg::Array::BIND_OVERALL); + p[0] += w + 10; - + img->addDimensionsChangedCallback(new MyDimensionsChangedCallback(tex.get(), geo)); - + return geode; } else @@ -443,7 +438,7 @@ static osg::Node* readImageStream(const std::string& file_name, osg::Vec3& p, fl std::cout << "could not read file from " << file_name << std::endl; return NULL; } - + return NULL; } @@ -455,24 +450,24 @@ public: , _tex(tex) { } - + virtual void apply(osg::Geode& geode) { apply(geode.getStateSet()); for(unsigned int i = 0; i < geode.getNumDrawables(); ++i) { osg::Drawable* drawable = geode.getDrawable(i); - + apply(drawable->getStateSet()); ImageStreamStateCallback* cb = dynamic_cast(drawable->getUpdateCallback()); if (cb) cb->setImageStream(dynamic_cast(_tex->getImage(0))); - + } - + osg::NodeVisitor::apply(geode); } - + void apply(osg::StateSet* ss) { if (ss && ss->getTextureAttribute(0, osg::StateAttribute::TEXTURE)) @@ -494,7 +489,7 @@ public: { loadSlide(_currentFile); } - + bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv) { switch(ea.getEventType()) @@ -507,37 +502,37 @@ public: loadSlide(_currentFile + 1); else return false; - + return true; } break; default: break; } - + return false; } - + private: - + void loadSlide(int new_ndx) { if (new_ndx == _currentFile) return; - + _currentFile = new_ndx; if (_currentFile < 0) _currentFile = _files.size() - 1; else if (_currentFile >= static_cast(_files.size())) _currentFile = 0; - + osg::ref_ptr obj = osgDB::readRefObjectFile(_files[_currentFile], _options.get()); osg::ref_ptr tex = dynamic_cast(obj.get()); if (!tex) { osg::ref_ptr stream = dynamic_cast(obj.get()); if (!stream) stream = dynamic_cast(osgDB::readImageFile(_files[_currentFile], _options.get())); - + if (stream) { tex = new osg::Texture2D(stream.get()); @@ -564,12 +559,12 @@ int main(int argc, char** argv) { /* std::string plugin_to_use = "AVFoundation"; // "QTKit"; - + osgDB::Registry::instance()->addFileExtensionAlias("mov", plugin_to_use); osgDB::Registry::instance()->addFileExtensionAlias("mp4", plugin_to_use); osgDB::Registry::instance()->addFileExtensionAlias("m4v", plugin_to_use); */ - + // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); @@ -582,23 +577,23 @@ int main(int argc, char** argv) arguments.getApplicationUsage()->addCommandLineOption("--disableMultiThreadedFrameDispatching","disable frame dispatching via multiple threads (QTKit+AVFoundation plugin)"); arguments.getApplicationUsage()->addCommandLineOption("--maxVideos [numVideos]","max videos to open from a folder"); arguments.getApplicationUsage()->addCommandLineOption("--slideShow","present movies in a slide-show"); - + unsigned int max_videos(10); bool slide_show = false; std::string options_str(""); - + if (arguments.find("--slideShow") > 0) { slide_show = true; } - + if (arguments.find("--disableMultiThreadedFrameDispatching") > 0) { options_str += " disableMultiThreadedFrameDispatching"; } - + if (arguments.find("--disableCoreVideo") > 0) { options_str += " disableCoreVideo"; } - + if (int ndx = arguments.find("--numFrameDispatchThreads") > 0) { options_str += std::string(" numFrameDispatchThreads=") + arguments[ndx+1]; @@ -611,13 +606,13 @@ int main(int argc, char** argv) // construct the viewer. osgViewer::Viewer viewer(arguments); - + if (arguments.argc()<=1) { arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); return 1; } - + // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) @@ -632,15 +627,15 @@ int main(int argc, char** argv) osg::StateSet* stateset = group->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - + osg::Vec3 pos(0.0f,0.0f,0.0f); static const float desired_height = 768.0f; - + osgDB::DirectoryContents files = getSuitableFiles(arguments); osgGA::GUIEventHandler* movie_event_handler(NULL); - + osg::ref_ptr options = new osgDB::ReaderWriter::Options(options_str); - + if (slide_show) { osg::Node* node = readImageStream(files[0], pos, desired_height, options.get()); @@ -653,14 +648,14 @@ int main(int argc, char** argv) unsigned int num_files_per_row = std::max(osg::round(sqrt(static_cast(std::min(max_videos, static_cast(files.size()))))), 1.0); static const float new_row_at = num_files_per_row * desired_height * 16 / 9.0; - + unsigned int num_videos = 0; for(osgDB::DirectoryContents::iterator i = files.begin(); (i != files.end()) && (num_videos < max_videos); ++i) { osg::Node* node = readImageStream(*i, pos, desired_height, options.get()); if (node) group->addChild(node); - + if (pos[0] > new_row_at) { pos[0] = 0; @@ -679,8 +674,8 @@ int main(int argc, char** argv) arguments.getApplicationUsage()->write(std::cout); return 1; } - - + + viewer.addEventHandler( movie_event_handler ); viewer.addEventHandler( new osgViewer::StatsHandler ); viewer.addEventHandler( new osgViewer::ToggleSyncToVBlankHandler()); diff --git a/examples/osgmultiplerendertargets/osgmultiplerendertargets.cpp b/examples/osgmultiplerendertargets/osgmultiplerendertargets.cpp index 501592999..bf95dc0a7 100644 --- a/examples/osgmultiplerendertargets/osgmultiplerendertargets.cpp +++ b/examples/osgmultiplerendertargets/osgmultiplerendertargets.cpp @@ -58,10 +58,10 @@ struct MyCameraPostDrawCallback : public osg::Camera::DrawCallback // we'll pick out the center 1/2 of the whole image, int column_start = _image->s()/4; int column_end = 3*column_start; - + int row_start = _image->t()/4; int row_end = 3*row_start; - + // and then halve their contribution for(int r=row_start; rs()/4; int column_end = 3*column_start; - + int row_start = _image->t()/4; int row_end = 3*row_start; - + // and then halve their contribution for(int r=row_start; rdirty(); - + //print out the first three values float* data = (float*)_image->data(0, 0); fprintf(stderr,"Float pixel data: r %e g %e b %e\n", data[0], data[1], data[2]); } } - + osg::Image* _image; }; @@ -116,7 +116,7 @@ struct MyCameraPostDrawCallback : public osg::Camera::DrawCallback osg::Group* createRTTQuad(unsigned int tex_width, unsigned int tex_height, bool useHDR) { osg::Group *top_group = new osg::Group; - + osg::ref_ptr quad_geode = new osg::Geode; osg::ref_ptr quad_coords = new osg::Vec3Array; // vertex coords @@ -141,16 +141,15 @@ osg::Group* createRTTQuad(unsigned int tex_width, unsigned int tex_height, bool quad_geom->setVertexArray(quad_coords.get()); quad_geom->setTexCoordArray(0, quad_tcoords.get()); quad_geom->addPrimitiveSet(quad_da.get()); - quad_geom->setColorArray(quad_colors.get()); - quad_geom->setColorBinding(osg::Geometry::BIND_OVERALL); - + quad_geom->setColorArray(quad_colors.get(), osg::Array::BIND_OVERALL); + osg::StateSet *stateset = quad_geom->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); stateset->addUniform(new osg::Uniform("width", (int)tex_width)); // Attach shader, glFragData is used to create data for multiple render targets - + if (useHDR) { static const char *shaderSource = { "uniform int width;" @@ -162,7 +161,7 @@ osg::Group* createRTTQuad(unsigned int tex_width, unsigned int tex_height, bool " gl_FragData[3] = vec4(0,0,1e-12,1);\n" "}\n" }; - + osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT , shaderSource); osg::ref_ptr program = new osg::Program; program->addShader(fshader.get()); @@ -178,7 +177,7 @@ osg::Group* createRTTQuad(unsigned int tex_width, unsigned int tex_height, bool " gl_FragData[3] = vec4(0,0,1,1);\n" "}\n" }; - + osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT , shaderSource); osg::ref_ptr program = new osg::Program; program->addShader(fshader.get()); @@ -186,7 +185,7 @@ osg::Group* createRTTQuad(unsigned int tex_width, unsigned int tex_height, bool } quad_geode->addDrawable(quad_geom.get()); - + top_group->addChild(quad_geode.get()); return top_group; @@ -203,7 +202,7 @@ osg::Node* createScene(osg::Node* cam_subgraph, unsigned int tex_width, unsigned // textures to render to and to use for texturing of the final quad osg::TextureRectangle* textureRect[NUM_TEXTURES] = {0,0,0,0}; - + for (int i=0;isetTextureSize(tex_width, tex_height); @@ -219,24 +218,24 @@ osg::Node* createScene(osg::Node* cam_subgraph, unsigned int tex_width, unsigned // GL_FLOAT_RGBA32_NV might be supported on pre 8-series GPUs //textureRect[i]->setInternalFormat(GL_FLOAT_RGBA32_NV); - // GL_RGBA16F_ARB can be used with this example, + // GL_RGBA16F_ARB can be used with this example, // but modify e-12 and e12 in the shaders accordingly //textureRect[i]->setInternalFormat(GL_RGBA16F_ARB); - + textureRect[i]->setSourceFormat(GL_RGBA); textureRect[i]->setSourceType(GL_FLOAT); } } // first create the geometry of the quad - { + { osg::Geometry* polyGeom = new osg::Geometry(); polyGeom->setSupportsDisplayList(false); osg::Vec3Array* vertices = new osg::Vec3Array; osg::Vec2Array* texcoords = new osg::Vec2Array; - + vertices->push_back(osg::Vec3d(0,0,0)); texcoords->push_back(osg::Vec2(0,0)); @@ -254,8 +253,7 @@ osg::Node* createScene(osg::Node* cam_subgraph, unsigned int tex_width, unsigned osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); - polyGeom->setColorArray(colors); - polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); + polyGeom->setColorArray(colors, osg::Array::BIND_OVERALL); polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,vertices->size())); @@ -264,7 +262,7 @@ osg::Node* createScene(osg::Node* cam_subgraph, unsigned int tex_width, unsigned for (int i=0;isetTextureAttributeAndModes(i, textureRect[i], osg::StateAttribute::ON); } - + polyGeom->setStateSet(stateset); // Attach a shader to the final quad to combine the input textures. @@ -308,24 +306,24 @@ osg::Node* createScene(osg::Node* cam_subgraph, unsigned int tex_width, unsigned osg::ref_ptr program = new osg::Program; program->addShader( fshader.get()); stateset->setAttributeAndModes( program.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE ); - + } stateset->addUniform(new osg::Uniform("textureID0", 0)); stateset->addUniform(new osg::Uniform("textureID1", 1)); stateset->addUniform(new osg::Uniform("textureID2", 2)); stateset->addUniform(new osg::Uniform("textureID3", 3)); - + //stateset->setDataVariance(osg::Object::DYNAMIC); - + osg::Geode* geode = new osg::Geode(); geode->addDrawable(polyGeom); - + parent->addChild(geode); } // now create the camera to do the multiple render to texture - { + { osg::Camera* camera = new osg::Camera; // set up the background color and clear mask. @@ -353,14 +351,14 @@ osg::Node* createScene(osg::Node* cam_subgraph, unsigned int tex_width, unsigned else camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0+i), textureRect[i]); - + } - + // we can also read back any of the targets as an image, modify this image and push it back if (useImage) { // which texture to get the image from const int tex_to_get = 0; - + osg::Image* image = new osg::Image; if (useHDR) { image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_FLOAT); @@ -372,7 +370,7 @@ osg::Node* createScene(osg::Node* cam_subgraph, unsigned int tex_width, unsigned camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0 + tex_to_get), image); camera->setPostDrawCallback(new MyCameraPostDrawCallback(image)); - + // push back the image to the texture textureRect[tex_to_get]->setImage(0, image); } @@ -381,7 +379,7 @@ osg::Node* createScene(osg::Node* cam_subgraph, unsigned int tex_width, unsigned camera->addChild(cam_subgraph); parent->addChild(camera); - } + } return parent; } diff --git a/examples/osgoccluder/osgoccluder.cpp b/examples/osgoccluder/osgoccluder.cpp index 59942b47d..a754074cd 100644 --- a/examples/osgoccluder/osgoccluder.cpp +++ b/examples/osgoccluder/osgoccluder.cpp @@ -44,18 +44,18 @@ class OccluderEventHandler : public osgGA::GUIEventHandler { public: - + OccluderEventHandler(osgViewer::Viewer* viewer):_viewer(viewer) {} - + virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); void addPoint(const osg::Vec3& pos); - + void endOccluder(); - + osg::Group* rootNode() { return dynamic_cast(_viewer->getSceneData()); } - - + + osgViewer::Viewer* _viewer; osg::ref_ptr _occluders; osg::ref_ptr _convexPlanarOccluder; @@ -90,7 +90,7 @@ bool OccluderEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAct { if (_occluders.valid()) { - + if (osgDB::writeNodeFile(*_occluders,"saved_occluders.osgt")) std::cout<<"saved occluders to 'saved_occluders.osgt'"<getOccluder(); occluder.add(pos); -// +// // osg::BoundingSphere bs = rootNode()->getBound(); -// +// // osg::ShapeDrawable* sd = new osg::ShapeDrawable(new osg::Sphere(pos,bs.radius()*0.001f)); // osg::Geode* geode = new osg::Geode; // geode->addDrawable(sd); -// +// // rootNode()->addChild(geode); -// - +// + } - + void OccluderEventHandler::endOccluder() { - if (_convexPlanarOccluder.valid()) + if (_convexPlanarOccluder.valid()) { if (_convexPlanarOccluder->getOccluder().getVertexList().size()>=3) { @@ -156,7 +156,7 @@ void OccluderEventHandler::endOccluder() { std::cout<<"No occluder points to create occluder with."<setOccluder(cpo); occluderNode->setName("occluder"); - + // set the occluder up for the front face of the bounding box. osg::ConvexPlanarPolygon& occluder = cpo->getOccluder(); occluder.add(v1); @@ -200,39 +200,38 @@ osg::Node* createOccluder(const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec hole.add(v4dash); cpo->addHole(hole); - } - + } + // create a drawable for occluder. osg::Geometry* geom = new osg::Geometry; - + osg::Vec3Array* coords = new osg::Vec3Array(occluder.getVertexList().begin(),occluder.getVertexList().end()); geom->setVertexArray(coords); - + osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,0.5f); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); - + geom->setColorArray(colors, osg::Array::BIND_OVERALL); + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); - + osg::Geode* geode = new osg::Geode; geode->addDrawable(geom); - + osg::StateSet* stateset = new osg::StateSet; stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); stateset->setMode(GL_BLEND,osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - + geom->setStateSet(stateset); - + // add the occluder geode as a child of the occluder, // as the occluder can't self occlude its subgraph the // geode will never be occluded by this occluder. - occluderNode->addChild(geode); - + occluderNode->addChild(geode); + return occluderNode; - + } osg::Group* createOccludersAroundModel(osg::Node* model) @@ -247,7 +246,7 @@ osg::Group* createOccludersAroundModel(osg::Node* model) // get the bounding volume of the model. const osg::BoundingSphere bs = model->getBound(); - + // create a bounding box around the sphere. osg::BoundingBox bb; bb.expandBy(bs); @@ -278,7 +277,7 @@ osg::Group* createOccludersAroundModel(osg::Node* model) 0.5f)); // create a hole half the size of the occluder. return scene; -} +} int main( int argc, char **argv ) @@ -292,7 +291,7 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); arguments.getApplicationUsage()->addCommandLineOption("-m","Mannually create occluders"); - + // initialize the viewer. osgViewer::Viewer viewer; @@ -313,34 +312,34 @@ int main( int argc, char **argv ) // load the nodes from the commandline arguments. osg::Node* loadedmodel = osgDB::readNodeFiles(arguments); - + // if not loaded assume no arguments passed in, try using default mode instead. if (!loadedmodel) loadedmodel = osgDB::readNodeFile("glider.osgt"); - + if (!loadedmodel) { osg::notify(osg::NOTICE)<<"Please specify a model filename on the command line."< rootnode; - + if (manuallyCreateOccluders) { rootnode = new osg::Group; rootnode->addChild(loadedmodel); } - else + else { rootnode = createOccludersAroundModel(loadedmodel); } - - + + // add a viewport to the viewer and attach the scene graph. viewer.setSceneData( rootnode.get() ); diff --git a/examples/osgoit/DepthPeeling.cpp b/examples/osgoit/DepthPeeling.cpp index 285996f94..f9249b8e9 100644 --- a/examples/osgoit/DepthPeeling.cpp +++ b/examples/osgoit/DepthPeeling.cpp @@ -242,8 +242,7 @@ osg::Node* DepthPeeling::createQuad(unsigned int layerNumber, unsigned int numTi geometry->setVertexArray(vertices); geometry->setTexCoordArray(0, texcoords); - geometry->setColorArray(colors); - geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + geometry->setColorArray(colors, osg::Array::BIND_OVERALL); geometry->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4)); diff --git a/examples/osgoit/HeatMap.cpp b/examples/osgoit/HeatMap.cpp index a5fdbb2a1..4b381e6fa 100644 --- a/examples/osgoit/HeatMap.cpp +++ b/examples/osgoit/HeatMap.cpp @@ -125,10 +125,10 @@ Heatmap::Heatmap(float width, float depth, float maxheight, unsigned int K, unsi xypositions->push_back(osg::Vec2(1.0f-0.5f/(O*K),((float)y+0.5f)/(O*N))); } } + xypositions->setBinding(osg::Array::BIND_PER_VERTEX); + xypositions->setNormalize(false); meshGeom->setVertexAttribArray(6, xypositions); - meshGeom->setVertexAttribNormalize(6, false); - meshGeom->setVertexAttribBinding(6, osg::Geometry::BIND_PER_VERTEX); meshGeom->setVertexArray(vertices); // generate several tri strips to form a mesh diff --git a/examples/osgoscdevice/osgoscdevice.cpp b/examples/osgoscdevice/osgoscdevice.cpp index 62c34ae1a..f982aadcc 100644 --- a/examples/osgoscdevice/osgoscdevice.cpp +++ b/examples/osgoscdevice/osgoscdevice.cpp @@ -50,13 +50,13 @@ // class to handle events with a pick class PickHandler : public osgGA::GUIEventHandler { -public: +public: PickHandler(osgGA::Device* device): _device(device) {} - + ~PickHandler() {} - + bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa); virtual void pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea); @@ -69,10 +69,10 @@ public: ea->setUserValue("name", name); ea->setUserValue("x", x); ea->setUserValue("y", y); - + _device->sendEvent(*ea); } - + protected: osg::ref_ptr _device; @@ -88,7 +88,7 @@ bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapte if (view) pick(view,ea); return false; } - + case(osgGA::GUIEventAdapter::KEYUP): { if (ea.getKey() == 't') @@ -98,18 +98,18 @@ bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapte user_event->setUserValue("vec2f", osg::Vec2f(1.0f,2.0f)); user_event->setUserValue("vec3f", osg::Vec3f(1.0f,2.0f, 3.0f)); user_event->setUserValue("vec4f", osg::Vec4f(1.0f,2.0f, 3.0f, 4.0f)); - + user_event->setUserValue("vec2d", osg::Vec2d(1.0,2.0)); user_event->setUserValue("vec3d", osg::Vec3d(1.0,2.0, 3.0)); user_event->setUserValue("vec4d", osg::Vec4d(1.0,2.0, 3.0, 4.0)); - + user_event->setName("osc_test_1"); - + _device->sendEvent(*user_event); } - + } - + default: return false; } @@ -146,7 +146,7 @@ void PickHandler::pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea) { os<<" vertex indices ["< _text; @@ -199,7 +199,7 @@ bool UserEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA { if (ea.getEventType() == osgGA::GUIEventAdapter::USER) { OSG_ALWAYS << "handle user-event: " << ea.getName() << std::endl; - + if (ea.getName() == "/pick-result") { std::string name(""); @@ -210,7 +210,7 @@ bool UserEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA std::ostringstream ss; ss << "Name: " << std::endl << name << std::endl << std::endl; ss << "x: " << y << " y: " << y << std::endl; - + _text->setText(ss.str()); } else if(ea.getName() == "/osgga") @@ -235,7 +235,7 @@ bool UserEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA { const osg::ValueObject* vo = dynamic_cast(udc->getUserObject(i)); OSG_ALWAYS << " " << vo->getName() << ": "; - + MyValueListVisitor vlv; vo->get(vlv); OSG_ALWAYS << vlv.value() << std::endl; @@ -244,7 +244,7 @@ bool UserEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA } return true; } - + return false; } @@ -262,13 +262,13 @@ osg::Node* createHUD() hudCamera->setViewMatrix(osg::Matrix::identity()); hudCamera->setRenderOrder(osg::Camera::POST_RENDER); hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT); - + std::string timesFont("fonts/times.ttf"); - + // turn lighting off for the text and disable depth test to ensure its always ontop. osg::Vec3 position(150.0f,800.0f,0.0f); osg::Vec3 delta(0.0f,-60.0f,0.0f); - + { osg::Geode* geode = new osg::Geode(); osg::StateSet* stateset = geode->getOrCreateStateSet(); @@ -276,18 +276,18 @@ osg::Node* createHUD() stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); geode->setName("simple"); hudCamera->addChild(geode); - + osgText::Text* text = new osgText::Text; geode->addDrawable( text ); - + text->setFont(timesFont); text->setText("Picking in Head Up Displays is simple!"); text->setPosition(position); - + position += delta; - } - - + } + + for (int i=0; i<5; i++) { osg::Vec3 dy(0.0f,-30.0f,0.0f); osg::Vec3 dx(120.0f,0.0f,0.0f); @@ -305,8 +305,7 @@ osg::Node* createHUD() osg::Vec4Array* colors = new osg::Vec4Array; colors = new osg::Vec4Array; colors->push_back(osg::Vec4(0.8-0.1*i,0.1*i,0.2*i, 1.0)); - quad->setColorArray(colors); - quad->setColorBinding(osg::Geometry::BIND_OVERALL); + quad->setColorArray(colors, osg::Array::BIND_OVERALL); (*vertices)[0]=position; (*vertices)[1]=position+dx; (*vertices)[2]=position+dx+dy; @@ -315,12 +314,12 @@ osg::Node* createHUD() quad->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); geode->addDrawable(quad); hudCamera->addChild(geode); - + position += delta; - } - - - + } + + + { // this displays what has been selected osg::Geode* geode = new osg::Geode(); osg::StateSet* stateset = geode->getOrCreateStateSet(); @@ -328,10 +327,10 @@ osg::Node* createHUD() stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); geode->setName("The text label"); hudCamera->addChild(geode); - + position += delta; - } - + } + return hudCamera; } @@ -340,13 +339,13 @@ osg::Node* createHUD() class ForwardToDeviceEventHandler : public osgGA::GUIEventHandler { public: ForwardToDeviceEventHandler(osgGA::Device* device) : osgGA::GUIEventHandler(), _device(device) {} - + virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, osg::Object *, osg::NodeVisitor *) { _device->sendEvent(ea); return false; } - + protected: osg::ref_ptr _device; }; @@ -354,12 +353,12 @@ protected: class OscServiceDiscoveredEventHandler: public ForwardToDeviceEventHandler { public: OscServiceDiscoveredEventHandler() : ForwardToDeviceEventHandler(NULL) {} - + virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, osg::Object *o, osg::NodeVisitor *nv) { if (_device.valid()) return ForwardToDeviceEventHandler::handle(ea, aa, o, nv); - + if (ea.getEventType() == osgGA::GUIEventAdapter::USER) { if (ea.getName() == "/zeroconf/service-added") @@ -368,13 +367,13 @@ public: unsigned int port; ea.getUserValue("host", host); ea.getUserValue("port", port); - + OSG_ALWAYS << "new osc-service discovered: " << host << ":" << port << std::endl; - + std::ostringstream ss ; ss << host << ":" << port << ".sender.osc"; _device = osgDB::readFile(ss.str()); - + osgViewer::View* view = dynamic_cast(&aa); if (view) view->addEventHandler(new PickHandler(_device.get())); @@ -383,7 +382,7 @@ public: } return false; } - + }; int main( int argc, char **argv ) @@ -391,11 +390,11 @@ int main( int argc, char **argv ) // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); - + arguments.getApplicationUsage()->addCommandLineOption("--zeroconf","uses zeroconf to advertise the osc-plugin and to discover it"); arguments.getApplicationUsage()->addCommandLineOption("--sender","create a view which sends its events via osc"); arguments.getApplicationUsage()->addCommandLineOption("--recevier","create a view which receive its events via osc"); - + // read the scene from the list of file specified commandline args. @@ -406,7 +405,7 @@ int main( int argc, char **argv ) std::cout << argv[0] << ": requires filename argument." << std::endl; return 1; } - + bool use_zeroconf(false); bool use_sender(false); bool use_receiver(false); @@ -415,7 +414,7 @@ int main( int argc, char **argv ) if(arguments.find("--receiver") > 0) { use_receiver = true; } // construct the viewer. osgViewer::CompositeViewer viewer(arguments); - + // receiver view if (use_receiver) { osg::ref_ptr traits = new osg::GraphicsContext::Traits; @@ -427,21 +426,21 @@ int main( int argc, char **argv ) traits->doubleBuffer = true; traits->sharedContext = 0; traits->windowName = "Receiver / view two"; - + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - + osgViewer::View* view = new osgViewer::View; view->setName("View two"); viewer.addView(view); - + osg::Group* group = new osg::Group(); group->addChild(scene.get()); osg::Geode* geode = new osg::Geode(); group->addChild(geode); - + osgText::Text* text = new osgText::Text(); geode->addDrawable( text ); - + text->setFont("Arial.ttf"); text->setText("Waiting for data"); text->setPosition(osg::Vec3(-50,0,30)); @@ -460,7 +459,7 @@ int main( int argc, char **argv ) if (device.valid() && (device->getCapabilities() & osgGA::Device::RECEIVE_EVENTS)) { view->addDevice(device.get()); - + // add a zeroconf device, advertising the osc-device if(use_zeroconf) { @@ -487,14 +486,14 @@ int main( int argc, char **argv ) traits->doubleBuffer = true; traits->sharedContext = 0; traits->windowName = "Sender / view one"; - + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - + osgViewer::View* view = new osgViewer::View; view->setName("View one"); viewer.addView(view); - + osg::Group* g = new osg::Group(); g->addChild(scene.get()); g->addChild(createHUD()); @@ -510,14 +509,14 @@ int main( int argc, char **argv ) view->addEventHandler( statesetManipulator.get() ); view->addEventHandler( new osgViewer::StatsHandler ); - + if (use_zeroconf) { osgGA::Device* zeroconf_device = osgDB::readFile("_osc._udp.discover.zeroconf"); if(zeroconf_device) { view->addDevice(zeroconf_device); view->getEventHandlers().push_front(new OscServiceDiscoveredEventHandler()); - + } } else @@ -527,7 +526,7 @@ int main( int argc, char **argv ) { // add as first event handler, so it gets ALL events ... view->getEventHandlers().push_front(new ForwardToDeviceEventHandler(device.get())); - + // add the demo-pick-event-handler view->addEventHandler(new PickHandler(device.get())); } @@ -537,7 +536,7 @@ int main( int argc, char **argv ) } } - + while (arguments.read("-s")) { viewer.setThreadingModel(osgViewer::CompositeViewer::SingleThreaded); } diff --git a/examples/osgpick/osgpick.cpp b/examples/osgpick/osgpick.cpp index 299a0d3ba..c6b99b9e4 100644 --- a/examples/osgpick/osgpick.cpp +++ b/examples/osgpick/osgpick.cpp @@ -53,13 +53,13 @@ // class to handle events with a pick class PickHandler : public osgGA::GUIEventHandler { -public: +public: PickHandler(osgText::Text* updateText): _updateText(updateText) {} - + ~PickHandler() {} - + bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa); virtual void pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea); @@ -68,7 +68,7 @@ public: { if (_updateText.get()) _updateText->setText(name); } - + protected: osg::ref_ptr _updateText; @@ -83,11 +83,11 @@ bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapte osgViewer::View* view = dynamic_cast(&aa); if (view) pick(view,ea); return false; - } + } case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()=='c') - { + { osgViewer::View* view = dynamic_cast(&aa); osg::ref_ptr event = new osgGA::GUIEventAdapter(ea); event->setX((ea.getXmin()+ea.getXmax())*0.5); @@ -95,7 +95,7 @@ bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapte if (view) pick(view,*event); } return false; - } + } default: return false; } @@ -106,7 +106,7 @@ void PickHandler::pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea) osgUtil::LineSegmentIntersector::Intersections intersections; std::string gdlist=""; - + if (view->computeIntersections(ea,intersections)) { for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin(); @@ -131,7 +131,7 @@ void PickHandler::pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea) { os<<" vertex indices ["<setViewMatrix(osg::Matrix::identity()); hudCamera->setRenderOrder(osg::Camera::POST_RENDER); hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT); - + std::string timesFont("fonts/times.ttf"); - + // turn lighting off for the text and disable depth test to ensure its always ontop. osg::Vec3 position(150.0f,800.0f,0.0f); osg::Vec3 delta(0.0f,-60.0f,0.0f); - + { osg::Geode* geode = new osg::Geode(); osg::StateSet* stateset = geode->getOrCreateStateSet(); @@ -166,18 +166,18 @@ osg::Node* createHUD(osgText::Text* updateText) stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); geode->setName("simple"); hudCamera->addChild(geode); - + osgText::Text* text = new osgText::Text; geode->addDrawable( text ); - + text->setFont(timesFont); text->setText("Picking in Head Up Displays is simple!"); text->setPosition(position); - + position += delta; - } - - + } + + for (int i=0; i<5; i++) { osg::Vec3 dy(0.0f,-30.0f,0.0f); osg::Vec3 dx(120.0f,0.0f,0.0f); @@ -195,8 +195,7 @@ osg::Node* createHUD(osgText::Text* updateText) osg::Vec4Array* colors = new osg::Vec4Array; colors = new osg::Vec4Array; colors->push_back(osg::Vec4(0.8-0.1*i,0.1*i,0.2*i, 1.0)); - quad->setColorArray(colors); - quad->setColorBinding(osg::Geometry::BIND_OVERALL); + quad->setColorArray(colors, osg::Array::BIND_OVERALL); (*vertices)[0]=position; (*vertices)[1]=position+dx; (*vertices)[2]=position+dx+dy; @@ -205,12 +204,12 @@ osg::Node* createHUD(osgText::Text* updateText) quad->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); geode->addDrawable(quad); hudCamera->addChild(geode); - + position += delta; - } - - - + } + + + { // this displays what has been selected osg::Geode* geode = new osg::Geode(); osg::StateSet* stateset = geode->getOrCreateStateSet(); @@ -219,17 +218,17 @@ osg::Node* createHUD(osgText::Text* updateText) geode->setName("The text label"); geode->addDrawable( updateText ); hudCamera->addChild(geode); - + updateText->setCharacterSize(20.0f); updateText->setFont(timesFont); updateText->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); updateText->setText(""); updateText->setPosition(position); updateText->setDataVariance(osg::Object::DYNAMIC); - + position += delta; - } - + } + return hudCamera; } @@ -283,7 +282,7 @@ int main( int argc, char **argv ) osg::ref_ptr updateText = new osgText::Text; - // add the HUD subgraph. + // add the HUD subgraph. group->addChild(createHUD(updateText.get())); if (arguments.read("--CompositeViewer")) @@ -324,7 +323,7 @@ int main( int argc, char **argv ) while (arguments.read("-p",pathfile)) { osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); - if (apm || !apm->valid()) + if (apm || !apm->valid()) { num = keyswitchManipulator->getNumMatrixManipulators(); keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); @@ -342,7 +341,7 @@ int main( int argc, char **argv ) // set the scene to render viewer.setSceneData(group.get()); - + return viewer.run(); } diff --git a/examples/osgplanets/osgplanets.cpp b/examples/osgplanets/osgplanets.cpp index 0ac50be68..c4b39f601 100644 --- a/examples/osgplanets/osgplanets.cpp +++ b/examples/osgplanets/osgplanets.cpp @@ -76,9 +76,8 @@ osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const osg::Vec3Array* norms = new osg::Vec3Array(1); (*norms)[0] = width^height; (*norms)[0].normalize(); - - geom->setNormalArray(norms); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); + + geom->setNormalArray(norms, osg::Array::BIND_OVERALL); osg::Vec2Array* tcoords = new osg::Vec2Array(4); (*tcoords)[0].set(0.0f,0.0f); @@ -86,15 +85,14 @@ osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const (*tcoords)[2].set(1.0f,1.0f); (*tcoords)[3].set(0.0f,1.0f); geom->setTexCoordArray(0,tcoords); - + osg::Vec4Array* colours = new osg::Vec4Array(1); (*colours)[0].set(1.0f,1.0f,1.0f,1.0f); - geom->setColorArray(colours); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colours, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); - + if (image) { osg::StateSet* stateset = new osg::StateSet; @@ -106,7 +104,7 @@ osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); geom->setStateSet(stateset); } - + return geom; } @@ -114,12 +112,12 @@ osg::Image* createBillboardImage(const osg::Vec4& centerColour, unsigned int siz { osg::Vec4 backgroundColour = centerColour; backgroundColour[3] = 0.0f; - + osg::Image* image = new osg::Image; image->allocateImage(size,size,1, GL_RGBA,GL_UNSIGNED_BYTE); - - + + float mid = (float(size)-1)*0.5f; float div = 2.0f/float(size); for(unsigned int r=0;rsetLoopMode(osg::AnimationPath::LOOP); - + int numSamples = 1000; float yaw = 0.0f; float yaw_delta = -2.0f*osg::PI/((float)numSamples-1.0f); float roll = osg::inDegrees(30.0f); - + double time=0.0f; double time_delta = looptime/(double)numSamples; for(int i=0;iinsert(time,osg::AnimationPath::ControlPoint(position,rotation)); yaw += yaw_delta; time += time_delta; } - return animationPath; + return animationPath; }// end createAnimationPath @@ -205,18 +203,18 @@ public: std::string _mapSpace; std::string _mapSun; - std::string _mapVenus; - std::string _mapMercury; + std::string _mapVenus; + std::string _mapMercury; std::string _mapEarth; std::string _mapEarthNight; std::string _mapMoon; std::string _mapMars; std::string _mapJupiter; - + double _rotateSpeedFactor; double _RorbitFactor; double _radiusFactor; - + SolarSystem() { _radiusSpace = 500.0; @@ -227,26 +225,26 @@ public: _radiusMoon = 0.1; _radiusMars = 0.53; _radiusJupiter = 5.0; - + _RorbitMercury = 11.7; _RorbitVenus = 21.6; _RorbitEarth = 30.0; _RorbitMoon = 1.0; _RorbitMars = 45.0; _RorbitJupiter = 156.0; - + // orbital period in days _rotateSpeedSun = 0.0; // should be 11.97; // 30.5 average _rotateSpeedMercury = 4.15; // 87.96 _rotateSpeedVenus = 1.62; // 224.70 _rotateSpeedEarthAndMoon = 1.0; // 365.25 - _rotateSpeedEarth = 1.0; // + _rotateSpeedEarth = 1.0; // _rotateSpeedMoon = 0.95; // _rotateSpeedMars = 0.53; // 686.98 _rotateSpeedJupiter = 0.08; // 4332.71 _tiltEarth = 23.45; // degrees - + _mapSpace = "Images/spacemap2.jpg"; _mapSun = "SolarSystem/sun256128.jpg"; _mapMercury = "SolarSystem/mercury256128.jpg"; @@ -261,15 +259,15 @@ public: _RorbitFactor = 15.0; _radiusFactor = 10.0; } - + osg::MatrixTransform* createTranslationAndTilt( double translation, double tilt ); osg::MatrixTransform* createRotation( double orbit, double speed ); - + osg::Geode* createSpace( const std::string& name, const std::string& textureName ); osg::Geode* createPlanet( double radius, const std::string& name, const osg::Vec4& color , const std::string& textureName ); osg::Geode* createPlanet( double radius, const std::string& name, const osg::Vec4& color , const std::string& textureName1, const std::string& textureName2); osg::Group* createSunLight(); - + void rotateSpeedCorrection() { _rotateSpeedSun *= _rotateSpeedFactor; @@ -280,10 +278,10 @@ public: _rotateSpeedMoon *= _rotateSpeedFactor; _rotateSpeedMars *= _rotateSpeedFactor; _rotateSpeedJupiter *= _rotateSpeedFactor; - + std::cout << "rotateSpeed corrected by factor " << _rotateSpeedFactor << std::endl; } - + void RorbitCorrection() { _RorbitMercury *= _RorbitFactor; @@ -292,10 +290,10 @@ public: _RorbitMoon *= _RorbitFactor; _RorbitMars *= _RorbitFactor; _RorbitJupiter *= _RorbitFactor; - + std::cout << "Rorbits corrected by factor " << _RorbitFactor << std::endl; } - + void radiusCorrection() { _radiusSpace *= _radiusFactor; @@ -306,11 +304,11 @@ public: _radiusMoon *= _radiusFactor; _radiusMars *= _radiusFactor; _radiusJupiter *= _radiusFactor; - + std::cout << "Radius corrected by factor " << _radiusFactor << std::endl; } void printParameters(); - + }; // end SolarSystem class FindNamedNodeVisitor : public osg::NodeVisitor @@ -319,7 +317,7 @@ public: FindNamedNodeVisitor(const std::string& name): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _name(name) {} - + virtual void apply(osg::Node& node) { if (node.getName()==_name) @@ -328,7 +326,7 @@ public: } traverse(node); } - + typedef std::vector< osg::ref_ptr > NodeList; std::string _name; @@ -358,8 +356,8 @@ osg::MatrixTransform* SolarSystem::createTranslationAndTilt( double /*translatio return moonPositioned; }// end SolarSystem::createTranslationAndTilt - - + + osg::Geode* SolarSystem::createSpace( const std::string& name, const std::string& textureName ) { osg::Sphere *spaceSphere = new osg::Sphere( osg::Vec3( 0.0, 0.0, 0.0 ), _radiusSpace ); @@ -387,7 +385,7 @@ osg::Geode* SolarSystem::createSpace( const std::string& name, const std::string }// end SolarSystem::createSpace - + osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, const osg::Vec4& color , const std::string& textureName) { // create a container that makes the sphere drawable @@ -397,11 +395,10 @@ osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, c // set the single colour so bind overall osg::Vec4Array* colours = new osg::Vec4Array(1); (*colours)[0] = color; - sPlanetSphere->setColorArray(colours); - sPlanetSphere->setColorBinding(osg::Geometry::BIND_OVERALL); + sPlanetSphere->setColorArray(colours, osg::Array::BIND_OVERALL); - // now set up the coords, normals and texcoords for geometry + // now set up the coords, normals and texcoords for geometry unsigned int numX = 100; unsigned int numY = 50; unsigned int numVertices = numX*numY; @@ -410,8 +407,7 @@ osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, c sPlanetSphere->setVertexArray(coords); osg::Vec3Array* normals = new osg::Vec3Array(numVertices); - sPlanetSphere->setNormalArray(normals); - sPlanetSphere->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + sPlanetSphere->setNormalArray(normals, osg::Array::BIND_PER_VERTEX); osg::Vec2Array* texcoords = new osg::Vec2Array(numVertices); sPlanetSphere->setTexCoordArray(0,texcoords); @@ -460,7 +456,7 @@ osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, c sPlanetSphere->addPrimitiveSet(elements); } } - + // set the object color //sPlanetSphere->setColor( color ); @@ -490,20 +486,20 @@ osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, c return( geodePlanet ); }// end SolarSystem::createPlanet - + osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, const osg::Vec4& color , const std::string& textureName1, const std::string& textureName2) { osg::Geode* geodePlanet = createPlanet( radius, name, color , textureName1); - + if( !textureName2.empty() ) { osg::Image* image = osgDB::readImageFile( textureName2 ); if ( image ) { osg::StateSet* stateset = geodePlanet->getOrCreateStateSet(); - + osg::TexEnvCombine* texenv = new osg::TexEnvCombine; - + texenv->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE); texenv->setSource0_RGB(osg::TexEnvCombine::PREVIOUS); texenv->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR); @@ -544,7 +540,7 @@ osg::Group* SolarSystem::createSunLight() return sunLightSource; }// end SolarSystem::createSunLight - + void SolarSystem::printParameters() { std::cout << "radiusSpace(" << _radiusSpace << ")" << std::endl; @@ -582,7 +578,7 @@ void SolarSystem::printParameters() std::cout << "mapMoon(" << _mapMoon << ")" << std::endl; std::cout << "mapMars(" << _mapMars << ")" << std::endl; std::cout << "mapJupiter(" << _mapJupiter << ")" << std::endl; - + std::cout << "rotateSpeedFactor(" << _rotateSpeedFactor << ")" << std::endl; std::cout << "RorbitFactor(" << _RorbitFactor << ")" << std::endl; std::cout << "radiusFactor(" << _radiusFactor << ")" << std::endl; @@ -616,15 +612,15 @@ int main( int argc, char **argv ) while (arguments.read("--radiusMoon",solarSystem._radiusMoon)) { } while (arguments.read("--radiusMars",solarSystem._radiusMars)) { } while (arguments.read("--radiusJupiter",solarSystem._radiusJupiter)) { } - + while (arguments.read("--RorbitEarth",solarSystem._RorbitEarth)) { } while (arguments.read("--RorbitMoon",solarSystem._RorbitMoon)) { } - + while (arguments.read("--rotateSpeedEarthAndMoon",solarSystem._rotateSpeedEarthAndMoon)) { } while (arguments.read("--rotateSpeedEarth",solarSystem._rotateSpeedEarth)) { } while (arguments.read("--rotateSpeedMoon",solarSystem._rotateSpeedMoon)) { } while (arguments.read("--tiltEarth",solarSystem._tiltEarth)) { } - + while (arguments.read("--mapSpace",solarSystem._mapSpace)) { } while (arguments.read("--mapEarth",solarSystem._mapEarth)) { } while (arguments.read("--mapEarthNight",solarSystem._mapEarthNight)) { } @@ -633,15 +629,15 @@ int main( int argc, char **argv ) while (arguments.read("--rotateSpeedFactor",solarSystem._rotateSpeedFactor)) { } while (arguments.read("--RorbitFactor",solarSystem._RorbitFactor)) { } while (arguments.read("--radiusFactor",solarSystem._radiusFactor)) { } - + solarSystem.rotateSpeedCorrection(); solarSystem.RorbitCorrection(); solarSystem.radiusCorrection(); - + std::string writeFileName; while (arguments.read("-o",writeFileName)) { } - - + + osgGA::NodeTrackerManipulator::TrackerMode trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION; std::string mode; while (arguments.read("--tracker-mode",mode)) @@ -658,8 +654,8 @@ int main( int argc, char **argv ) return 1; } } - - + + osgGA::NodeTrackerManipulator::RotationMode rotationMode = osgGA::NodeTrackerManipulator::TRACKBALL; while (arguments.read("--rotation-mode",mode)) { @@ -673,7 +669,7 @@ int main( int argc, char **argv ) return 1; } } - + // solarSystem.printParameters(); @@ -689,14 +685,14 @@ int main( int argc, char **argv ) std::cout << "\t--radiusMoon: double" << std::endl; std::cout << "\t--radiusMars: double" << std::endl; std::cout << "\t--radiusJupiter: double" << std::endl; - + std::cout << "\t--RorbitMercury: double" << std::endl; std::cout << "\t--RorbitVenus: double" << std::endl; std::cout << "\t--RorbitEarth: double" << std::endl; std::cout << "\t--RorbitMoon: double" << std::endl; std::cout << "\t--RorbitMars: double" << std::endl; std::cout << "\t--RorbitJupiter: double" << std::endl; - + std::cout << "\t--rotateSpeedMercury: double" << std::endl; std::cout << "\t--rotateSpeedVenus: double" << std::endl; std::cout << "\t--rotateSpeedEarthAndMoon: double" << std::endl; @@ -706,7 +702,7 @@ int main( int argc, char **argv ) std::cout << "\t--rotateSpeedJupiter: double" << std::endl; std::cout << "\t--tiltEarth: double" << std::endl; - + std::cout << "\t--mapSpace: string" << std::endl; std::cout << "\t--mapSun: string" << std::endl; std::cout << "\t--mapMercury: string" << std::endl; @@ -716,11 +712,11 @@ int main( int argc, char **argv ) std::cout << "\t--mapMoon: string" << std::endl; std::cout << "\t--mapMars: string" << std::endl; std::cout << "\t--mapJupiter: string" << std::endl; - + std::cout << "\t--rotateSpeedFactor: string" << std::endl; std::cout << "\t--RorbitFactor: string" << std::endl; std::cout << "\t--radiusFactor: string" << std::endl; - + return 1; } @@ -733,10 +729,10 @@ int main( int argc, char **argv ) arguments.writeErrorMessages(std::cout); return 1; } - - + + osg::Group* root = new osg::Group; - + osg::ClearNode* clearNode = new osg::ClearNode; clearNode->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); root->addChild(clearNode); @@ -756,7 +752,7 @@ int main( int argc, char **argv ) sunBillboard->addDrawable( createSquare(osg::Vec3(-150.0f,0.0f,-150.0f),osg::Vec3(300.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,300.0f),createBillboardImage( osg::Vec4( 1.0, 1.0, 0, 1.0f), 64, 1.0) ), osg::Vec3(0.0f,0.0f,0.0f)); - + sunLight->addChild( sunBillboard ); @@ -767,7 +763,7 @@ int main( int argc, char **argv ) /* ********************************************* -** earthMoonGroup and Transformations +** earthMoonGroup and Transformations ********************************************* */ // create earth and moon @@ -782,7 +778,7 @@ int main( int argc, char **argv ) //Group with earth and moon under it osg::Group* earthMoonGroup = new osg::Group; - + //transformation to rotate the earth around itself osg::MatrixTransform* earthAroundItselfRotation = solarSystem.createRotation ( 0.0, solarSystem._rotateSpeedEarth ); @@ -797,7 +793,7 @@ int main( int argc, char **argv ) earthAroundItselfRotation->addChild( earth ); earthMoonGroup->addChild( earthAroundItselfRotation ); - + earthMoonGroupPosition->addChild( earthMoonGroup ); aroundSunRotationEarthMoonGroup->addChild( earthMoonGroupPosition ); @@ -805,87 +801,87 @@ int main( int argc, char **argv ) sunLight->addChild( aroundSunRotationEarthMoonGroup ); /* ********************************************* -** end earthMoonGroup and Transformations +** end earthMoonGroup and Transformations ********************************************* */ /* ********************************************* -** Mercury and Transformations +** Mercury and Transformations ********************************************* */ osg::Node* mercury = solarSystem.createPlanet( solarSystem._radiusMercury, "Mercury", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapMercury, "" ); - + osg::MatrixTransform* aroundSunRotationMercury = solarSystem.createRotation( solarSystem._RorbitMercury, solarSystem._rotateSpeedMercury ); osg::MatrixTransform* mercuryPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitMercury, 0.0f ); - + mercuryPosition->addChild( mercury ); aroundSunRotationMercury->addChild( mercuryPosition ); - + sunLight->addChild( aroundSunRotationMercury ); /* ********************************************* -** end Mercury and Transformations +** end Mercury and Transformations ********************************************* */ /* ********************************************* -** Venus and Transformations +** Venus and Transformations ********************************************* */ osg::Node* venus = solarSystem.createPlanet( solarSystem._radiusVenus, "Venus", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapVenus, "" ); - + osg::MatrixTransform* aroundSunRotationVenus = solarSystem.createRotation( solarSystem._RorbitVenus, solarSystem._rotateSpeedVenus ); osg::MatrixTransform* venusPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitVenus, 0.0f ); - + venusPosition->addChild( venus ); aroundSunRotationVenus->addChild( venusPosition ); - + sunLight->addChild( aroundSunRotationVenus ); /* ********************************************* -** end Venus and Transformations +** end Venus and Transformations ********************************************* */ /* ********************************************* -** Mars and Transformations +** Mars and Transformations ********************************************* */ osg::Node* mars = solarSystem.createPlanet( solarSystem._radiusMars, "Mars", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapMars, "" ); - + osg::MatrixTransform* aroundSunRotationMars = solarSystem.createRotation( solarSystem._RorbitMars, solarSystem._rotateSpeedMars ); osg::MatrixTransform* marsPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitMars, 0.0f ); - + marsPosition->addChild( mars ); aroundSunRotationMars->addChild( marsPosition ); - + sunLight->addChild( aroundSunRotationMars ); /* ********************************************* -** end Mars and Transformations +** end Mars and Transformations ********************************************* */ /* ********************************************* -** Jupiter and Transformations +** Jupiter and Transformations ********************************************* */ osg::Node* jupiter = solarSystem.createPlanet( solarSystem._radiusJupiter, "Jupiter", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapJupiter, "" ); - + osg::MatrixTransform* aroundSunRotationJupiter = solarSystem.createRotation( solarSystem._RorbitJupiter, solarSystem._rotateSpeedJupiter ); osg::MatrixTransform* jupiterPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitJupiter, 0.0f ); - + jupiterPosition->addChild( jupiter ); aroundSunRotationJupiter->addChild( jupiterPosition ); - + sunLight->addChild( aroundSunRotationJupiter ); /* ********************************************* -** end Jupiter and Transformations +** end Jupiter and Transformations ********************************************* */ @@ -894,8 +890,8 @@ int main( int argc, char **argv ) osg::Node* space = solarSystem.createSpace( "Space", solarSystem._mapSpace ); space->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); root->addChild( space ); -*/ - +*/ + if (!writeFileName.empty()) { osgDB::writeNodeFile(*root, writeFileName); @@ -907,7 +903,7 @@ int main( int argc, char **argv ) // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize( root ); - + // set the scene to render viewer.setSceneData( root ); @@ -929,7 +925,7 @@ int main( int argc, char **argv ) keyswitchManipulator->addMatrixManipulator( 'm', "moon", tm ); keyswitchManipulator->selectMatrixManipulator( num ); } - } + } { FindNamedNodeVisitor fnnv("Earth"); @@ -947,8 +943,8 @@ int main( int argc, char **argv ) keyswitchManipulator->addMatrixManipulator( 'e', "earth", tm); keyswitchManipulator->selectMatrixManipulator( num ); } - } - + } + { FindNamedNodeVisitor fnnv("Sun"); root->accept(fnnv); @@ -965,7 +961,7 @@ int main( int argc, char **argv ) keyswitchManipulator->addMatrixManipulator( 's', "sun", tm); keyswitchManipulator->selectMatrixManipulator( num ); } - } + } return viewer.run(); diff --git a/examples/osgpointsprite/osgpointsprite.cpp b/examples/osgpointsprite/osgpointsprite.cpp index 41e096cc7..1bbef0df2 100644 --- a/examples/osgpointsprite/osgpointsprite.cpp +++ b/examples/osgpointsprite/osgpointsprite.cpp @@ -55,8 +55,7 @@ osg::Geode *makeGalaxy(unsigned 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->setColorArray(colors, osg::Array::BIND_PER_VERTEX); galaxy->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, nvertices)); geode->addDrawable(galaxy); return geode; diff --git a/examples/osgprerender/osgprerender.cpp b/examples/osgprerender/osgprerender.cpp index 8b0de5277..d2794e3c0 100644 --- a/examples/osgprerender/osgprerender.cpp +++ b/examples/osgprerender/osgprerender.cpp @@ -46,12 +46,12 @@ #include // call back which creates a deformation field to oscillate the model. -class MyGeometryCallback : - public osg::Drawable::UpdateCallback, +class MyGeometryCallback : + public osg::Drawable::UpdateCallback, public osg::Drawable::AttributeFunctor { public: - + MyGeometryCallback(const osg::Vec3& o, const osg::Vec3& x,const osg::Vec3& y,const osg::Vec3& z, double period,double xphase,double amplitude): @@ -65,11 +65,11 @@ class MyGeometryCallback : _xAxis(x), _yAxis(y), _zAxis(z) {} - + virtual void update(osg::NodeVisitor* nv,osg::Drawable* drawable) { // OpenThreads::Thread::microSleep( 1000 ); - + const osg::FrameStamp* fs = nv->getFrameStamp(); double simulationTime = fs->getSimulationTime(); if (_firstCall) @@ -77,37 +77,37 @@ class MyGeometryCallback : _firstCall = false; _startTime = simulationTime; } - + _time = simulationTime-_startTime; - + drawable->accept(*this); drawable->dirtyBound(); - + osg::Geometry* geometry = dynamic_cast(drawable); if (geometry) { osgUtil::SmoothingVisitor::smooth(*geometry); } - + } - - virtual void apply(osg::Drawable::AttributeType type,unsigned int count,osg::Vec3* begin) + + virtual void apply(osg::Drawable::AttributeType type,unsigned int count,osg::Vec3* begin) { if (type == osg::Drawable::VERTICES) { const float TwoPI=2.0f*osg::PI; const float phase = -_time/_period; - + osg::Vec3* end = begin+count; for (osg::Vec3* itr=begin;itrs()/4; int column_end = 3*column_start; - + int row_start = _image->t()/4; int row_end = 3*row_start; - + // and then invert these pixels for(int r=row_start; rs()/4; int column_end = 3*column_start; - + int row_start = _image->t()/4; int row_end = 3*row_start; - + // and then invert these pixels for(int r=row_start; rdirty(); } - + } - + osg::Image* _image; }; -osg::Node* createPreRenderSubGraph(osg::Node* subgraph, - unsigned tex_width, unsigned tex_height, - osg::Camera::RenderTargetImplementation renderImplementation, - bool useImage, bool useTextureRectangle, bool useHDR, +osg::Node* createPreRenderSubGraph(osg::Node* subgraph, + unsigned tex_width, unsigned tex_height, + osg::Camera::RenderTargetImplementation renderImplementation, + bool useImage, bool useTextureRectangle, bool useHDR, unsigned int samples, unsigned int colorSamples) { if (!subgraph) return 0; @@ -221,7 +221,7 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, textureRect->setInternalFormat(GL_RGBA); textureRect->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); textureRect->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); - + texture = textureRect; } else @@ -231,9 +231,9 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, texture2D->setInternalFormat(GL_RGBA); texture2D->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); texture2D->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); - + texture = texture2D; - } + } if (useHDR) { @@ -243,7 +243,7 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, } // first create the geometry of the flag of which to view. - { + { // create the to visualize. osg::Geometry* polyGeom = new osg::Geometry(); @@ -266,7 +266,7 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, osg::Vec3 dv = xAxis*(width/((float)(noSteps-1))); osg::Vec2Array* texcoords = new osg::Vec2Array; - + // note, when we use TextureRectangle we have to scale the tex coords up to compensate. osg::Vec2 bottom_texcoord(0.0f,0.0f); osg::Vec2 top_texcoord(0.0f, useTextureRectangle ? tex_height : 1.0f); @@ -293,12 +293,11 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); - polyGeom->setColorArray(colors); - polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); + polyGeom->setColorArray(colors, osg::Array::BIND_OVERALL); polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,vertices->size())); - // new we need to add the texture to the Drawable, we do so by creating a + // new we need to add the texture to the Drawable, we do so by creating a // StateSet to contain the Texture StateAttribute. osg::StateSet* stateset = new osg::StateSet; @@ -310,14 +309,14 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, osg::Geode* geode = new osg::Geode(); geode->addDrawable(polyGeom); - + parent->addChild(geode); } // then create the camera node to do the render to texture - { + { osg::Camera* camera = new osg::Camera; // set up the background color and clear mask. @@ -356,7 +355,7 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, // tell the camera to use OpenGL frame buffer object where supported. camera->setRenderTargetImplementation(renderImplementation); - + if (useImage) { osg::Image* image = new osg::Image; @@ -366,9 +365,9 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, // attach the image so its copied on each frame. camera->attach(osg::Camera::COLOR_BUFFER, image, samples, colorSamples); - + camera->setPostDrawCallback(new MyCameraPostDrawCallback(image)); - + // Rather than attach the texture directly to illustrate the texture's ability to // detect an image update and to subload the image onto the texture. You needn't // do this when using an Image for copying to, as a separate camera->attach(..) @@ -382,7 +381,7 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, else { // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, + camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, 0, false, samples, colorSamples); } @@ -393,7 +392,7 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph, parent->addChild(camera); - } + } return parent; } @@ -415,7 +414,7 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->addCommandLineOption("--height","Set the height of the render to texture."); arguments.getApplicationUsage()->addCommandLineOption("--image","Render to an image, then apply a post draw callback to it, and use this image to update a texture."); arguments.getApplicationUsage()->addCommandLineOption("--texture-rectangle","Use osg::TextureRectangle for doing the render to texture to."); - + // construct the viewer. osgViewer::Viewer viewer(arguments); @@ -439,12 +438,12 @@ int main( int argc, char **argv ) unsigned int tex_height = 512; unsigned int samples = 0; unsigned int colorSamples = 0; - + while (arguments.read("--width", tex_width)) {} while (arguments.read("--height", tex_height)) {} osg::Camera::RenderTargetImplementation renderImplementation = osg::Camera::FRAME_BUFFER_OBJECT; - + while (arguments.read("--fbo")) { renderImplementation = osg::Camera::FRAME_BUFFER_OBJECT; } while (arguments.read("--pbuffer")) { renderImplementation = osg::Camera::PIXEL_BUFFER; } while (arguments.read("--pbuffer-rtt")) { renderImplementation = osg::Camera::PIXEL_BUFFER_RTT; } @@ -455,25 +454,25 @@ int main( int argc, char **argv ) bool useImage = false; while (arguments.read("--image")) { useImage = true; } - + bool useTextureRectangle = false; while (arguments.read("--texture-rectangle")) { useTextureRectangle = true; } - + bool useHDR = false; while (arguments.read("--hdr")) { useHDR = true; } - + // load the nodes from the commandline arguments. osg::Node* loadedModel = osgDB::readNodeFiles(arguments); - + // if not loaded assume no arguments passed in, try use default mode instead. if (!loadedModel) loadedModel = osgDB::readNodeFile("cessna.osgt"); - + if (!loadedModel) { return 1; } - + // create a transform to spin the model. osg::MatrixTransform* loadedModelTransform = new osg::MatrixTransform; loadedModelTransform->addChild(loadedModel); diff --git a/examples/osgreflect/osgreflect.cpp b/examples/osgreflect/osgreflect.cpp index 0254a655c..d9367b0b4 100644 --- a/examples/osgreflect/osgreflect.cpp +++ b/examples/osgreflect/osgreflect.cpp @@ -38,7 +38,7 @@ #include // -// A simple demo demonstrating planar reflections using multiple renderings +// A simple demo demonstrating planar reflections using multiple renderings // of a subgraph, overriding of state attribures and use of the stencil buffer. // // The multipass system implemented here is a variation if Mark Kilgard's @@ -54,14 +54,14 @@ // Although there is still some unresolved issue with the clip plane needing // to be flipped when looking at the reverse side of the mirror. Niether // of these issues are mentioned in the Mark's paper, but trip us up when -// we apply them. +// we apply them. osg::StateSet* createMirrorTexturedState(const std::string& filename) { osg::StateSet* dstate = new osg::StateSet; dstate->setMode(GL_CULL_FACE,osg::StateAttribute::OFF|osg::StateAttribute::PROTECTED); - + // set up the texture. osg::Image* image = osgDB::readImageFile(filename.c_str()); if (image) @@ -70,14 +70,14 @@ osg::StateSet* createMirrorTexturedState(const std::string& filename) texture->setImage(image); dstate->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON|osg::StateAttribute::PROTECTED); } - + return dstate; } osg::Drawable* createMirrorSurface(float xMin,float xMax,float yMin,float yMax,float z) { - + // set up the drawstate. // set up the Geometry. @@ -92,8 +92,7 @@ osg::Drawable* createMirrorSurface(float xMin,float xMax,float yMin,float yMax,f osg::Vec3Array* norms = new osg::Vec3Array(1); (*norms)[0].set(0.0f,0.0f,1.0f); - geom->setNormalArray(norms); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); + geom->setNormalArray(norms, osg::Array::BIND_OVERALL); osg::Vec2Array* tcoords = new osg::Vec2Array(4); (*tcoords)[0].set(0.0f,1.0f); @@ -101,11 +100,10 @@ osg::Drawable* createMirrorSurface(float xMin,float xMax,float yMin,float yMax,f (*tcoords)[2].set(1.0f,0.0f); (*tcoords)[3].set(1.0f,1.0f); geom->setTexCoordArray(0,tcoords); - + osg::Vec4Array* colours = new osg::Vec4Array(1); (*colours)[0].set(1.0f,1.0f,1.0,1.0f); - geom->setColorArray(colours); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colours, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); @@ -121,33 +119,33 @@ osg::Node* createMirroredScene(osg::Node* model) float width_factor = 1.5; float height_factor = 0.3; - + float xMin = bs.center().x()-bs.radius()*width_factor; float xMax = bs.center().x()+bs.radius()*width_factor; float yMin = bs.center().y()-bs.radius()*width_factor; float yMax = bs.center().y()+bs.radius()*width_factor; - + float z = bs.center().z()-bs.radius()*height_factor; - - + + // create a textured, transparent node at the appropriate place. osg::Drawable* mirror = createMirrorSurface(xMin,xMax,yMin,yMax,z); - + osg::MatrixTransform* rootNode = new osg::MatrixTransform; rootNode->setMatrix(osg::Matrix::rotate(osg::inDegrees(45.0f),1.0f,0.0f,0.0f)); - + // make sure that the global color mask exists. osg::ColorMask* rootColorMask = new osg::ColorMask; - rootColorMask->setMask(true,true,true,true); - + rootColorMask->setMask(true,true,true,true); + // set up depth to be inherited by the rest of the scene unless // overrideen. this is overridden in bin 3. osg::Depth* rootDepth = new osg::Depth; rootDepth->setFunction(osg::Depth::LESS); rootDepth->setRange(0.0,1.0); - osg::StateSet* rootStateSet = new osg::StateSet(); + osg::StateSet* rootStateSet = new osg::StateSet(); rootStateSet->setAttribute(rootColorMask); rootStateSet->setAttribute(rootDepth); @@ -156,60 +154,60 @@ osg::Node* createMirroredScene(osg::Node* model) // bin1 - set up the stencil values and depth for mirror. { - + // set up the stencil ops so that the stencil buffer get set at - // the mirror plane + // the mirror plane osg::Stencil* stencil = new osg::Stencil; stencil->setFunction(osg::Stencil::ALWAYS,1,~0u); stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::REPLACE); - + // switch off the writing to the color bit planes. osg::ColorMask* colorMask = new osg::ColorMask; colorMask->setMask(false,false,false,false); - - osg::StateSet* statesetBin1 = new osg::StateSet(); + + osg::StateSet* statesetBin1 = new osg::StateSet(); statesetBin1->setRenderBinDetails(1,"RenderBin"); statesetBin1->setMode(GL_CULL_FACE,osg::StateAttribute::OFF); statesetBin1->setAttributeAndModes(stencil,osg::StateAttribute::ON); statesetBin1->setAttribute(colorMask); - + // set up the mirror geode. osg::Geode* geode = new osg::Geode; geode->addDrawable(mirror); geode->setStateSet(statesetBin1); - + rootNode->addChild(geode); - + } - // bin one - draw scene without mirror or reflection, unset + // bin one - draw scene without mirror or reflection, unset // stencil values where scene is infront of mirror and hence - // occludes the mirror. - { + // occludes the mirror. + { osg::Stencil* stencil = new osg::Stencil; stencil->setFunction(osg::Stencil::ALWAYS,0,~0u); stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::REPLACE); - osg::StateSet* statesetBin2 = new osg::StateSet(); + osg::StateSet* statesetBin2 = new osg::StateSet(); statesetBin2->setRenderBinDetails(2,"RenderBin"); statesetBin2->setAttributeAndModes(stencil,osg::StateAttribute::ON); - + osg::Group* groupBin2 = new osg::Group(); groupBin2->setStateSet(statesetBin2); groupBin2->addChild(model); - + rootNode->addChild(groupBin2); } - + // bin3 - set up the depth to the furthest depth value { - + // set up the stencil ops so that only operator on this mirrors stencil value. osg::Stencil* stencil = new osg::Stencil; stencil->setFunction(osg::Stencil::EQUAL,1,~0u); stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); - + // switch off the writing to the color bit planes. osg::ColorMask* colorMask = new osg::ColorMask; colorMask->setMask(false,false,false,false); @@ -225,24 +223,24 @@ osg::Node* createMirroredScene(osg::Node* model) statesetBin3->setAttributeAndModes(stencil,osg::StateAttribute::ON); statesetBin3->setAttribute(colorMask); statesetBin3->setAttribute(depth); - + // set up the mirror geode. osg::Geode* geode = new osg::Geode; geode->addDrawable(mirror); geode->setStateSet(statesetBin3); - + rootNode->addChild(geode); - + } // bin4 - draw the reflection. { - + // now create the 'reflection' of the loaded model by applying // create a Transform which flips the loaded model about the z axis // relative to the mirror node, the loadedModel is added to the // Transform so now appears twice in the scene, but is shared so there - // is negligable memory overhead. Also use an osg::StateSet + // is negligable memory overhead. Also use an osg::StateSet // attached to the Transform to override the face culling on the subgraph // to prevert an 'inside' out view of the reflected model. // set up the stencil ops so that only operator on this mirrors stencil value. @@ -280,13 +278,13 @@ osg::Node* createMirroredScene(osg::Node* model) clipNode->addChild(reverseMatrix); rootNode->addChild(clipNode); - + } // bin5 - draw the textured mirror and blend it with the reflection. { - + // set up depth so all writing to depth goes to maximum depth. osg::Depth* depth = new osg::Depth; depth->setFunction(osg::Depth::ALWAYS); @@ -306,16 +304,16 @@ osg::Node* createMirroredScene(osg::Node* model) statesetBin5->setAttributeAndModes(stencil,osg::StateAttribute::ON); statesetBin5->setAttributeAndModes(trans,osg::StateAttribute::ON); statesetBin5->setAttribute(depth); - + // set up the mirror geode. osg::Geode* geode = new osg::Geode; geode->addDrawable(mirror); geode->setStateSet(statesetBin5); - + rootNode->addChild(geode); } - + return rootNode; } @@ -338,12 +336,12 @@ int main( int argc, char **argv ) // read the scene from the list of file specified commandline args. osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); - + // if not loaded assume no arguments passed in, try use default mode instead. if (!loadedModel) loadedModel = osgDB::readNodeFile("cessna.osgt"); // if no model has been successfully loaded report failure. - if (!loadedModel) + if (!loadedModel) { std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; return 1; diff --git a/examples/osgshaderterrain/osgshaderterrain.cpp b/examples/osgshaderterrain/osgshaderterrain.cpp index aab69f4ad..0d33b4828 100644 --- a/examples/osgshaderterrain/osgshaderterrain.cpp +++ b/examples/osgshaderterrain/osgshaderterrain.cpp @@ -53,7 +53,7 @@ osg::Node* createScene() { osg::Group* scene = new osg::Group; - + unsigned int numColumns = 38; unsigned int numRows = 39; unsigned int r; @@ -99,7 +99,7 @@ osg::Node* createScene() max_z = osg::maximum(max_z,vertex[r+c*numRows][2]); } } - + float scale_z = size.z()/(max_z-min_z); osg::Image* terrainImage = new osg::Image; @@ -112,7 +112,7 @@ osg::Node* createScene() *((float*)(terrainImage->data(c,r))) = (vertex[r+c*numRows][2]-min_z)*scale_z; } } - + osg::Texture2D* terrainTexture = new osg::Texture2D; terrainTexture->setImage(terrainImage); terrainTexture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST); @@ -125,12 +125,12 @@ osg::Node* createScene() if (image) { osg::Texture2D* texture = new osg::Texture2D; - + texture->setImage(image); stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON); } - { + { std::cout<<"Creating terrain..."; osg::Geode* geode = new osg::Geode(); @@ -143,10 +143,10 @@ osg::Node* createScene() #if 1 // use inline shaders - + /////////////////////////////////////////////////////////////////// // vertex shader using just Vec4 coefficients - char vertexShaderSource[] = + char vertexShaderSource[] = "uniform sampler2D terrainTexture;\n" "uniform vec3 terrainOrigin;\n" "uniform vec3 terrainScaleDown;\n" @@ -172,7 +172,7 @@ osg::Node* createScene() ////////////////////////////////////////////////////////////////// // fragment shader // - char fragmentShaderSource[] = + char fragmentShaderSource[] = "uniform sampler2D baseTexture; \n" "varying vec2 texcoord;\n" "\n" @@ -183,7 +183,7 @@ osg::Node* createScene() program->addShader(new osg::Shader(osg::Shader::VERTEX, vertexShaderSource)); program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource)); - + #else // get shaders from source @@ -229,8 +229,7 @@ osg::Node* createScene() } geometry->setVertexArray(&v); - geometry->setColorArray(&color); - geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + geometry->setColorArray(&color, osg::Array::BIND_OVERALL); for(r=0;rsetInitialBound(osg::BoundingBox(origin, origin+size)); geode->addDrawable(geometry); @@ -251,9 +250,9 @@ osg::Node* createScene() scene->addChild(geode); } } - + std::cout<<"done."< testSupportOperation = new TestSupportOperation; -#if 0 - // temporily commenting out as its causing the viewer to crash... no clue yet to why +#if 0 + // temporily commenting out as its causing the viewer to crash... no clue yet to why viewer.setRealizeOperation(testSupportOperation.get()); #endif // create the windows and run the threads. viewer.realize(); - + if (!testSupportOperation->_supported) { osg::notify(osg::WARN)<_errorMessage<push_back( p + osg::Vec3( -4 - r, -4 -r, h * 2 / 3 ) * s ); + vertices->push_back( p + osg::Vec3( -4 - r, -4 -r, h * 2 / 3 ) * s ); vertices->push_back( p + osg::Vec3( -4 - r, 4 + r, h * 2 / 3 ) * s ); vertices->push_back( p + osg::Vec3( 4 + r, 4 + r, h * 2 / 3 ) * s ); - vertices->push_back( p + osg::Vec3( 4 + r, -4 -r, h * 2 / 3 ) * s ); + vertices->push_back( p + osg::Vec3( 4 + r, -4 -r, h * 2 / 3 ) * s ); normals->push_back( osg::Vec3(0, 0, 1) ); normals->push_back( osg::Vec3(0, 0, 1) ); @@ -329,7 +329,7 @@ static void addTree //////////////////////////////////////////////////////////////////////////////// static void addHouse ( const osg::Vec3 & p, - osg::Vec3Array* vertices, osg::Vec3Array* normals, osg::Vec2Array* texCoords, + osg::Vec3Array* vertices, osg::Vec3Array* normals, osg::Vec2Array* texCoords, float r = 3, float h = 10.f, float s = 3.f ) { float te = 0.5 / 64; @@ -380,7 +380,7 @@ static void addHouse } //////////////////////////////////////////////////////////////////////////////// static osg::Geode* createObjects( osg::HeightField * grid, unsigned int density ) -{ +{ osg::Geode* geode = new osg::Geode; // set up the texture of the base. @@ -399,7 +399,7 @@ static osg::Geode* createObjects( osg::HeightField * grid, unsigned int density stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); stateset->setMode( GL_BLEND,osg::StateAttribute::ON ); - + stateset->setAttributeAndModes( new osg::CullFace() ); stateset->setAttributeAndModes( new osg::Depth( osg::Depth::LESS, 0.f, 1.f, true ) ); stateset->setAttributeAndModes( new osg::AlphaFunc( osg::AlphaFunc::GEQUAL, 0.5f ) ); @@ -413,15 +413,13 @@ static osg::Geode* createObjects( osg::HeightField * grid, unsigned int density geometry->setVertexArray(vertices); osg::Vec3Array* normals = new osg::Vec3Array; - geometry->setNormalArray(normals); - geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + geometry->setNormalArray(normals, osg::Array::BIND_PER_VERTEX); osg::Vec2Array* texCoords = new osg::Vec2Array; - geometry->setTexCoordArray(0, texCoords); + geometry->setTexCoordArray(0, texCoords); osg::Vec4Array* colours = new osg::Vec4Array; - geometry->setColorArray(colours); - geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + geometry->setColorArray(colours, osg::Array::BIND_OVERALL); colours->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); for( unsigned int x = 0; x < grid->getNumColumns() - 1; x++ ) @@ -446,16 +444,16 @@ static osg::Geode* createObjects( osg::HeightField * grid, unsigned int density { osg::Vec3 p( float( rand() ) / RAND_MAX, float( rand() ) / RAND_MAX, 0 ); - z = ( 1.f - p[0] ) * ( 1.f - p[1] ) * z00 + + z = ( 1.f - p[0] ) * ( 1.f - p[1] ) * z00 + ( 1.f - p[0] ) * ( p[1] ) * z01 + ( p[0] ) * ( p[1] ) * z11 + - ( p[0] ) * ( 1.f - p[1] ) * z10; + ( p[0] ) * ( 1.f - p[1] ) * z10; osg::Vec3 pos(o + osg::Vec3(p.x() * grid->getXInterval(), p.y() * grid->getYInterval(), z)); - + if( rand() % 3 > 0 ) addTree( pos, vertices, normals, texCoords ); - else + else addHouse( pos, vertices, normals, texCoords ); } @@ -475,34 +473,34 @@ osg::Node* createIsland(const osg::Vec3& center = osg::Vec3( 0,0,0 ), float radi osg::ref_ptr group = new osg::Group; osg::ref_ptr heightMap = new osg::Image(); - heightMap->setImage( 64, 64, 1, - GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, - orderBytes( heightTexture, sizeof( heightTexture ) ), + heightMap->setImage( 64, 64, 1, + GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, + orderBytes( heightTexture, sizeof( heightTexture ) ), osg::Image::NO_DELETE ); osg::ref_ptr colorMap = NULL; // osgDB::readImageFile("Images/colorMap.png"); if ( !colorMap ) { - - struct colorElevation + + struct colorElevation { colorElevation(unsigned int elev, const osg::Vec4ub& c): elevation(elev), color(c) {} - - unsigned int elevation; + + unsigned int elevation; osg::Vec4ub color; }; - + colorElevation colorElevationMap[] = { - colorElevation(0, osg::Vec4ub( 0, 128, 255, 255 )), + colorElevation(0, osg::Vec4ub( 0, 128, 255, 255 )), colorElevation(8, osg::Vec4ub( 192, 192, 128, 255 )), colorElevation(32, osg::Vec4ub( 0, 255, 0, 255 )), colorElevation(128, osg::Vec4ub( 128, 128, 128, 255 )), colorElevation(192, osg::Vec4ub( 96, 96, 96, 255 )), colorElevation(255, osg::Vec4ub( 255, 255, 255, 255 )), colorElevation(256, osg::Vec4ub( 255, 255, 255, 255 )) - }; + }; colorMap = new osg::Image(); colorMap->allocateImage( heightMap->s(), heightMap->t(),1, GL_RGBA, GL_UNSIGNED_BYTE ); @@ -520,8 +518,8 @@ osg::Node* createIsland(const osg::Vec3& center = osg::Vec3( 0,0,0 ), float radi float f1 = 1.f - f0; - - *(osg::Vec4ub*)colorMap->data(c,r) = + + *(osg::Vec4ub*)colorMap->data(c,r) = colorElevationMap[i].color * f1 + colorElevationMap[i+1].color * f0; } } @@ -566,7 +564,7 @@ osg::Node* createIsland(const osg::Vec3& center = osg::Vec3( 0,0,0 ), float radi stateset->setAttributeAndModes( new osg::CullFace(), osg::StateAttribute::ON ); group->addChild(terrainTile.get()); - + group->addChild( createObjects( grid, 1 ) ); return group.release(); @@ -574,7 +572,7 @@ osg::Node* createIsland(const osg::Vec3& center = osg::Vec3( 0,0,0 ), float radi //////////////////////////////////////////////////////////////////////////////// namespace ModelFour { - + osg::Node* createModel(osg::ArgumentParser& /*arguments*/) { return createIsland(); diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index f76f2ff55..52d2fda8a 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -194,12 +194,10 @@ namespace ModelOne geometry->setVertexArray(vertices); osg::Vec3Array* normals = new osg::Vec3Array; - geometry->setNormalArray(normals); - geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + geometry->setNormalArray(normals, osg::Array::BIND_PER_VERTEX); osg::Vec4Array* colours = new osg::Vec4Array; - geometry->setColorArray(colours); - geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + geometry->setColorArray(colours, osg::Array::BIND_OVERALL); colours->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); @@ -868,7 +866,7 @@ int main(int argc, char** argv) OSG_NOTICE<<"MaximumShadowMapDistance set to "<getMaximumShadowMapDistance()< msm = NULL; if (arguments.read("--no-shadows")) { diff --git a/examples/osgsharedarray/osgsharedarray.cpp b/examples/osgsharedarray/osgsharedarray.cpp index fc5b4558b..75cbc5b6c 100644 --- a/examples/osgsharedarray/osgsharedarray.cpp +++ b/examples/osgsharedarray/osgsharedarray.cpp @@ -21,16 +21,16 @@ #include #include -/** This class is an example of how to create your own subclass of osg::Array. This - * is useful if your application has data in its own form of storage and you don't +/** This class is an example of how to create your own subclass of osg::Array. This + * is useful if your application has data in its own form of storage and you don't * want to make another copy into one of the predefined osg::Array classes. * - * @note This is not really intended to be a useful subclass of osg::Array. It - * doesn't do anything smart about memory management. It is simply intended as - * an example you can follow to create your own subclasses of osg::Array for - * your application's storage requirements. + * @note This is not really intended to be a useful subclass of osg::Array. It + * doesn't do anything smart about memory management. It is simply intended as + * an example you can follow to create your own subclasses of osg::Array for + * your application's storage requirements. */ -class MyArray : public osg::Array { +class MyArray : public osg::Array { public: /** Default ctor. Creates an empty array. */ MyArray() : @@ -39,10 +39,10 @@ public: _ptr(NULL) { } - /** "Normal" ctor. + /** "Normal" ctor. * * @param no The number of elements in the array. - * @param ptr Pointer to the data. This class just keeps that + * @param ptr Pointer to the data. This class just keeps that * pointer. It doesn't manage the memory. */ MyArray(unsigned int no, osg::Vec3* ptr) : @@ -59,15 +59,15 @@ public: } /** What type of object would clone return? */ - virtual Object* cloneType() const { - return new MyArray(); + virtual Object* cloneType() const { + return new MyArray(); } - - /** Create a copy of the object. */ - virtual osg::Object* clone(const osg::CopyOp& copyop) const { - return new MyArray(*this,copyop); - } - + + /** Create a copy of the object. */ + virtual osg::Object* clone(const osg::CopyOp& copyop) const { + return new MyArray(*this,copyop); + } + /** Accept method for ArrayVisitors. * * @note This will end up in ArrayVisitor::apply(osg::Array&). @@ -94,9 +94,9 @@ public: cvv.apply(_ptr[index]); } - /** Compare method. + /** Compare method. * Return -1 if lhs element is less than rhs element, 0 if equal, - * 1 if lhs element is greater than rhs element. + * 1 if lhs element is greater than rhs element. */ virtual int compare(unsigned int lhs,unsigned int rhs) const { const osg::Vec3& elem_lhs = _ptr[lhs]; @@ -118,7 +118,7 @@ public: return _numElements; } - /** Returns the number of bytes of storage required to hold + /** Returns the number of bytes of storage required to hold * all of the elements of the array. */ virtual unsigned int getTotalDataSize() const { @@ -133,7 +133,7 @@ private: osg::Vec3* _ptr; }; -/** The data values for the example. Simply defines a cube with +/** The data values for the example. Simply defines a cube with * per-face colors and normals. */ @@ -231,28 +231,28 @@ const osg::Vec4 myColors[] = { osg::Vec4( 1., 0., 0., 1.), osg::Vec4( 0., 1., 1., 1.) }; -/** Create a Geode that describes a cube using our own - * subclass of osg::Array for the vertices. It uses - * the "regular" array classes for all of the other +/** Create a Geode that describes a cube using our own + * subclass of osg::Array for the vertices. It uses + * the "regular" array classes for all of the other * arrays. * - * Creating your own Array class isn't really very - * useful for a tiny amount of data like this. You - * could just go ahead and copy the data into one of - * the "regular" Array classes like this does for - * normals and colors. The point of creating your - * own subclass of Array is for use with datasets - * that are much larger than anything you could - * create a simple example from. In that case, you - * might not want to create a copy of the data in - * one of the Array classes that comes with OSG, but - * instead reuse the copy your application already + * Creating your own Array class isn't really very + * useful for a tiny amount of data like this. You + * could just go ahead and copy the data into one of + * the "regular" Array classes like this does for + * normals and colors. The point of creating your + * own subclass of Array is for use with datasets + * that are much larger than anything you could + * create a simple example from. In that case, you + * might not want to create a copy of the data in + * one of the Array classes that comes with OSG, but + * instead reuse the copy your application already * has and wrap it up in a subclass of osg::Array - * that presents the right interface for use with + * that presents the right interface for use with * OpenSceneGraph. * - * Note that I'm only using the shared array for the - * vertices. You could do something similar for any + * Note that I'm only using the shared array for the + * vertices. You could do something similar for any * of the Geometry node's data arrays. */ osg::Geode* createGeometry() @@ -268,21 +268,19 @@ osg::Geode* createGeometry() // add normals unsigned int numNormals = sizeof(myNormals)/sizeof(myNormals[0]); - geom->setNormalArray(new osg::Vec3Array(numNormals,const_cast(&myNormals[0]))); - geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + geom->setNormalArray(new osg::Vec3Array(numNormals,const_cast(&myNormals[0])), osg::Array::BIND_PER_VERTEX); // add colors unsigned int numColors = sizeof(myColors)/sizeof(myColors[0]); osg::Vec4Array* normal_array = new osg::Vec4Array(numColors,const_cast(&myColors[0])); - geom->setColorArray(normal_array); - geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); + geom->setColorArray(normal_array, osg::Array::BIND_PER_VERTEX); // add PrimitiveSet geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, numVertices)); - // Changing these flags will tickle different cases in - // Geometry::drawImplementation. They should all work fine - // with the shared array. + // Changing these flags will tickle different cases in + // Geometry::drawImplementation. They should all work fine + // with the shared array. geom->setUseVertexBufferObjects(false); geom->setUseDisplayList(false); diff --git a/examples/osgspacewarp/osgspacewarp.cpp b/examples/osgspacewarp/osgspacewarp.cpp index fa5b1a651..df885f81c 100644 --- a/examples/osgspacewarp/osgspacewarp.cpp +++ b/examples/osgspacewarp/osgspacewarp.cpp @@ -35,13 +35,13 @@ struct DrawCallback : public osg::Drawable::DrawCallback virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const { osg::State& state = *renderInfo.getState(); - + if (!_firstTime) { _previousModelViewMatrix = _currentModelViewMatrix; _currentModelViewMatrix = state.getModelViewMatrix(); _inverseModelViewMatrix.invert(_currentModelViewMatrix); - + osg::Matrix T(_previousModelViewMatrix*_inverseModelViewMatrix); osg::Geometry* geometry = dynamic_cast(const_cast(drawable)); @@ -55,12 +55,12 @@ struct DrawCallback : public osg::Drawable::DrawCallback { _currentModelViewMatrix = state.getModelViewMatrix(); } - + _firstTime = false; drawable->drawImplementation(renderInfo); } - + mutable bool _firstTime; mutable osg::Matrix _currentModelViewMatrix; mutable osg::Matrix _inverseModelViewMatrix; @@ -72,13 +72,13 @@ struct DrawCallback : public osg::Drawable::DrawCallback osg::Node* createScene(unsigned int noStars) { - + osg::Geometry* geometry = new osg::Geometry; - + // set up vertices osg::Vec3Array* vertices = new osg::Vec3Array(noStars*2); geometry->setVertexArray(vertices); - + float min = -1.0f; float max = 1.0f; unsigned int j = 0; @@ -87,12 +87,11 @@ osg::Node* createScene(unsigned int noStars) { (*vertices)[j].set(random(min,max),random(min,max),random(min,max)); (*vertices)[j+1] = (*vertices)[j]+osg::Vec3(0.0f,0.0f,0.001f); - } + } // set up colours osg::Vec4Array* colours = new osg::Vec4Array(1); - geometry->setColorArray(colours); - geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + geometry->setColorArray(colours, osg::Array::BIND_OVERALL); (*colours)[0].set(1.0f,1.0f,1.0f,1.0f); // set up the primitive set to draw lines @@ -108,14 +107,14 @@ osg::Node* createScene(unsigned int noStars) geometry->setUseDisplayList(false); geometry->setDrawCallback(new DrawCallback); - + osg::Geode* geode = new osg::Geode; geode->addDrawable(geometry); geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); osg::Group* group = new osg::Group; - group->addChild(geode); - + group->addChild(geode); + return group; } diff --git a/examples/osgspheresegment/osgspheresegment.cpp b/examples/osgspheresegment/osgspheresegment.cpp index c62fc148e..2d658ba53 100644 --- a/examples/osgspheresegment/osgspheresegment.cpp +++ b/examples/osgspheresegment/osgspheresegment.cpp @@ -49,29 +49,29 @@ osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime) { - // set up the animation path + // set up the animation path osg::AnimationPath* animationPath = new osg::AnimationPath; animationPath->setLoopMode(osg::AnimationPath::LOOP); - + int numSamples = 40; float yaw = 0.0f; float yaw_delta = 2.0f*osg::PI/((float)numSamples-1.0f); float roll = osg::inDegrees(30.0f); - + double time=0.0f; double time_delta = looptime/(double)numSamples; for(int i=0;iinsert(time,osg::AnimationPath::ControlPoint(position,rotation)); yaw += yaw_delta; time += time_delta; } - return animationPath; + return animationPath; } @@ -85,7 +85,7 @@ class IntersectionUpdateCallback : public osg::NodeCallback osg::notify(osg::NOTICE)<<"IntersectionUpdateCallback not set up correctly."< 200) @@ -101,13 +101,13 @@ class IntersectionUpdateCallback : public osg::NodeCallback osg::notify(osg::NOTICE)<<"IntersectionUpdateCallback: warning cannot interestect with multiple terrain instances, just uses first one."<getNodePath()); - + // now we can compute the terrain to ss transform osg::Matrixd possie = terrainLocalToWorld*ssWorldToLocal; - + osgSim::SphereSegment::LineList lines = ss_->computeIntersection(possie, terrain_.get()); if (!lines.empty()) { @@ -118,7 +118,7 @@ class IntersectionUpdateCallback : public osg::NodeCallback osg::MatrixTransform* mt = new osg::MatrixTransform; mt->setMatrix(osg::computeLocalToWorld(nv->getNodePath())); intersectionGroup_->addChild(mt); - + // std::cout<<"matrix = "<getMatrix()<setArea(osg::Vec3(cos(i/(2*osg::PI)),sin(i/(2*osg::PI)),0), osg::PI_2, osg::PI_2); - + i += 0.1f; } @@ -194,16 +194,16 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode * positioned->setMatrix(osg::Matrix::translate(-bs.center())* osg::Matrix::scale(size,size,size)* osg::Matrix::rotate(osg::inDegrees(-90.0f),0.0f,0.0f,1.0f)); - + positioned->addChild(glider); - - osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform; + + osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform; xform->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON); xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0,1.0)); xform->addChild(positioned); model->addChild(xform); } - + if (createMovingRadar) { // The IntersectionUpdateCallback has to have a safe place to put all its generated geometry into, @@ -211,10 +211,10 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode * // traversal iterators. osg::Group* intersectionGroup = new osg::Group; root->addChild(intersectionGroup); - - osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform; + + osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform; xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0,1.0)); - + osgSim::SphereSegment * ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0), 700.0f, // radius osg::DegreesToRadians(135.0f), @@ -222,7 +222,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode * osg::DegreesToRadians(-60.0f), osg::DegreesToRadians(-40.0f), 60); - + IntersectionUpdateCallback * iuc = new IntersectionUpdateCallback; iuc->frameCount_ = 0; iuc->root_ = root; @@ -235,7 +235,7 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode * xform->addChild(ss); model->addChild(xform); } - + osg::Node* cessna = osgDB::readNodeFile("cessna.osgt"); if (cessna) { @@ -250,10 +250,10 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode * text->setAxisAlignment(osgText::Text::SCREEN); text->setCharacterSize(40.0f); text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS); - + osg::Geode* geode = new osg::Geode; geode->addDrawable(text); - + osg::LOD* lod = new osg::LOD; lod->setRangeMode(osg::LOD::PIXEL_SIZE_ON_SCREEN); lod->setRadius(cessna->getBound().radius()); @@ -267,28 +267,28 @@ osg::Node* createMovingModel(const osg::Vec3& center, float radius, osg::Geode * positioned->setMatrix(osg::Matrix::translate(-bs.center())* osg::Matrix::scale(size,size,size)* osg::Matrix::rotate(osg::inDegrees(180.0f),0.0f,0.0f,1.0f)); - + //positioned->addChild(cessna); positioned->addChild(lod); - + osg::MatrixTransform* xform = new osg::MatrixTransform; xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0f,2.0)); xform->addChild(positioned); - + model->addChild(xform); } - + return model; } osg::Group* createOverlay(const osg::Vec3& center, float radius) { osg::Group* group = new osg::Group; - + // create a grid of lines. { osg::Geometry* geom = new osg::Geometry; - + unsigned int num_rows = 10; osg::Vec3 left = center+osg::Vec3(-radius,-radius,0.0f); @@ -312,23 +312,22 @@ osg::Group* createOverlay(const osg::Vec3& center, float radius) top += delta_column; bottom += delta_column; } - + geom->setVertexArray(vertices); osg::Vec4ubArray& color = *(new osg::Vec4ubArray(1)); color[0].set(0,0,0,255); - geom->setColorArray(&color); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(&color, osg::Array::BIND_OVERALL); - geom->addPrimitiveSet(new osg::DrawArrays(GL_LINES,0,vertices->getNumElements())); + geom->addPrimitiveSet(new osg::DrawArrays(GL_LINES,0,vertices->getNumElements())); geom->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); osg::Geode* geode = new osg::Geode; geode->addDrawable(geom); - group->addChild(geode); + group->addChild(geode); } - + return group; } @@ -337,8 +336,8 @@ osg::Vec3 computeTerrainIntersection(osg::Node* subgraph,float x,float y) const osg::BoundingSphere& bs = subgraph->getBound(); float zMax = bs.center().z()+bs.radius(); float zMin = bs.center().z()-bs.radius(); - - osg::ref_ptr intersector = + + osg::ref_ptr intersector = new osgUtil::LineSegmentIntersector(osg::Vec3(x,y,zMin),osg::Vec3(x,y,zMax)); osgUtil::IntersectionVisitor iv(intersector.get()); @@ -377,12 +376,12 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi terrainGeode->setStateSet( stateset ); - + { unsigned int numColumns = 38; unsigned int numRows = 39; unsigned int r, c; - + osg::Vec3 origin(0.0f,0.0f,0.0f); osg::Vec3 size(1000.0f,1000.0f,250.0f); @@ -435,8 +434,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi geometry->setVertexArray(&v); geometry->setTexCoordArray(0, &tc); - geometry->setColorArray(&color); - geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + geometry->setColorArray(&color, osg::Array::BIND_OVERALL); for(r=0;raddDrawable(geometry); } - - } + + } // create sphere segment @@ -467,7 +465,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi switch(testCase) { - case(0): + case(0): ss = new osgSim::SphereSegment( computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center 510.0f, // radius @@ -478,7 +476,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi 60); root->addChild(ss.get()); break; - case(1): + case(1): ss = new osgSim::SphereSegment( computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center 510.0f, // radius @@ -489,7 +487,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi 60); root->addChild(ss.get()); break; - case(2): + case(2): ss = new osgSim::SphereSegment( computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center 510.0f, // radius @@ -500,7 +498,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi 60); root->addChild(ss.get()); break; - case(3): + case(3): ss = new osgSim::SphereSegment( computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center 510.0f, // radius @@ -511,7 +509,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi 60); root->addChild(ss.get()); break; - case(4): + case(4): { ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0), 700.0f, // radius @@ -520,21 +518,21 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi osg::DegreesToRadians(-60.0f), osg::DegreesToRadians(-40.0f), 60); - - osg::ref_ptr mt = new osg::MatrixTransform; - + + osg::ref_ptr mt = new osg::MatrixTransform; + mt->setMatrix(osg::Matrix(-0.851781, 0.156428, -0.5, 0, -0.180627, -0.983552, -6.93889e-18, 0, -0.491776, 0.0903136, 0.866025, 0, 598.217, 481.957, 100, 1)); mt->addChild(ss.get()); - + terrainToSS.invert(mt->getMatrix()); - + root->addChild(mt.get()); break; } - case(5): + case(5): { ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0), 700.0f, // radius @@ -543,21 +541,21 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi osg::DegreesToRadians(-60.0f), osg::DegreesToRadians(-40.0f), 60); - - osg::ref_ptr mt = new osg::MatrixTransform; - + + osg::ref_ptr mt = new osg::MatrixTransform; + mt->setMatrix(osg::Matrix(-0.851781, 0.156428, -0.5, 0, -0.180627, -0.983552, -6.93889e-18, 0, -0.491776, 0.0903136, 0.866025, 0, 598.217, 481.957, 100, 1)); mt->addChild(ss.get()); - + terrainToSS.invert(mt->getMatrix()); - + root->addChild(mt.get()); break; } - case(6): + case(6): { ss = new osgSim::SphereSegment(osg::Vec3d(0.0,0.0,0.0), 700.0f, // radius @@ -566,21 +564,21 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi osg::DegreesToRadians(-60.0f), osg::DegreesToRadians(-40.0f), 60); - - osg::ref_ptr mt = new osg::MatrixTransform; - + + osg::ref_ptr mt = new osg::MatrixTransform; + mt->setMatrix(osg::Matrix(-0.851781, 0.156428, -0.5, 0, -0.180627, -0.983552, -6.93889e-18, 0, -0.491776, 0.0903136, 0.866025, 0, 598.217, 481.957, 100, 1)); mt->addChild(ss.get()); - + terrainToSS.invert(mt->getMatrix()); - + root->addChild(mt.get()); break; } - case(7): + case(7): { ss = new osgSim::SphereSegment( computeTerrainIntersection(terrainGeode.get(),550.0f,780.0f), // center @@ -595,7 +593,7 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi break; } }; - + if (ss.valid()) { ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,0.5f)); @@ -605,10 +603,10 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi { ss->getParent(0)->addChild(ss->computeIntersectionSubgraph(terrainToSS, terrainGeode.get())); } - + } } - + if (useOverlay) { @@ -629,9 +627,9 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi { root->addChild(terrainGeode.get()); } - + // create particle effects - { + { osg::Vec3 position = computeTerrainIntersection(terrainGeode.get(),100.0f,100.0f); osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect(position, 10.0f); @@ -642,9 +640,9 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi root->addChild(smoke); root->addChild(fire); } - + // create particle effects - { + { osg::Vec3 position = computeTerrainIntersection(terrainGeode.get(),200.0f,100.0f); osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect(position, 1.0f); @@ -655,10 +653,10 @@ void build_world(osg::Group *root, unsigned int testCase, bool useOverlay, osgSi root->addChild(smoke); root->addChild(fire); } - - + + bool createMovingRadar = true; - + // create the moving models. { root->addChild(createMovingModel(osg::Vec3(500.0f,500.0f,500.0f),100.0f, terrainGeode.get(), root, createMovingRadar)); @@ -675,12 +673,12 @@ int main(int argc, char **argv) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); - + // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of particle systems."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye"); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); - + // construct the viewer. osgViewer::Viewer viewer(arguments); @@ -694,7 +692,7 @@ int main(int argc, char **argv) while (arguments.read("--object")) { useOverlay = true; technique = osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; } while (arguments.read("--ortho") || arguments.read("--orthographic")) { useOverlay = true; technique = osgSim::OverlayNode::VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; } while (arguments.read("--persp") || arguments.read("--perspective")) { useOverlay = true; technique = osgSim::OverlayNode::VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY; } - + // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) @@ -712,12 +710,12 @@ int main(int argc, char **argv) arguments.writeErrorMessages(std::cout); return 1; } - + osg::Group *root = new osg::Group; build_world(root, testCase, useOverlay, technique); - + // add a viewport to the viewer and attach the scene graph. viewer.setSceneData(root); - + return viewer.run(); } diff --git a/examples/osgstereoimage/osgstereoimage.cpp b/examples/osgstereoimage/osgstereoimage.cpp index e6f145093..55ae2a673 100644 --- a/examples/osgstereoimage/osgstereoimage.cpp +++ b/examples/osgstereoimage/osgstereoimage.cpp @@ -40,10 +40,10 @@ typedef std::vector FileList; osg::StateSet* createColorToGreyscaleStateSet() { osg::StateSet* stateset = new osg::StateSet; - + osg::Program* program = new osg::Program; stateset->setAttribute(program); - + const char* fragSource = { "uniform sampler2D baseTexture;\n" @@ -55,7 +55,7 @@ osg::StateSet* createColorToGreyscaleStateSet() "}\n" }; program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragSource)); - + stateset->addUniform(new osg::Uniform("baseTexture",0)); osg::Matrixf colorMatrix( @@ -63,8 +63,8 @@ osg::StateSet* createColorToGreyscaleStateSet() 0.59f, 0.59f, 0.59f, 0.0f, 0.11f, 0.11f, 0.11f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f - ); - + ); + stateset->addUniform(new osg::Uniform("colorMatrix",colorMatrix)); return stateset; @@ -78,9 +78,9 @@ osg::Geode* createSectorForImage(osg::Image* image, osg::TexMat* texmat, float s int numSegments = 20; float Theta = length/radius; float dTheta = Theta/(float)(numSegments-1); - + float ThetaZero = height*s/(t*radius); - + // set up the texture. osg::Texture2D* texture = new osg::Texture2D; texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); @@ -103,7 +103,7 @@ osg::Geode* createSectorForImage(osg::Image* image, osg::TexMat* texmat, float s osg::Vec3Array* coords = new osg::Vec3Array(); osg::Vec2Array* tcoords = new osg::Vec2Array(); - + int i; float angle = -Theta/2.0f; for(i=0; @@ -112,7 +112,7 @@ osg::Geode* createSectorForImage(osg::Image* image, osg::TexMat* texmat, float s { coords->push_back(osg::Vec3(sinf(angle)*radius,cosf(angle)*radius,height*0.5f)); // top coords->push_back(osg::Vec3(sinf(angle)*radius,cosf(angle)*radius,-height*0.5f)); // bottom. - + tcoords->push_back(osg::Vec2(angle/ThetaZero+0.5f, flip ? 0.0f : 1.0f)); // top tcoords->push_back(osg::Vec2(angle/ThetaZero+0.5f, flip ? 1.0f : 0.0f)); // bottom. @@ -123,12 +123,11 @@ osg::Geode* createSectorForImage(osg::Image* image, osg::TexMat* texmat, float s osg::DrawArrays* elements = new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,coords->size()); - + geom->setVertexArray(coords); geom->setTexCoordArray(0,tcoords); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(elements); @@ -174,7 +173,7 @@ osg::Group * loadImages(std::string image1, std::string image2, osg::TexMat* tex } } -// create a switch containing a set of child each containing a +// create a switch containing a set of child each containing a // stereo image pair. osg::Switch* createScene(FileList fileList, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float radius, float height, float length) { @@ -202,7 +201,7 @@ class SlideEventHandler : public osgGA::GUIEventHandler public: SlideEventHandler(); - + META_Object(osgStereImageApp,SlideEventHandler); @@ -212,17 +211,17 @@ public: virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); - + virtual void getUsage(osg::ApplicationUsage& usage) const; virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); - + void nextSlide(); - + void previousSlide(); - + void scaleImage(float s); - + void offsetImage(float ds,float dt); void rotateImage(float rx,float ry); @@ -250,7 +249,7 @@ protected: float _initSeperationY; float _currentSeperationY; FileList _fileList; - + }; SlideEventHandler::SlideEventHandler(): @@ -274,8 +273,8 @@ void SlideEventHandler::set(osg::Switch* sw, float offsetX, float offsetY, osg:: _texmatRight = texmatRight; _timePerSlide = timePerSlide; - _autoSteppingActive = autoSteppingActive; - + _autoSteppingActive = autoSteppingActive; + _initSeperationX = offsetX; _currentSeperationX = _initSeperationX; @@ -303,8 +302,8 @@ void SlideEventHandler::set(FileList fileList, osg::Switch* sw, float offsetX, f _length=length; _timePerSlide = timePerSlide; - _autoSteppingActive = autoSteppingActive; - + _autoSteppingActive = autoSteppingActive; + _initSeperationX = offsetX; _currentSeperationX = _initSeperationX; @@ -327,22 +326,22 @@ bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction _previousTime = ea.getTime(); return true; } - else if ((ea.getKey()=='n') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_Right)) + else if ((ea.getKey()=='n') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_Right)) { nextSlide(); return true; } - else if ((ea.getKey()=='p') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_Left)) + else if ((ea.getKey()=='p') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_Left)) { previousSlide(); return true; } - else if ((ea.getKey()=='w') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Add)) + else if ((ea.getKey()=='w') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Add)) { scaleImage(0.99f); return true; } - else if ((ea.getKey()=='s') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Subtract)) + else if ((ea.getKey()=='s') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Subtract)) { scaleImage(1.01f); return true; @@ -379,15 +378,15 @@ bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction { static float px = ea.getXnormalized(); static float py = ea.getYnormalized(); - + float dx = ea.getXnormalized()-px; float dy = ea.getYnormalized()-py; - + px = ea.getXnormalized(); py = ea.getYnormalized(); - + rotateImage(dx,dy); - + return true; } @@ -415,7 +414,7 @@ void SlideEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) if (_autoSteppingActive && nv->getFrameStamp()) { double time = nv->getFrameStamp()->getSimulationTime(); - + if (_firstTraversal) { _firstTraversal = false; @@ -424,10 +423,10 @@ void SlideEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) else if (time-_previousTime>_timePerSlide) { _previousTime = time; - + nextSlide(); } - + } traverse(node,nv); @@ -461,7 +460,7 @@ void SlideEventHandler::previousSlide() else --_activeSlide; osg::ref_ptr images = loadImages(_fileList[2*_activeSlide],_fileList[2*_activeSlide+1],_texmatLeft.get(),_texmatRight.get(),_radius,_height,_length); if (images.valid()) _switch->replaceChild(_switch->getChild(0),images.get()); - } else { + } else { if (_activeSlide==0) _activeSlide = _switch->getNumChildren()-1; else --_activeSlide; @@ -503,7 +502,7 @@ int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); - + // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use node masks to create stereo images."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye"); @@ -518,7 +517,7 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->addCommandLineOption("--CullDrawThreadPerContext","Select CullDrawThreadPerContext threading model for viewer."); arguments.getApplicationUsage()->addCommandLineOption("--DrawThreadPerContext","Select DrawThreadPerContext threading model for viewer."); arguments.getApplicationUsage()->addCommandLineOption("--CullThreadPerCameraDrawThreadPerContext","Select CullThreadPerCameraDrawThreadPerContext threading model for viewer."); - + // construct the viewer. osgViewer::Viewer viewer(arguments); @@ -553,7 +552,7 @@ int main( int argc, char **argv ) while (std::getline(is,line,'\n')) fileList.push_back(line); is.close(); } - + } // if user request help write it out to cout. @@ -580,7 +579,7 @@ int main( int argc, char **argv ) arguments.writeErrorMessages(std::cout); return 1; } - + // extract the filenames from the arguments list. for(int pos=1;possetStateSet(createColorToGreyscaleStateSet()); } - - + + // set the scene to render viewer.setSceneData(rootNode.get()); @@ -656,19 +655,19 @@ int main( int argc, char **argv ) // set up the SlideEventHandler. if (onDisk) seh->set(fileList,rootNode.get(),offsetX,offsetY,texmatLeft,texmatRight,radius,height,length,timeDelayBetweenSlides,autoSteppingActive); else seh->set(rootNode.get(),offsetX,offsetY,texmatLeft,texmatRight,timeDelayBetweenSlides,autoSteppingActive); - + osg::Matrix homePosition; homePosition.makeLookAt(osg::Vec3(0.0f,0.0f,0.0f),osg::Vec3(0.0f,1.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f)); - + while( !viewer.done() ) { viewer.getCamera()->setViewMatrix(homePosition); // fire off the cull and draw traversals of the scene. viewer.frame(); - + } - + return 0; } diff --git a/examples/osgstereomatch/StereoMultipass.cpp b/examples/osgstereomatch/StereoMultipass.cpp index 6aad751f3..90a71ba24 100644 --- a/examples/osgstereomatch/StereoMultipass.cpp +++ b/examples/osgstereomatch/StereoMultipass.cpp @@ -22,7 +22,7 @@ #include #include -SubtractPass::SubtractPass(osg::TextureRectangle *left_tex, +SubtractPass::SubtractPass(osg::TextureRectangle *left_tex, osg::TextureRectangle *right_tex, int width, int height, int start_disparity) : @@ -33,7 +33,7 @@ SubtractPass::SubtractPass(osg::TextureRectangle *left_tex, _RootGroup = new osg::Group; _InTextureLeft = left_tex; _InTextureRight = right_tex; - + createOutputTextures(); _Camera = new osg::Camera; @@ -52,7 +52,7 @@ SubtractPass::~SubtractPass() osg::ref_ptr SubtractPass::createTexturedQuad() { osg::ref_ptr top_group = new osg::Group; - + osg::ref_ptr quad_geode = new osg::Geode; osg::ref_ptr quad_coords = new osg::Vec3Array; // vertex coords @@ -77,8 +77,7 @@ osg::ref_ptr SubtractPass::createTexturedQuad() quad_geom->setVertexArray(quad_coords.get()); quad_geom->setTexCoordArray(0, quad_tcoords.get()); quad_geom->addPrimitiveSet(quad_da.get()); - quad_geom->setColorArray(quad_colors.get()); - quad_geom->setColorBinding(osg::Geometry::BIND_OVERALL); + quad_geom->setColorArray(quad_colors.get(), osg::Array::BIND_OVERALL); _StateSet = quad_geom->getOrCreateStateSet(); _StateSet->setMode(GL_LIGHTING,osg::StateAttribute::OFF); @@ -88,9 +87,9 @@ osg::ref_ptr SubtractPass::createTexturedQuad() _StateSet->addUniform(new osg::Uniform("textureLeft", 0)); _StateSet->addUniform(new osg::Uniform("textureRight", 1)); _StateSet->addUniform(new osg::Uniform("start_disparity", _StartDisparity)); - + quad_geode->addDrawable(quad_geom.get()); - + top_group->addChild(quad_geode.get()); return top_group; @@ -112,7 +111,7 @@ void SubtractPass::setupCamera() _Camera->setRenderOrder(osg::Camera::PRE_RENDER); _Camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - + // attach the 4 textures for (int i=0; i<4; i++) { _Camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0+i), _OutTexture[i].get()); @@ -123,7 +122,7 @@ void SubtractPass::createOutputTextures() { for (int i=0; i<4; i++) { _OutTexture[i] = new osg::TextureRectangle; - + _OutTexture[i]->setTextureSize(_TextureWidth, _TextureHeight); _OutTexture[i]->setInternalFormat(GL_RGBA); _OutTexture[i]->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); @@ -133,7 +132,7 @@ void SubtractPass::createOutputTextures() void SubtractPass::setShader(std::string filename) { - osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT ); + osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT ); fshader->loadShaderSourceFromFile(osgDB::findDataFile(filename)); _FragmentProgram = 0; @@ -160,7 +159,7 @@ AggregatePass::AggregatePass(osg::TextureRectangle *diff_tex0, _WindowSize(window_size) { _RootGroup = new osg::Group; - + _InTextureDifference[0] = diff_tex0; _InTextureDifference[1] = diff_tex1; _InTextureDifference[2] = diff_tex2; @@ -170,7 +169,7 @@ AggregatePass::AggregatePass(osg::TextureRectangle *diff_tex0, _OutTextureAggregate = agg_tex_out; _OutTexture = _OutTextureAggregate; - + _Camera = new osg::Camera; setupCamera(); _Camera->addChild(createTexturedQuad().get()); @@ -188,7 +187,7 @@ AggregatePass::~AggregatePass() osg::ref_ptr AggregatePass::createTexturedQuad() { osg::ref_ptr top_group = new osg::Group; - + osg::ref_ptr quad_geode = new osg::Geode; osg::ref_ptr quad_coords = new osg::Vec3Array; // vertex coords @@ -213,8 +212,7 @@ osg::ref_ptr AggregatePass::createTexturedQuad() quad_geom->setVertexArray(quad_coords.get()); quad_geom->setTexCoordArray(0, quad_tcoords.get()); quad_geom->addPrimitiveSet(quad_da.get()); - quad_geom->setColorArray(quad_colors.get()); - quad_geom->setColorBinding(osg::Geometry::BIND_OVERALL); + quad_geom->setColorArray(quad_colors.get(), osg::Array::BIND_OVERALL); _StateSet = quad_geom->getOrCreateStateSet(); _StateSet->setMode(GL_LIGHTING,osg::StateAttribute::OFF); @@ -223,7 +221,7 @@ osg::ref_ptr AggregatePass::createTexturedQuad() _StateSet->setTextureAttributeAndModes(2, _InTextureDifference[2].get(), osg::StateAttribute::ON); _StateSet->setTextureAttributeAndModes(3, _InTextureDifference[3].get(), osg::StateAttribute::ON); _StateSet->setTextureAttributeAndModes(4, _InTextureAggregate.get(), osg::StateAttribute::ON); - + _StateSet->addUniform(new osg::Uniform("textureDiff0", 0)); _StateSet->addUniform(new osg::Uniform("textureDiff1", 1)); _StateSet->addUniform(new osg::Uniform("textureDiff2", 2)); @@ -233,7 +231,7 @@ osg::ref_ptr AggregatePass::createTexturedQuad() _StateSet->addUniform(new osg::Uniform("window_size", _WindowSize)); quad_geode->addDrawable(quad_geom.get()); - + top_group->addChild(quad_geode.get()); return top_group; @@ -261,7 +259,7 @@ void AggregatePass::setupCamera() void AggregatePass::setShader(std::string filename) { - osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT ); + osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT ); fshader->loadShaderSourceFromFile(osgDB::findDataFile(filename)); _FragmentProgram = 0; @@ -274,7 +272,7 @@ void AggregatePass::setShader(std::string filename) // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -SelectPass::SelectPass(osg::TextureRectangle *in_tex, +SelectPass::SelectPass(osg::TextureRectangle *in_tex, int width, int height, int min_disparity, int max_disparity) : _TextureWidth(width), @@ -284,7 +282,7 @@ SelectPass::SelectPass(osg::TextureRectangle *in_tex, { _RootGroup = new osg::Group; _InTexture = in_tex; - + createOutputTextures(); _Camera = new osg::Camera; @@ -303,7 +301,7 @@ SelectPass::~SelectPass() osg::ref_ptr SelectPass::createTexturedQuad() { osg::ref_ptr top_group = new osg::Group; - + osg::ref_ptr quad_geode = new osg::Geode; osg::ref_ptr quad_coords = new osg::Vec3Array; // vertex coords @@ -328,19 +326,18 @@ osg::ref_ptr SelectPass::createTexturedQuad() quad_geom->setVertexArray(quad_coords.get()); quad_geom->setTexCoordArray(0, quad_tcoords.get()); quad_geom->addPrimitiveSet(quad_da.get()); - quad_geom->setColorArray(quad_colors.get()); - quad_geom->setColorBinding(osg::Geometry::BIND_OVERALL); + quad_geom->setColorArray(quad_colors.get(), osg::Array::BIND_OVERALL); _StateSet = quad_geom->getOrCreateStateSet(); _StateSet->setMode(GL_LIGHTING,osg::StateAttribute::OFF); _StateSet->setTextureAttributeAndModes(0, _InTexture.get(), osg::StateAttribute::ON); - + _StateSet->addUniform(new osg::Uniform("textureIn", 0)); _StateSet->addUniform(new osg::Uniform("min_disparity", _MinDisparity)); _StateSet->addUniform(new osg::Uniform("max_disparity", _MaxDisparity)); quad_geode->addDrawable(quad_geom.get()); - + top_group->addChild(quad_geode.get()); return top_group; @@ -369,7 +366,7 @@ void SelectPass::setupCamera() void SelectPass::createOutputTextures() { _OutTexture = new osg::TextureRectangle; - + _OutTexture->setTextureSize(_TextureWidth, _TextureHeight); _OutTexture->setInternalFormat(GL_RGBA); _OutTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); @@ -378,7 +375,7 @@ void SelectPass::createOutputTextures() void SelectPass::setShader(std::string filename) { - osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT ); + osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT ); fshader->loadShaderSourceFromFile(osgDB::findDataFile(filename)); _FragmentProgram = 0; @@ -391,9 +388,9 @@ void SelectPass::setShader(std::string filename) // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -StereoMultipass::StereoMultipass(osg::TextureRectangle *left_tex, +StereoMultipass::StereoMultipass(osg::TextureRectangle *left_tex, osg::TextureRectangle *right_tex, - int width, int height, + int width, int height, int min_disparity, int max_disparity, int window_size) : _TextureWidth(width), _TextureHeight(height) @@ -401,7 +398,7 @@ StereoMultipass::StereoMultipass(osg::TextureRectangle *left_tex, _RootGroup = new osg::Group; createOutputTextures(); - + _Camera = new osg::Camera; setupCamera(); _Camera->addChild(createTexturedQuad().get()); @@ -447,7 +444,7 @@ StereoMultipass::~StereoMultipass() osg::ref_ptr StereoMultipass::createTexturedQuad() { osg::ref_ptr top_group = new osg::Group; - + osg::ref_ptr quad_geode = new osg::Geode; osg::ref_ptr quad_coords = new osg::Vec3Array; // vertex coords @@ -472,14 +469,13 @@ osg::ref_ptr StereoMultipass::createTexturedQuad() quad_geom->setVertexArray(quad_coords.get()); quad_geom->setTexCoordArray(0, quad_tcoords.get()); quad_geom->addPrimitiveSet(quad_da.get()); - quad_geom->setColorArray(quad_colors.get()); - quad_geom->setColorBinding(osg::Geometry::BIND_OVERALL); - + quad_geom->setColorArray(quad_colors.get(), osg::Array::BIND_OVERALL); + _StateSet = quad_geom->getOrCreateStateSet(); _StateSet->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - + quad_geode->addDrawable(quad_geom.get()); - + top_group->addChild(quad_geode.get()); return top_group; @@ -511,12 +507,12 @@ void StereoMultipass::createOutputTextures() { for (int i=0; i<2; i++) { _OutTexture[i] = new osg::TextureRectangle; - + _OutTexture[i]->setTextureSize(_TextureWidth, _TextureHeight); _OutTexture[i]->setInternalFormat(GL_RGBA); _OutTexture[i]->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); _OutTexture[i]->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); - + // hdr, we want to store floats _OutTexture[i]->setInternalFormat(GL_RGBA16F_ARB); //_OutTexture[i]->setInternalFormat(GL_FLOAT_RGBA32_NV); @@ -528,7 +524,7 @@ void StereoMultipass::createOutputTextures() void StereoMultipass::setShader(std::string filename) { - osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT ); + osg::ref_ptr fshader = new osg::Shader( osg::Shader::FRAGMENT ); fshader->loadShaderSourceFromFile(osgDB::findDataFile(filename)); _FragmentProgram = 0; diff --git a/examples/osgstereomatch/osgstereomatch.cpp b/examples/osgstereomatch/osgstereomatch.cpp index 8d467f4c4..4f871b7d4 100644 --- a/examples/osgstereomatch/osgstereomatch.cpp +++ b/examples/osgstereomatch/osgstereomatch.cpp @@ -44,12 +44,12 @@ osg::Node* createScene(osg::Image *left, osg::Image *right, unsigned int min_dis osg::Group* topnode = new osg::Group; // create four quads so we can display up to four images - + osg::ref_ptr geode = new osg::Geode(); - + // each geom will contain a quad osg::ref_ptr da = new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4); - + osg::ref_ptr colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); @@ -58,21 +58,21 @@ osg::Node* createScene(osg::Image *left, osg::Image *right, unsigned int min_dis tcoords->push_back(osg::Vec2(width, 0)); tcoords->push_back(osg::Vec2(width, height)); tcoords->push_back(osg::Vec2(0, height)); - + osg::ref_ptr geomss[4]; // stateset where we can attach textures osg::ref_ptr texture[4]; for (int i=0;i<4;i++) { osg::ref_ptr vcoords = new osg::Vec3Array; // vertex coords osg::ref_ptr geom = new osg::Geometry; - + // tile the quads on the screen // 2 3 // 0 1 int xoff, zoff; xoff = (i%2); zoff = i>1 ? 1 : 0; - + // initial viewer camera looks along y vcoords->push_back(osg::Vec3d(0+(xoff * width), 0, 0+(zoff * height))); vcoords->push_back(osg::Vec3d(width+(xoff * width), 0, 0+(zoff * height))); @@ -82,8 +82,7 @@ osg::Node* createScene(osg::Image *left, osg::Image *right, unsigned int min_dis geom->setVertexArray(vcoords.get()); geom->setTexCoordArray(0,tcoords.get()); geom->addPrimitiveSet(da.get()); - geom->setColorArray(colors.get()); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors.get(), osg::Array::BIND_OVERALL); geomss[i] = geom->getOrCreateStateSet(); geomss[i]->setMode(GL_LIGHTING, osg::StateAttribute::OFF); @@ -102,15 +101,15 @@ osg::Node* createScene(osg::Image *left, osg::Image *right, unsigned int min_dis geomss[1]->setTextureAttributeAndModes(0, texture[1].get(), osg::StateAttribute::ON); topnode->addChild(geode.get()); - + // create the processing passes if (single_pass) { StereoPass *stereopass = new StereoPass(texture[0].get(), texture[1].get(), width, height, min_disp, max_disp, window_size); - + topnode->addChild(stereopass->getRoot().get()); - + // attach the output of the processing to the top left geom geomss[2]->setTextureAttributeAndModes(0, stereopass->getOutputTexture().get(), @@ -178,9 +177,9 @@ int main(int argc, char *argv[]) // load the images osg::ref_ptr leftIm = osgDB::readImageFile(leftName); osg::ref_ptr rightIm = osgDB::readImageFile(rightName); - + osg::Node* scene = createScene(leftIm.get(), rightIm.get(), minDisparity, maxDisparity, windowSize, useSinglePass); - + // construct the viewer. osgViewer::Viewer viewer; viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); diff --git a/examples/osgtessellate/osgtessellate.cpp b/examples/osgtessellate/osgtessellate.cpp index 1f68af62d..e0a137f10 100644 --- a/examples/osgtessellate/osgtessellate.cpp +++ b/examples/osgtessellate/osgtessellate.cpp @@ -23,7 +23,7 @@ * the Tessellator has new member fuinctions setTessellationType(osgUtil::Tessellator::TESS_TYPE_xxx); tscx->setBoundaryOnly(bool); - tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_xxx); + tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_xxx); * for winding rules: See the red book chap 13. */ @@ -40,8 +40,8 @@ class tessellateDemoGeometry : public osg::Geometry, public osgUtil::Tessellator { // We add the Tessellator to the geometry because we want to access the - // tessellatable contours again; you can apply a Tessellator to a Geometry - // to produce exactly a required tessellation once only, and then + // tessellatable contours again; you can apply a Tessellator to a Geometry + // to produce exactly a required tessellation once only, and then // the contours could be discarded since the geometry does not need to be retessellated. public: tessellateDemoGeometry() {}; @@ -50,7 +50,7 @@ protected: virtual ~tessellateDemoGeometry() {}; }; -osg::Geometry *makePolsTwo (void) +osg::Geometry *makePolsTwo (void) { // an example of using current geometry contours to create next tessellation // this polygon disappears once the contour rules make no polygons. @@ -62,12 +62,12 @@ osg::Geometry *makePolsTwo (void) osg::Vec3 nrm(0,-1,0); static GLdouble quadstrip[8][3] = { { 1900.0, 1130.0, 0.0 }, - { 2100.0, 1130.0, 0.0 }, + { 2100.0, 1130.0, 0.0 }, { 1900.0, 1350.0, 0.0 }, - { 1950.0, 1350.0, 0.0 }, - { 1900.0, 1550.0, 0.0 }, - { 2000.0, 1550.0, 0.0 }, - { 1900.0, 1750.0, 0.0 }, + { 1950.0, 1350.0, 0.0 }, + { 1900.0, 1550.0, 0.0 }, + { 2000.0, 1550.0, 0.0 }, + { 1900.0, 1750.0, 0.0 }, { 2400.0, 1750.0, 0.0 } }; static GLdouble innerquadstrip[8][3] = { { 2000.0, 1230.0, 0.0 }, @@ -75,11 +75,11 @@ osg::Geometry *makePolsTwo (void) { 1920.0, 1350.0, 0.0 }, { 1940.0, 1350.0, 0.0 }, { 1920.0, 1550.0, 0.0 }, - { 1980.0, 1550.0, 0.0 }, + { 1980.0, 1550.0, 0.0 }, { 2000.0, 1650.0, 0.0 }, { 2400.0, 1650.0, 0.0 } }; - - // add one large quadstrip + + // add one large quadstrip for (i = 0; i < 8; i++) { coords->push_back(osg::Vec3(quadstrip[i][0],quadstrip[i][2],quadstrip[i][1])); @@ -92,13 +92,12 @@ osg::Geometry *makePolsTwo (void) nrms->push_back(nrm); } gtess->setVertexArray(coords); - gtess->setNormalArray(nrms); - gtess->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + gtess->setNormalArray(nrms, osg::Array::BIND_PER_VERTEX); gtess->setTexCoordArray(0,tcs); - + // demonstrate that the Tessellator makes textured tessellations osg::StateSet* stateset = new osg::StateSet(); - + osg::Image* image = osgDB::readImageFile("Cubemap_snow/posy.jpg"); if (image) { @@ -109,7 +108,7 @@ osg::Geometry *makePolsTwo (void) stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); } gtess->setStateSet( stateset ); - + int nstart=0; // The derived class tessellateDemoGeometry retains the original contours for re-use. gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,nstart,8));nstart+=8; @@ -118,7 +117,7 @@ osg::Geometry *makePolsTwo (void) gtess->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); gtess->setBoundaryOnly(true); gtess->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tessellation - ODD. - + return gtess; } @@ -134,13 +133,12 @@ osg::Geometry *makeSideWall (const float xpos) // front wall static GLdouble wall[4][2] = { { 1130.0, 0.0 }, - { 1130.0, 300.0 } , + { 1130.0, 300.0 } , { 1340.0,300.0 }, { 1340.0,0.0 } }; gtess->setVertexArray(coords); - gtess->setNormalArray(nrms); - gtess->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + gtess->setNormalArray(nrms, osg::Array::BIND_PER_VERTEX); gtess->setTexCoordArray(0,tcs); for (i = 0; i < 4; i++) { @@ -167,10 +165,10 @@ osg::Geometry *makeSideWall (const float xpos) nrms->push_back(nrm); } gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,5));nstart+=5; - + // demonstrate that the Tessellator makes textured tessellations osg::StateSet* stateset = new osg::StateSet(); - + osg::Image* image = osgDB::readImageFile("Cubemap_snow/posx.jpg"); if (image) { @@ -181,7 +179,7 @@ osg::Geometry *makeSideWall (const float xpos) stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); } gtess->setStateSet( stateset ); - + osg::ref_ptr tscx=new osgUtil::Tessellator; // the v1.2 multi-contour Tessellator. // we use the geometry primitives to describe the contours which are tessellated. @@ -189,9 +187,9 @@ osg::Geometry *makeSideWall (const float xpos) tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); tscx->setBoundaryOnly(false); tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // so that first change in wind type makes the commonest tessellation - ODD. - + tscx->retessellatePolygons(*gtess); - + return gtess; } @@ -210,48 +208,47 @@ osg::Geometry *makeFrontWall (const float zpos) { // front wall static GLdouble wall[5][2] = { { 2200.0, 1130.0 }, - { 2600.0, 1130.0 }, - { 2600.0, 1340.0 }, + { 2600.0, 1130.0 }, + { 2600.0, 1340.0 }, { 2400.0, 1440.0 }, { 2200.0, 1340.0 } }; static GLdouble door[4][2] = { { 2360.0, 1130.0 }, - { 2440.0, 1130.0 }, + { 2440.0, 1130.0 }, { 2440.0, 1230.0 }, { 2360.0, 1230.0 } }; static GLdouble windows[16][2] = { { 2240.0, 1180.0 }, - { 2330.0, 1180.0 }, + { 2330.0, 1180.0 }, { 2330.0, 1220.0 }, - { 2240.0, 1220.0 }, + { 2240.0, 1220.0 }, { 2460.0, 1180.0 }, - { 2560.0, 1180.0 }, + { 2560.0, 1180.0 }, { 2560.0, 1220.0 }, { 2460.0, 1220.0 }, { 2240.0, 1280.0 }, - { 2330.0, 1280.0 }, + { 2330.0, 1280.0 }, { 2330.0, 1320.0 }, - { 2240.0, 1320.0 }, + { 2240.0, 1320.0 }, { 2460.0, 1280.0 }, - { 2560.0, 1280.0 }, + { 2560.0, 1280.0 }, { 2560.0, 1320.0 }, { 2460.0, 1320.0 } }; gtess->setVertexArray(coords); - gtess->setNormalArray(nrms); - gtess->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + gtess->setNormalArray(nrms, osg::Array::BIND_PER_VERTEX); gtess->setTexCoordArray(0,tcs); - // add one large pentagon -the wall + // add one large pentagon -the wall for (i = 0; i < 5; i++) { coords->push_back(osg::Vec3(wall[i][0],zpos,wall[i][1])); tcs->push_back(osg::Vec2(wall[i][0],wall[i][1])/100.0); nrms->push_back(nrm); } gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,5));nstart+=5; - // add first hole, a door + // add first hole, a door for (i = 0; i < 4; i++) { coords->push_back(osg::Vec3(door[i][0],zpos,door[i][1])); tcs->push_back(osg::Vec2(door[i][0],door[i][1])/100.0); @@ -267,7 +264,7 @@ osg::Geometry *makeFrontWall (const float zpos) { // demonstrate that the Tessellator makes textured tessellations osg::StateSet* stateset = new osg::StateSet(); - + osg::Image* image = osgDB::readImageFile("Cubemap_snow/posy.jpg"); if (image) { @@ -278,16 +275,16 @@ osg::Geometry *makeFrontWall (const float zpos) { stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); } gtess->setStateSet( stateset ); - - // We use a Tessellator to produce the tessellation required once only + + // We use a Tessellator to produce the tessellation required once only // and the contours are discarded. osg::ref_ptr tscx=new osgUtil::Tessellator; // the v1.2 multi-contour Tessellator. tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); tscx->setBoundaryOnly(false); tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // so that first change in wind type makes the commonest tessellation - ODD. - + tscx->retessellatePolygons(*gtess); - + return gtess; } osg::Geode *makeHouse (void) { @@ -306,85 +303,85 @@ osg::Geometry *makePols (void) { osg::Vec2Array *tcs = new osg::Vec2Array; osg::Vec3 nrm(0,-1,0); // coordinates from red book code but shifted by 1000 & 2000 for alternate Tessellatory things. - static GLdouble rects[12][3] = + static GLdouble rects[12][3] = { { 50.0, 50.0, 0.0 }, - { 300.0, 50.0, 0.0 }, + { 300.0, 50.0, 0.0 }, { 300.0, 300.0, 0.0 }, { 50.0, 300.0, 0.0 }, { 100.0, 100.0, 0.0 }, - { 250.0, 100.0, 0.0 }, + { 250.0, 100.0, 0.0 }, { 250.0, 250.0, 0.0 }, { 100.0, 250.0, 0.0 }, { 150.0, 150.0, 0.0 }, - { 200.0, 150.0, 0.0 }, + { 200.0, 150.0, 0.0 }, { 200.0, 200.0, 0.0 }, { 150.0, 200.0, 0.0 } }; static GLdouble rectsMidanti[12][3] = // the centre 2 contours are traversed opposite order to outer contour. { { 1050.0, 50.0, 0.0 }, - { 1300.0, 50.0, 0.0 }, + { 1300.0, 50.0, 0.0 }, { 1300.0, 300.0, 0.0 }, { 1050.0, 300.0, 0.0 }, { 1250.0, 100.0, 0.0 }, - { 1100.0, 100.0, 0.0 }, + { 1100.0, 100.0, 0.0 }, { 1100.0, 250.0, 0.0 }, - { 1250.0, 250.0, 0.0 }, + { 1250.0, 250.0, 0.0 }, { 1200.0, 150.0, 0.0 }, - { 1150.0, 150.0, 0.0 }, + { 1150.0, 150.0, 0.0 }, { 1150.0, 200.0, 0.0 }, { 1200.0, 200.0, 0.0 } }; static GLdouble spiral[16][3] = // shift by 1000; nb the order of vertices is reversed from that of the red book { { 3400.0, 250.0, 0.0 }, - { 3400.0, 50.0, 0.0 }, - { 3050.0, 50.0, 0.0 }, - { 3050.0, 400.0, 0.0 }, - { 3350.0, 400.0, 0.0 }, - { 3350.0, 100.0, 0.0 }, - { 3100.0, 100.0, 0.0 }, - { 3100.0, 350.0, 0.0 }, - { 3300.0, 350.0, 0.0 }, - { 3300.0, 150.0, 0.0 }, - { 3150.0, 150.0, 0.0 }, - { 3150.0, 300.0, 0.0 }, - { 3250.0, 300.0, 0.0 }, - { 3250.0, 200.0, 0.0 }, - { 3200.0, 200.0, 0.0 }, + { 3400.0, 50.0, 0.0 }, + { 3050.0, 50.0, 0.0 }, + { 3050.0, 400.0, 0.0 }, + { 3350.0, 400.0, 0.0 }, + { 3350.0, 100.0, 0.0 }, + { 3100.0, 100.0, 0.0 }, + { 3100.0, 350.0, 0.0 }, + { 3300.0, 350.0, 0.0 }, + { 3300.0, 150.0, 0.0 }, + { 3150.0, 150.0, 0.0 }, + { 3150.0, 300.0, 0.0 }, + { 3250.0, 300.0, 0.0 }, + { 3250.0, 200.0, 0.0 }, + { 3200.0, 200.0, 0.0 }, { 3200.0, 250.0, 0.0 } }; static GLdouble quad1[4][3] = // shift by 2000 for next 3 things - { { 2050.0, 150.0, 0.0 }, - { 2350.0, 150.0, 0.0 }, - { 2350.0, 200.0, 0.0 }, + { { 2050.0, 150.0, 0.0 }, + { 2350.0, 150.0, 0.0 }, + { 2350.0, 200.0, 0.0 }, { 2050.0, 200.0, 0.0 } }; static GLdouble quad2[4][3] = { { 2100.0, 100.0, 0.0 }, - { 2300.0, 100.0, 0.0 }, - { 2300.0, 350.0, 0.0 }, + { 2300.0, 100.0, 0.0 }, + { 2300.0, 350.0, 0.0 }, { 2100.0, 350.0, 0.0 } }; static GLdouble tri[3][3] = - { { 2200.0, 50.0, 0.0 }, + { { 2200.0, 50.0, 0.0 }, { 2250.0, 300.0, 0.0 }, { 2150.0, 300.0, 0.0 } }; static GLdouble quad3[4][3] = - { { 100.0, 1100.0, 0.0 }, - { 1300.0, 1100.0, 0.0 }, - { 1300.0, 2350.0, 0.0 }, + { { 100.0, 1100.0, 0.0 }, + { 1300.0, 1100.0, 0.0 }, + { 1300.0, 2350.0, 0.0 }, { 100.0, 2350.0, 0.0} }; static GLdouble quadstrip[8][3] = { { 900.0, 1130.0, 0.0 }, - { 1100.0, 1130.0, 0.0 }, + { 1100.0, 1130.0, 0.0 }, { 900.0, 1350.0, 0.0 }, - { 950.0, 1350.0, 0.0 }, + { 950.0, 1350.0, 0.0 }, { 900.0, 1550.0, 0.0 }, { 1000.0, 1550.0, 0.0 }, { 900.0, 1750.0, 0.0 }, { 1400.0, 1750.0, 0.0 } }; - + for (i = 0; i < 12; i++) { coords->push_back(osg::Vec3(rects[i][0],rects[i][2],rects[i][1])); tcs->push_back(osg::Vec2(rects[i][0],rects[i][1])/200.0); @@ -448,20 +445,19 @@ osg::Geometry *makePols (void) { nrms->push_back(nrm); } } - // add one large quadstrip + // add one large quadstrip for (i = 0; i < 8; i++) { coords->push_back(osg::Vec3(quadstrip[i][0],quadstrip[i][2],quadstrip[i][1])); tcs->push_back(osg::Vec2(quadstrip[i][0],quadstrip[i][1])/200.0); nrms->push_back(nrm); } gtess->setVertexArray(coords); - gtess->setNormalArray(nrms); - gtess->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + gtess->setNormalArray(nrms, osg::Array::BIND_PER_VERTEX); gtess->setTexCoordArray(0,tcs); - + // demonstrate that the Tessellator makes textured tessellations osg::StateSet* stateset = new osg::StateSet(); - + osg::Image* image = osgDB::readImageFile("Cubemap_snow/posz.jpg"); if (image) { @@ -472,7 +468,7 @@ osg::Geometry *makePols (void) { stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); } gtess->setStateSet( stateset ); - + int nstart=0; // the contours accepoted are polygons; quads & tris. Trifans can bve added later. gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,nstart,12));nstart+=12; @@ -488,28 +484,28 @@ osg::Geometry *makePols (void) { gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,18));nstart+=18; // test for quad strip gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,nstart,8));nstart+=8; - + // We need to access the tessellatable contours again to demonstrate all types of tessellation. // I could add the Tessellator to the geometry as userdata, but here // I use the derived tessellateDemoGeometry to hold both the drawable geode and the original contours. - + gtess->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); gtess->setBoundaryOnly(true); gtess->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tessellation - ODD. - + return gtess; } osg::Node* createHUD() { // add a string reporting the type of winding rule tessellation applied osg::Geode* geode = new osg::Geode(); - + std::string timesFont("fonts/arial.ttf"); // turn lighting off for the text and disable depth test to ensure its always ontop. osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - // Disable depth test, and make sure that the hud is drawn after everything + // Disable depth test, and make sure that the hud is drawn after everything // else so that it always appears ontop. stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); stateset->setRenderBinDetails(11,"RenderBin"); @@ -526,8 +522,8 @@ osg::Node* createHUD() text->setText("Tessellation example - no tessellation (use 'W' wireframe to visualise)"); text->setColor(osg::Vec4(1.0,1.0,0.8,1.0)); position += delta; - - } + + } { osgText::Text* text = new osgText::Text; geode->addDrawable( text ); @@ -535,8 +531,8 @@ osg::Node* createHUD() text->setFont(timesFont); text->setPosition(position); text->setText("Press 'n' to use an alternative tessellation."); - - } + + } // create the hud. osg::MatrixTransform* modelview_abs = new osg::MatrixTransform; @@ -573,7 +569,7 @@ class setTessellateVisitor : public osg::NodeVisitor // all the polygons within the specific node are deemed to be contours, so // any tessellation can be requested. public: - + setTessellateVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { } virtual void apply(osg::Geode& geode) { @@ -631,7 +627,7 @@ public: } } } - } + } }; class cxTessellateVisitor : public osg::NodeVisitor @@ -641,7 +637,7 @@ class cxTessellateVisitor : public osg::NodeVisitor // the Tessellator holds copies of the original contours used in the tessellation // In this visitor, I reuse the contours to make a different type of tessellation. public: - + cxTessellateVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { } virtual void apply(osg::Geode& geode) { @@ -651,9 +647,9 @@ public: tessellateDemoGeometry *geom=dynamic_cast(geode.getDrawable(i)); if (geom) { if (!geom->getBoundaryOnly()) { // turn on bounds only - // NB this shows only the true boundary of the curves, no internal edges + // NB this shows only the true boundary of the curves, no internal edges geom->setBoundaryOnly(true); - + } else { // change to next type of tessellation... geom->setBoundaryOnly(false); switch (geom->getWindingType()) { @@ -674,7 +670,7 @@ public: break; } } - + switch (geom->getWindingType()) { // a text to be added to the scene. case osgUtil::Tessellator::TESS_WINDING_ODD: str="TESS_WINDING_ODD"; @@ -693,7 +689,7 @@ public: break; } if (geom->getBoundaryOnly()) str += " Boundary"; - + geom->retessellatePolygons(*geom); } osgText::Text* txt = dynamic_cast(geode.getDrawable(i)); @@ -706,17 +702,17 @@ public: } traverse(geode); } - + std::string str; // a label for on screen display }; class KeyboardEventHandler : public osgGA::GUIEventHandler { // extra event handler traps 'n' key to re-tessellate any tessellated geodes. public: - + KeyboardEventHandler(osg::Node *nd): _scene(nd) {} - + virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) { switch(ea.getEventType()) @@ -725,8 +721,8 @@ public: { if (_scene && ea.getKey()=='n') { - // re-tessellate the scene graph. - // the same contours are re-tessellated using a new method. Old contours + // re-tessellate the scene graph. + // the same contours are re-tessellated using a new method. Old contours // & tessellation type are held internally in the derived Geode class tessellateDemoGeometry. cxTessellateVisitor tsv; _scene->accept(tsv); @@ -739,9 +735,9 @@ public: } return false; } - + osg::Node *_scene; - + }; @@ -757,7 +753,7 @@ int main( int argc, char **argv ) osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); // if no model has been successfully loaded report failure. - if (!loadedModel) + if (!loadedModel) { loadedModel=makeTessellateExample(); diff --git a/examples/osgtexture2D/osgtexture2D.cpp b/examples/osgtexture2D/osgtexture2D.cpp index b5e1752fd..30d04f729 100644 --- a/examples/osgtexture2D/osgtexture2D.cpp +++ b/examples/osgtexture2D/osgtexture2D.cpp @@ -56,11 +56,11 @@ public: _minFilterList.push_back(osg::Texture2D::NEAREST); _magFilterList.push_back(osg::Texture2D::NEAREST); _textList.push_back("Nearest filtering\nsetFilter(MIN_FILTER,NEAREST)\nsetFilter(MAG_FILTER,NEAREST)"); - + _minFilterList.push_back(osg::Texture2D::LINEAR); _magFilterList.push_back(osg::Texture2D::LINEAR); _textList.push_back("Linear filtering\nsetFilter(MIN_FILTER,LINEAR)\nsetFilter(MAG_FILTER,LINEAR)"); - + _minFilterList.push_back(osg::Texture2D::NEAREST_MIPMAP_NEAREST); _magFilterList.push_back(osg::Texture2D::LINEAR); _textList.push_back("nearest mip mapping (default filtering)\nsetFilter(MIN_FILTER,)\nsetFilter(MAG_FILTER,LINEAR)"); @@ -73,7 +73,7 @@ public: _magFilterList.push_back(osg::Texture2D::LINEAR); _textList.push_back("bi-linear mip mapping\nsetFilter(MIN_FILTER,NEAREST_MIPMAP_LINEAR)\nsetFilter(MAG_FILTER,LINEAR)"); - + setValues(); } @@ -82,21 +82,21 @@ public: if (nv->getFrameStamp()) { double currTime = nv->getFrameStamp()->getSimulationTime(); - if (currTime-_prevTime>_delay) + if (currTime-_prevTime>_delay) { // update filter modes and text. setValues(); - + // advance the current positon, wrap round if required. _currPos++; - if (_currPos>=_minFilterList.size()) _currPos=0; - + if (_currPos>=_minFilterList.size()) _currPos=0; + // record time _prevTime = currTime; } } } - + void setValues() { _texture->setFilter(osg::Texture2D::MIN_FILTER,_minFilterList[_currPos]); @@ -113,38 +113,38 @@ protected: osg::ref_ptr _texture; osg::ref_ptr _text; double _delay; - + FilterList _minFilterList; FilterList _magFilterList; TextList _textList; - + unsigned int _currPos; double _prevTime; - + }; osg::Node* createFilterWall(osg::BoundingBox& bb,const std::string& filename) { osg::Group* group = new osg::Group; - + // left hand side of bounding box. osg::Vec3 top_left(bb.xMin(),bb.yMin(),bb.zMax()); osg::Vec3 bottom_left(bb.xMin(),bb.yMin(),bb.zMin()); osg::Vec3 bottom_right(bb.xMin(),bb.yMax(),bb.zMin()); osg::Vec3 top_right(bb.xMin(),bb.yMax(),bb.zMax()); - osg::Vec3 center(bb.xMin(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f); + osg::Vec3 center(bb.xMin(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f); float height = bb.zMax()-bb.zMin(); - + // create the geometry for the wall. osg::Geometry* geom = new osg::Geometry; - + osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); - + osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f,1.0f); (*texcoords)[1].set(0.0f,0.0f); @@ -154,31 +154,29 @@ osg::Node* createFilterWall(osg::BoundingBox& bb,const std::string& filename) osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(1.0f,0.0f,0.0f); - geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); - + geom->setNormalArray(normals, osg::Array::BIND_OVERALL); + osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); - + osg::Geode* geom_geode = new osg::Geode; geom_geode->addDrawable(geom); group->addChild(geom_geode); - - - // set up the texture state. + + + // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. texture->setImage(osgDB::readImageFile(filename)); - + osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); - + // create the text label. - + osgText::Text* text = new osgText::Text; text->setDataVariance(osg::Object::DYNAMIC); @@ -187,20 +185,20 @@ osg::Node* createFilterWall(osg::BoundingBox& bb,const std::string& filename) text->setCharacterSize(height*0.03f); text->setAlignment(osgText::Text::CENTER_CENTER); text->setAxisAlignment(osgText::Text::YZ_PLANE); - + osg::Geode* text_geode = new osg::Geode; text_geode->addDrawable(text); - + osg::StateSet* text_stateset = text_geode->getOrCreateStateSet(); text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON); - + group->addChild(text_geode); // set the update callback to cycle through the various min and mag filter modes. group->setUpdateCallback(new FilterCallback(texture,text)); - + return group; - + } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -222,16 +220,16 @@ public: _maxAnisotropyList.push_back(1.0f); _textList.push_back("No anisotropic filtering (default)\nsetMaxAnisotropy(1.0f)"); - + _maxAnisotropyList.push_back(2.0f); _textList.push_back("Anisotropic filtering\nsetMaxAnisotropy(2.0f)"); - + _maxAnisotropyList.push_back(4.0f); _textList.push_back("Anisotropic filtering\nsetMaxAnisotropy(4.0f)"); - + _maxAnisotropyList.push_back(8.0f); _textList.push_back("Anisotropic filtering\nsetMaxAnisotropy(8.0f)"); - + _maxAnisotropyList.push_back(16.0f); _textList.push_back("Higest quality anisotropic filtering\nsetMaxAnisotropy(16.0f)"); @@ -243,21 +241,21 @@ public: if (nv->getFrameStamp()) { double currTime = nv->getFrameStamp()->getSimulationTime(); - if (currTime-_prevTime>_delay) + if (currTime-_prevTime>_delay) { // update filter modes and text. setValues(); - + // advance the current positon, wrap round if required. _currPos++; - if (_currPos>=_maxAnisotropyList.size()) _currPos=0; - + if (_currPos>=_maxAnisotropyList.size()) _currPos=0; + // record time _prevTime = currTime; } } } - + void setValues() { _texture->setMaxAnisotropy(_maxAnisotropyList[_currPos]); @@ -273,37 +271,37 @@ protected: osg::ref_ptr _texture; osg::ref_ptr _text; double _delay; - + AnisotropyList _maxAnisotropyList; TextList _textList; - + unsigned int _currPos; double _prevTime; - + }; osg::Node* createAnisotripicWall(osg::BoundingBox& bb,const std::string& filename) { osg::Group* group = new osg::Group; - + // left hand side of bounding box. osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMin()); osg::Vec3 bottom_left(bb.xMin(),bb.yMin(),bb.zMin()); osg::Vec3 bottom_right(bb.xMax(),bb.yMin(),bb.zMin()); osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMin()); - osg::Vec3 center((bb.xMin()+bb.xMax())*0.5f,(bb.yMin()+bb.yMax())*0.5f,bb.zMin()); + osg::Vec3 center((bb.xMin()+bb.xMax())*0.5f,(bb.yMin()+bb.yMax())*0.5f,bb.zMin()); float height = bb.yMax()-bb.yMin(); - + // create the geometry for the wall. osg::Geometry* geom = new osg::Geometry; - + osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); - + osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f,1.0f); (*texcoords)[1].set(0.0f,0.0f); @@ -313,31 +311,29 @@ osg::Node* createAnisotripicWall(osg::BoundingBox& bb,const std::string& filenam osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f,0.0f,1.0f); - geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); - + geom->setNormalArray(normals, osg::Array::BIND_OVERALL); + osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); - + osg::Geode* geom_geode = new osg::Geode; geom_geode->addDrawable(geom); group->addChild(geom_geode); - - - // set up the texture state. + + + // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. texture->setImage(osgDB::readImageFile(filename)); - + osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); - + // create the text label. - + osgText::Text* text = new osgText::Text; text->setDataVariance(osg::Object::DYNAMIC); text->setFont("fonts/arial.ttf"); @@ -349,17 +345,17 @@ osg::Node* createAnisotripicWall(osg::BoundingBox& bb,const std::string& filenam osg::Geode* text_geode = new osg::Geode; text_geode->addDrawable(text); - + osg::StateSet* text_stateset = text_geode->getOrCreateStateSet(); text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON); - + group->addChild(text_geode); // set the update callback to cycle through the various min and mag filter modes. group->setUpdateCallback(new AnisotropicCallback(texture,text)); - + return group; - + } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -380,16 +376,16 @@ public: _wrapList.push_back(osg::Texture2D::CLAMP); _textList.push_back("Default tex coord clamp\nsetWrap(WRAP_S,CLAMP)"); - + _wrapList.push_back(osg::Texture2D::CLAMP_TO_EDGE); _textList.push_back("Clamp to edge extension\nsetWrap(WRAP_S,CLAMP_TO_EDGE)"); - + _wrapList.push_back(osg::Texture2D::CLAMP_TO_BORDER); _textList.push_back("Clamp to border color extension\nsetWrap(WRAP_S,CLAMP_TO_BORDER)"); - + _wrapList.push_back(osg::Texture2D::REPEAT); _textList.push_back("Repeat wrap\nsetWrap(WRAP_S,REPEAT)"); - + _wrapList.push_back(osg::Texture2D::MIRROR); _textList.push_back("Mirror wrap extension\nsetWrap(WRAP_S,MIRROR)"); @@ -401,21 +397,21 @@ public: if (nv->getFrameStamp()) { double currTime = nv->getFrameStamp()->getSimulationTime(); - if (currTime-_prevTime>_delay) + if (currTime-_prevTime>_delay) { // update filter modes and text. setValues(); - + // advance the current positon, wrap round if required. _currPos++; - if (_currPos>=_wrapList.size()) _currPos=0; - + if (_currPos>=_wrapList.size()) _currPos=0; + // record time _prevTime = currTime; } } } - + void setValues() { _texture->setWrap(osg::Texture2D::WRAP_S,_wrapList[_currPos]); @@ -432,37 +428,37 @@ protected: osg::ref_ptr _texture; osg::ref_ptr _text; double _delay; - + WrapList _wrapList; TextList _textList; - + unsigned int _currPos; double _prevTime; - + }; osg::Node* createWrapWall(osg::BoundingBox& bb,const std::string& filename) { osg::Group* group = new osg::Group; - + // left hand side of bounding box. osg::Vec3 top_left(bb.xMax(),bb.yMax(),bb.zMax()); osg::Vec3 bottom_left(bb.xMax(),bb.yMax(),bb.zMin()); osg::Vec3 bottom_right(bb.xMax(),bb.yMin(),bb.zMin()); osg::Vec3 top_right(bb.xMax(),bb.yMin(),bb.zMax()); - osg::Vec3 center(bb.xMax(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f); + osg::Vec3 center(bb.xMax(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f); float height = bb.zMax()-bb.zMin(); - + // create the geometry for the wall. osg::Geometry* geom = new osg::Geometry; - + osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); - + osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(-1.0f,2.0f); (*texcoords)[1].set(-1.0f,-1.0f); @@ -472,34 +468,32 @@ osg::Node* createWrapWall(osg::BoundingBox& bb,const std::string& filename) osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(-1.0f,0.0f,0.0f); - geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); - + geom->setNormalArray(normals, osg::Array::BIND_OVERALL); + osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); - + osg::Geode* geom_geode = new osg::Geode; geom_geode->addDrawable(geom); group->addChild(geom_geode); - - - // set up the texture state. + + + // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. texture->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,0.5f)); // only used when wrap is set to CLAMP_TO_BORDER texture->setImage(osgDB::readImageFile(filename)); - + osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); stateset->setMode(GL_BLEND,osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - + // create the text label. - + osgText::Text* text = new osgText::Text; text->setDataVariance(osg::Object::DYNAMIC); text->setFont("fonts/arial.ttf"); @@ -510,17 +504,17 @@ osg::Node* createWrapWall(osg::BoundingBox& bb,const std::string& filename) osg::Geode* text_geode = new osg::Geode; text_geode->addDrawable(text); - + osg::StateSet* text_stateset = text_geode->getOrCreateStateSet(); text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON); - + group->addChild(text_geode); // set the update callback to cycle through the various min and mag filter modes. group->setUpdateCallback(new WrapCallback(texture,text)); - + return group; - + } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -540,7 +534,7 @@ public: _prevTime(0.0) { -#if 1 +#if 1 osg::ref_ptr originalImage = osgDB::readImageFile("Images/dog_left_eye.jpg"); osg::ref_ptr subImage = new osg::Image; @@ -576,19 +570,19 @@ public: *d = 255-*d; } } -#endif +#endif + - _imageList.push_back(subImage.get()); #else _imageList.push_back(osgDB::readImageFile("Images/dog_left_eye.jpg")); #endif _textList.push_back("Subloaded Image 1 - dog_left_eye.jpg"); - + _imageList.push_back(osgDB::readImageFile("Images/dog_right_eye.jpg")); _textList.push_back("Subloaded Image 2 - dog_right_eye.jpg"); - + setValues(); } @@ -597,21 +591,21 @@ public: if (nv->getFrameStamp()) { double currTime = nv->getFrameStamp()->getSimulationTime(); - if (currTime-_prevTime>_delay) + if (currTime-_prevTime>_delay) { // update filter modes and text. setValues(); - + // advance the current positon, wrap round if required. _currPos++; - if (_currPos>=_imageList.size()) _currPos=0; - + if (_currPos>=_imageList.size()) _currPos=0; + // record time _prevTime = currTime; } } } - + void setValues() { // Note, as long as the images are the same dimensions subloading will be used @@ -622,7 +616,7 @@ public: // the setImage which just updates internal pointers and modifed flags. _texture->setImage(_imageList[_currPos].get()); - + //_texture->dirtyTextureObject(); _text->setText(_textList[_currPos]); @@ -630,44 +624,44 @@ public: protected: - + typedef std::vector< osg::ref_ptr > ImageList; typedef std::vector TextList; osg::ref_ptr _texture; osg::ref_ptr _text; double _delay; - + ImageList _imageList; TextList _textList; - + unsigned int _currPos; double _prevTime; - + }; osg::Node* createSubloadWall(osg::BoundingBox& bb) { osg::Group* group = new osg::Group; - + // left hand side of bounding box. osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMax()); osg::Vec3 bottom_left(bb.xMin(),bb.yMax(),bb.zMin()); osg::Vec3 bottom_right(bb.xMax(),bb.yMax(),bb.zMin()); osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMax()); - osg::Vec3 center((bb.xMax()+bb.xMin())*0.5f,bb.yMax(),(bb.zMin()+bb.zMax())*0.5f); + osg::Vec3 center((bb.xMax()+bb.xMin())*0.5f,bb.yMax(),(bb.zMin()+bb.zMax())*0.5f); float height = bb.zMax()-bb.zMin(); - + // create the geometry for the wall. osg::Geometry* geom = new osg::Geometry; - + osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); - + osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f,1.0f); (*texcoords)[1].set(0.0f,0.0f); @@ -677,32 +671,30 @@ osg::Node* createSubloadWall(osg::BoundingBox& bb) osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f,-1.0f,0.0f); - geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); - + geom->setNormalArray(normals, osg::Array::BIND_OVERALL); + osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); - + osg::Geode* geom_geode = new osg::Geode; geom_geode->addDrawable(geom); group->addChild(geom_geode); - - - // set up the texture state. + + + // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); - + osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); - + // create the text label. - + osgText::Text* text = new osgText::Text; text->setDataVariance(osg::Object::DYNAMIC); text->setFont("fonts/arial.ttf"); @@ -710,20 +702,20 @@ osg::Node* createSubloadWall(osg::BoundingBox& bb) text->setCharacterSize(height*0.03f); text->setAlignment(osgText::Text::CENTER_CENTER); text->setAxisAlignment(osgText::Text::XZ_PLANE); - + osg::Geode* text_geode = new osg::Geode; text_geode->addDrawable(text); - + osg::StateSet* text_stateset = text_geode->getOrCreateStateSet(); text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON); - + group->addChild(text_geode); // set the update callback to cycle through the various min and mag filter modes. group->setUpdateCallback(new ImageUpdateCallback(texture,text)); - + return group; - + } @@ -732,8 +724,8 @@ osg::Node* createModel() // create the root node which will hold the model. osg::Group* root = new osg::Group(); - - // turn off lighting + + // turn off lighting root->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); osg::BoundingBox bb(0.0f,0.0f,0.0f,1.0f,1.0f,1.0f); @@ -742,7 +734,7 @@ osg::Node* createModel() root->addChild(createAnisotripicWall(bb,"Images/primitives.gif")); root->addChild(createWrapWall(bb,"Images/tree0.rgba")); root->addChild(createSubloadWall(bb)); - + return root; } diff --git a/examples/osgtexture3D/osgtexture3D.cpp b/examples/osgtexture3D/osgtexture3D.cpp index 76f33a279..4b31fb0d1 100644 --- a/examples/osgtexture3D/osgtexture3D.cpp +++ b/examples/osgtexture3D/osgtexture3D.cpp @@ -31,7 +31,7 @@ #include // -// A simple demo demonstrating different texturing modes, +// A simple demo demonstrating different texturing modes, // including using of texture extensions. // @@ -78,7 +78,7 @@ osg::StateSet* createState() image_3d->copySubImage(0,0,2,image_2.get()); image_3d->copySubImage(0,0,3,image_3.get()); - image_3d->setInternalTextureFormat(image_0->getInternalTextureFormat()); + image_3d->setInternalTextureFormat(image_0->getInternalTextureFormat()); // set up the 3d texture itself, // note, well set the filtering up so that mip mapping is disabled, @@ -114,7 +114,7 @@ class UpdateStateCallback : public osg::NodeCallback { public: UpdateStateCallback() {} - + void animateState(osg::StateSet* stateset) { // here we simply get any existing texgen, and then increment its @@ -129,7 +129,7 @@ class UpdateStateCallback : public osg::NodeCallback } virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) - { + { osg::StateSet* stateset = node->getStateSet(); if (stateset) @@ -139,10 +139,10 @@ class UpdateStateCallback : public osg::NodeCallback } // note, callback is repsonsible for scenegraph traversal so - // should always include call the traverse(node,nv) to ensure + // should always include call the traverse(node,nv) to ensure // that the rest of cullbacks and the scene graph are traversed. traverse(node,nv); - } + } }; /** create 2,2 square with center at 0,0,0 and aligned along the XZ plan */ @@ -160,8 +160,7 @@ osg::Drawable* createSquare(float textureCoordMax=1.0f) osg::Vec3Array* norms = new osg::Vec3Array(1); (*norms)[0].set(0.0f,-1.0f,0.0f); - geom->setNormalArray(norms); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); + geom->setNormalArray(norms, osg::Array::BIND_OVERALL); osg::Vec2Array* tcoords = new osg::Vec2Array(4); (*tcoords)[0].set(0.0f,textureCoordMax); @@ -169,7 +168,7 @@ osg::Drawable* createSquare(float textureCoordMax=1.0f) (*tcoords)[2].set(textureCoordMax,0.0f); (*tcoords)[3].set(textureCoordMax,textureCoordMax); geom->setTexCoordArray(0,tcoords); - + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); return geom; @@ -178,7 +177,7 @@ osg::Drawable* createSquare(float textureCoordMax=1.0f) osg::Node* createModel() { - // create the geometry of the model, just a simple 2d quad right now. + // create the geometry of the model, just a simple 2d quad right now. osg::Geode* geode = new osg::Geode; geode->addDrawable(createSquare()); @@ -195,7 +194,7 @@ osg::Node* createModel() // this current limitation. geode->setUpdateCallback(new UpdateStateCallback()); geode->setStateSet(createState()); - + return geode; } diff --git a/examples/osgtexturerectangle/osgtexturerectangle.cpp b/examples/osgtexturerectangle/osgtexturerectangle.cpp index 1a674e447..97617cb0a 100644 --- a/examples/osgtexturerectangle/osgtexturerectangle.cpp +++ b/examples/osgtexturerectangle/osgtexturerectangle.cpp @@ -114,7 +114,7 @@ osg::Node* createRectangle(osg::BoundingBox& bb, osg::Vec3 bottom_left(bb.xMin(),bb.yMax(),bb.zMin()); osg::Vec3 bottom_right(bb.xMax(),bb.yMax(),bb.zMin()); osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMax()); - + // create geometry osg::Geometry* geom = new osg::Geometry; @@ -124,7 +124,7 @@ osg::Node* createRectangle(osg::BoundingBox& bb, (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); - + osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f, 0.0f); (*texcoords)[1].set(1.0f, 0.0f); @@ -134,13 +134,11 @@ osg::Node* createRectangle(osg::BoundingBox& bb, osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f,-1.0f,0.0f); - geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_OVERALL); + geom->setNormalArray(normals, osg::Array::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); - geom->setColorArray(colors); - geom->setColorBinding(osg::Geometry::BIND_OVERALL); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4)); @@ -161,14 +159,14 @@ osg::Node* createRectangle(osg::BoundingBox& bb, state->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); state->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); - // turn off lighting + // turn off lighting state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); // install 'update' callback osg::Geode* geode = new osg::Geode; geode->addDrawable(geom); geode->setUpdateCallback(new TexturePanCallback(texmat)); - + return geode; } @@ -262,6 +260,6 @@ int main(int argc, char** argv) // add model to viewer. viewer.setSceneData(rootNode); - + return viewer.run(); } diff --git a/examples/osgthirdpersonview/osgthirdpersonview.cpp b/examples/osgthirdpersonview/osgthirdpersonview.cpp index c1bc5e108..ea9e15c7f 100644 --- a/examples/osgthirdpersonview/osgthirdpersonview.cpp +++ b/examples/osgthirdpersonview/osgthirdpersonview.cpp @@ -100,8 +100,7 @@ makeFrustumFromCamera( osg::Camera* camera ) osg::Vec4Array* c = new osg::Vec4Array; c->push_back( osg::Vec4( 1., 1., 1., 1. ) ); - geom->setColorArray( c ); - geom->setColorBinding( osg::Geometry::BIND_OVERALL ); + geom->setColorArray( c, osg::Array::BIND_OVERALL ); GLushort idxLines[8] = { 0, 5, 0, 6, 0, 7, 0, 8 }; @@ -170,7 +169,7 @@ main( int argc, view->setSceneData( scene.get() ); view->setCameraManipulator( new osgGA::TrackballManipulator ); } - + // Create view 1 -- Contains the loaded moel, as well as a wireframe frustum derived from View 0's Camera. { osgViewer::View* view = new osgViewer::View; diff --git a/examples/osgvertexattributes/osgvertexattributes.cpp b/examples/osgvertexattributes/osgvertexattributes.cpp index 664095399..28dfb2c79 100644 --- a/examples/osgvertexattributes/osgvertexattributes.cpp +++ b/examples/osgvertexattributes/osgvertexattributes.cpp @@ -209,32 +209,32 @@ class ConvertToVertexAttibArrays : public osg::NodeVisitor osg::notify(osg::NOTICE)<<"Found geometry "<<&geom<setName(name); + if (binding!=osg::Array::BIND_UNDEFINED) array->setBinding(binding); + array->setNormalize(normalize); geom.setVertexAttribArray(index, array); - geom.setVertexAttribNormalize(index, normalize); - geom.setVertexAttribBinding(index, binding); osg::notify(osg::NOTICE)<<" vertex attrib("<addChild(geode); - + osg::Geometry* geometry = new osg::Geometry; geode->addDrawable(geometry); @@ -301,14 +301,14 @@ osg::Node* createSimpleTestModel() geometry->setVertexArray(vertices); geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4)); - - char vertexShaderSource[] = + + char vertexShaderSource[] = "void main(void)\n" "{\n" " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" "}\n"; - char fragmentShaderSource[] = + char fragmentShaderSource[] = "void main(void)\n" "{\n" " gl_FragColor = vec4(1.0,1.0,0.0,1.0); \n" @@ -319,17 +319,17 @@ osg::Node* createSimpleTestModel() program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource)); geometry->getOrCreateStateSet()->setAttribute(program); - + return group; } osg::Node* createSimpleTextureTestModel() { osg::Group* group = new osg::Group; - + osg::Geode* geode = new osg::Geode; group->addChild(geode); - + osg::Geometry* geometry = new osg::Geometry; geode->addDrawable(geometry); @@ -348,8 +348,8 @@ osg::Node* createSimpleTextureTestModel() geometry->setTexCoordArray(0, texcoords); geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4)); - - char vertexShaderSource[] = + + char vertexShaderSource[] = "varying vec2 texCoord;\n" "void main(void)\n" "{\n" @@ -357,7 +357,7 @@ osg::Node* createSimpleTextureTestModel() " texCoord = gl_MultiTexCoord0.xy;\n" "}\n"; - char fragmentShaderSource[] = + char fragmentShaderSource[] = "varying vec2 texCoord;\n" "uniform sampler2D baseTexture;\n" "void main(void)\n" @@ -371,13 +371,13 @@ osg::Node* createSimpleTextureTestModel() osg::StateSet* stateset = geometry->getOrCreateStateSet(); stateset->setAttribute(program); - + osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); osg::Texture2D* texture = new osg::Texture2D(image); texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); stateset->setTextureAttribute(0, texture); - + osg::Uniform* baseTextureSampler = new osg::Uniform("baseTexture",0); stateset->addUniform(baseTextureSampler); @@ -436,9 +436,9 @@ int main(int argc, char *argv[]) loadedModel->accept(ctvaa); } } - + if (!loadedModel) return 1; - + if (!outputFileName.empty()) { osgDB::writeNodeFile(*loadedModel, outputFileName);