1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSGUTIL_SCENEGRAPHBUILDER
15#define OSGUTIL_SCENEGRAPHBUILDER 1
18#include <osg/Geometry>
19#include <osg/MatrixTransform>
22#include <osgUtil/Export>
26/** A class for assisting the building a scene graph that is equivalent to OpenGL 1.0 style calls.
28class OSGUTIL_EXPORT SceneGraphBuilder
35 // OpenGL 1.0 style building methods
40 void LoadMatrixd(const GLdouble* m);
41 void MultMatrixd(const GLdouble* m);
42 void Translated(GLdouble x, GLdouble y, GLdouble z);
43 void Scaled(GLdouble x, GLdouble y, GLdouble z);
44 void Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
46 void BlendFunc(GLenum srcFactor, GLenum dstFactor);
47 void CullFace(GLenum mode);
48 void DepthFunc(GLenum mode);
49 void FrontFace(GLenum mode);
50 void LineStipple(GLint factor, GLushort pattern);
51 void LineWidth(GLfloat lineWidth);
52 void PointSize(GLfloat pointSize);
53 void PolygonMode(GLenum face, GLenum mode);
54 void PolygonOffset(GLfloat factor, GLfloat units);
55 void PolygonStipple(const GLubyte* mask);
56 void ShadeModel(GLenum mode);
58 void Enable(GLenum mode);
59 void Disable(GLenum mode);
61 void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
62 void Color4fv(GLfloat* c) { Color4f(c[0], c[1], c[2], c[3]); }
64 void Vertex3f(GLfloat x, GLfloat y, GLfloat z);
65 void Vertex3fv(GLfloat* v) { Vertex3f(v[0], v[1], v[2]); }
67 void Normal3f(GLfloat x, GLfloat y, GLfloat z);
68 void Normal3fv(GLfloat* n) { Normal3f(n[0], n[1], n[2]); }
70 void TexCoord1f(GLfloat x);
71 void TexCoord1fv(GLfloat* tc) { TexCoord1f(tc[0]); }
73 void TexCoord2f(GLfloat x, GLfloat y);
74 void TexCoord2fv(GLfloat* tc) { TexCoord2f(tc[0],tc[1]); }
76 void TexCoord3f(GLfloat x, GLfloat y, GLfloat z);
77 void TexCoord3fv(GLfloat* tc) { TexCoord3f(tc[0], tc[1], tc[2]); }
79 void TexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
80 void TexCoord4fv(GLfloat* tc) { TexCoord4f(tc[0], tc[1], tc[2], tc[3]); }
82 void Begin(GLenum mode);
86 // glu style building methods
88 void QuadricDrawStyle(GLenum aDrawStyle);
89 void QuadricNormals(GLenum aNormals);
90 void QuadricOrientation(GLenum aOrientation);
91 void QuadricTexture(GLboolean aTexture);
93 void Cylinder(GLfloat base,
99 void Disk(GLfloat inner,
104 void PartialDisk(GLfloat inner,
111 void Sphere(GLfloat radius,
117 // methods for obtaining the built scene graph
119 osg::Node* getScene();
120 osg::Node* takeScene();
124 typedef std::vector<osg::Matrixd> Matrices;
126 void matrixChanged();
127 void addAttribute(osg::StateAttribute* attribute);
128 void addMode(GLenum mode, bool enabled);
129 void addTextureAttribute(unsigned int unit, osg::StateAttribute* attribute);
130 void addTextureMode(unsigned int unit, GLenum mode, bool enabled);
131 void addShape(osg::Shape* shape);
132 void addDrawable(osg::Drawable* drawable);
135 void allocateGeometry();
136 void completeGeometry();
138 void allocateStateSet();
140 Matrices _matrixStack;
141 osg::ref_ptr<osg::StateSet> _stateset;
142 bool _statesetAssigned;
150 unsigned int _maxNumTexCoordComponents;
151 osg::Vec4f _texCoord;
153 GLenum _primitiveMode;
154 osg::ref_ptr<osg::Vec3Array> _vertices;
155 osg::ref_ptr<osg::Vec3Array> _normals;
156 osg::ref_ptr<osg::Vec4Array> _colors;
157 osg::ref_ptr<osg::Vec4Array> _texCoords;
162 _drawStyle(GLU_FILL),
163 _normals(GLU_SMOOTH),
164 _orientation(GLU_OUTSIDE),
165 _texture(GLU_FALSE) {}
173 QuadricState _quadricState;
176 osg::ref_ptr<osg::Geometry> _geometry;
177 osg::ref_ptr<osg::Geode> _geode;
178 osg::ref_ptr<osg::MatrixTransform> _transform;
179 osg::ref_ptr<osg::Group> _group;