source: Swollen/swollen/bedslope.cpp @ 64

Last change on this file since 64 was 64, checked in by darran, 20 years ago
  • swollen is broken while I investigate lack of bedslope lighting
File size: 1.9 KB
Line 
1
2
3#include <bedslope.h>
4
5#include <osg/Texture2D>
6#include <osg/TexEnv>
7#include <osgUtil/SmoothingVisitor>
8
9
10#define DEF_BEDSLOPE_COLOUR     145, 122, 59, 255     // R, G, B, Alpha (brown)
11
12
13// constructor
14BedSlope::BedSlope(SWWReader* sww)
15{
16    // persistent
17    _sww = sww;
18
19    // bedslope geometry as triangles with shared vertices
20    _geom = new osg::Geometry;
21
22    // geometry from sww file
23    osg::Vec3Array* vertices = _sww->getBedslopeVertexArray().get();
24    //osg::Vec3Array* normals = _sww->getBedslopeNormalArray().get();
25
26    _geom->setUseDisplayList(true);
27    _geom->setVertexArray( vertices );
28    _geom->addPrimitiveSet( _sww->getBedslopeIndexArray().get() );
29    //_geom->setNormalArray( normals );
30    //_geom->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );
31    _geom->setTexCoordArray( 0, _sww->getBedslopeTextureCoords().get() );
32
33    osg::UByte4Array* color = new osg::UByte4Array(1);
34    (*color)[0] = osg::UByte4( 255,255,255,255 );
35    _geom->setColorArray( color );
36    _geom->setColorBinding( osg::Geometry::BIND_OVERALL );
37
38    // Calculate per-vertex normals
39    osgUtil::SmoothingVisitor* visitor = new osgUtil::SmoothingVisitor();
40    visitor->smooth( *_geom );
41
42    // bedslope texture
43    osg::Texture2D* texture = new osg::Texture2D;
44    texture->setDataVariance(osg::Object::DYNAMIC);
45    texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
46    texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
47    texture->setImage( _sww->getBedslopeTexture() );
48
49    // state
50    _stateset = new osg::StateSet;
51    //_stateset->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON );
52    _stateset->setMode( GL_BLEND, osg::StateAttribute::ON );
53    _stateset->setMode( GL_LIGHTING, osg::StateAttribute::ON );
54
55    _node = new osg::Geode;
56    _node->setName("bedslope");
57    _node->addDrawable(_geom);
58    _node->setStateSet(_stateset);
59
60}
61
Note: See TracBrowser for help on using the repository browser.