root/OpenSceneGraph/trunk/examples/osghangglide/base.cpp @ 1697

Revision 1697, 1.9 kB (checked in by robert, 11 years ago)

Ported osgGLUT based src/Demos across to being osgProducer based, and placed
them in the new examples/ directory.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <math.h>
2
3#include <osg/Geode>
4#include <osg/Geometry>
5#include <osg/Texture2D>
6#include <osg/TexEnv>
7#include <osg/Depth>
8#include <osg/StateSet>
9
10#include <osgDB/ReadFile>
11
12using namespace osg;
13
14Node *makeBase( void )
15{
16    int i, c;
17    float theta;
18    float ir = 20.0f;
19
20    Vec3Array *coords = new Vec3Array(19);
21    Vec2Array *tcoords = new Vec2Array(19);
22    Vec4Array *colors = new Vec4Array(1);
23
24    (*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
25
26    c = 0;
27    (*coords)[c].set(0.0f,0.0f,0.0f);
28    (*tcoords)[c].set(0.0f,0.0f);
29   
30    for( i = 0; i <= 18; i++ )
31    {
32        theta = osg::DegreesToRadians((float)i * 20.0);
33
34        (*coords)[c].set(ir * cosf( theta ), ir * sinf( theta ), 0.0f);
35        (*tcoords)[c].set((*coords)[c][0]/36.0f,(*coords)[c][1]/36.0f);
36
37        c++;
38    }
39
40    Geometry *geom = new Geometry;
41
42    geom->setVertexArray( coords );
43
44    geom->setTexCoordArray( 0, tcoords );
45
46    geom->setColorArray( colors );
47    geom->setColorBinding( Geometry::BIND_OVERALL );
48
49    geom->addPrimitiveSet( new DrawArrays(PrimitiveSet::TRIANGLE_FAN,0,19) );
50
51    Texture2D *tex = new Texture2D;
52
53    tex->setImage(osgDB::readImageFile("Images/water.rgb"));
54    tex->setWrap( Texture2D::WRAP_S, Texture2D::REPEAT );
55    tex->setWrap( Texture2D::WRAP_T, Texture2D::REPEAT );
56
57    StateSet *dstate = new StateSet;
58    dstate->setMode( GL_LIGHTING, StateAttribute::OFF );
59    dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON );
60
61    dstate->setTextureAttribute(0, new TexEnv );
62
63    // clear the depth to the far plane.
64    osg::Depth* depth = new osg::Depth;
65    depth->setFunction(osg::Depth::ALWAYS);
66    depth->setRange(1.0,1.0);   
67    dstate->setAttributeAndModes(depth,StateAttribute::ON );
68
69    dstate->setRenderBinDetails(-1,"RenderBin");
70
71
72    geom->setStateSet( dstate );
73
74    Geode *geode = new Geode;
75    geode->addDrawable( geom );
76
77    return geode;
78}
Note: See TracBrowser for help on using the browser.