Changeset 44 for Swollen/swollen/watersurface.cpp
- Timestamp:
- Dec 10, 2004, 8:13:41 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Swollen/swollen/watersurface.cpp
r43 r44 8 8 9 9 #include <watersurface.h> 10 #include <osg/AlphaFunc> 10 11 #include <osg/BlendFunc> 11 12 #include <osg/PolygonMode> … … 18 19 #include <osgDB/ReadFile> 19 20 21 #include <osgUtil/TriStripVisitor> 22 20 23 21 24 #define DEF_WATER_COLOUR 0, 0, 0.5, 1 // R, G, B, Alpha (blue) 22 25 #define DEF_WATER_TRANSPARENCY 0.1 // 0=opaque, 1=transparent 23 #define DEF_ZOFFSET 0.0 026 #define DEF_ZOFFSET 0.01 24 27 25 28 // constructor … … 38 41 _node->addDrawable(_geom); 39 42 _node->setStateSet(_stateset); 40 _stateset->setAttribute(_material);43 //_stateset->setAttribute(_material); 41 44 42 // why??? 43 _geom->setUseDisplayList(false); 45 _geom->setUseDisplayList(true); 44 46 45 47 // initial geometry 46 48 setTimeStep(0); 47 49 48 _material->setDiffuse(osg::Material::FRONT, osg::Vec4(DEF_WATER_COLOUR));49 _material->setSpecular(osg::Material::FRONT, osg::Vec4(1,1,1,1));50 _material->setTransparency(osg::Material::FRONT_AND_BACK, DEF_WATER_TRANSPARENCY);51 _material->setShininess(osg::Material::FRONT, 128);50 //_material->setDiffuse(osg::Material::FRONT, osg::Vec4(DEF_WATER_COLOUR)); 51 //_material->setSpecular(osg::Material::FRONT, osg::Vec4(1,1,1,1)); 52 //_material->setTransparency(osg::Material::FRONT_AND_BACK, DEF_WATER_TRANSPARENCY); 53 //_material->setShininess(osg::Material::FRONT, 128); 52 54 53 55 // environment map … … 57 59 texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); 58 60 texture->setImage(osgDB::readImageFile("envmap.jpg")); 59 _stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON );61 //_stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON ); 60 62 _stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); 61 63 62 64 // surface transparency 63 osg::BlendFunc* osgBlendFunc = new osg::BlendFunc(); 64 osgBlendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); 65 _stateset->setAttribute(osgBlendFunc); 66 _stateset->setMode(GL_BLEND, osg::StateAttribute::ON); 65 //osg::BlendFunc* osgBlendFunc = new osg::BlendFunc(); 66 //osgBlendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); 67 //_stateset->setAttribute(osgBlendFunc); 68 //_stateset->setMode(GL_BLEND, osg::StateAttribute::ON); 69 70 osg::AlphaFunc* alphaFunc = new osg::AlphaFunc; 71 //alphaFunc->setFunction(osg::AlphaFunc::GEQUAL,0.1f); 72 alphaFunc->setFunction(osg::AlphaFunc::ALWAYS); 73 _stateset->setAttributeAndModes( alphaFunc, osg::StateAttribute::ON ); 74 67 75 _stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); 76 68 77 69 78 // automatically generate texture coords … … 74 83 texenv->setMode( osg::TexEnv::DECAL ); 75 84 texenv->setColor( osg::Vec4(0.6f,0.6f,0.6f,0.2f) ); 76 _stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON );77 _stateset->setTextureAttribute( 1, texenv );85 //_stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON ); 86 //_stateset->setTextureAttribute( 1, texenv ); 78 87 } 79 88 … … 97 106 osg::ref_ptr<osg::Vec3Array> normals = _sww->getStagePrimitiveNormalArray(); 98 107 osg::ref_ptr<osg::Vec3Array> vertexnormals = _sww->getStageVertexNormalArray(); 99 108 osg::ref_ptr<osg::Vec4Array> colors = _sww->getStageColorArray(); 100 109 101 110 // vertical (z) offset to eliminate potential zbuffer problems with bedslope 102 //for( unsigned int iv=0; iv < vertices.get()->size(); iv++ ) 103 // vertices.get()->at(iv) += osg::Vec3f( 0.0, 0.0, _zoffset ); 111 osg::UIntArray* colorindices = new osg::UIntArray(vertices.get()->size()); 112 for( unsigned int iv=0; iv < vertices.get()->size(); iv++ ) 113 { 114 vertices.get()->at(iv) += osg::Vec3f( 0.0, 0.0, _zoffset ); 115 colorindices->at(iv) = iv; 116 } 104 117 118 // geometry 105 119 _geom->setVertexArray( vertices.get() ); 106 120 _geom->setVertexIndices( indices.get() ); … … 108 122 osg::PrimitiveSet::TRIANGLES, 0, _sww->getNumberOfStageIndices() ) ); 109 123 110 //_geom->setNormalArray( normals.get() ); 111 //_geom->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE ); 124 // per vertex colors (using only alpha) 125 _geom->setColorArray( colors.get() ); 126 _geom->setColorIndices( colorindices ); 127 _geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); 112 128 129 // normals 113 130 _geom->setNormalArray( vertexnormals.get() ); 114 131 _geom->setNormalIndices( indices.get() ); 115 132 _geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); 133 134 // osgUtil::TriStripVisitor* optimize = new osgUtil::TriStripVisitor(); 135 // optimize->stripify( *_geom ); 116 136 117 137 }
Note: See TracChangeset
for help on using the changeset viewer.