OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SceneGraphBuilder.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
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.
7  *
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.
12 */
13 
14 #ifndef OSGUTIL_SCENEGRAPHBUILDER
15 #define OSGUTIL_SCENEGRAPHBUILDER 1
16 
17 #include <osg/Geode>
18 #include <osg/Geometry>
19 #include <osg/MatrixTransform>
20 #include <osg/GLU>
21 
22 #include <osgUtil/Export>
23 
24 namespace osgUtil {
25 
29 {
30  public:
31 
33 
34  //
35  // OpenGL 1.0 style building methods
36  //
37  void PushMatrix();
38  void PopMatrix();
39  void LoadIdentity();
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);
45 
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);
57 
58  void Enable(GLenum mode);
59  void Disable(GLenum mode);
60 
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]); }
63 
64  void Vertex3f(GLfloat x, GLfloat y, GLfloat z);
65  void Vertex3fv(GLfloat* v) { Vertex3f(v[0], v[1], v[2]); }
66 
67  void Normal3f(GLfloat x, GLfloat y, GLfloat z);
68  void Normal3fv(GLfloat* n) { Normal3f(n[0], n[1], n[2]); }
69 
70  void TexCoord1f(GLfloat x);
71  void TexCoord1fv(GLfloat* tc) { TexCoord1f(tc[0]); }
72 
73  void TexCoord2f(GLfloat x, GLfloat y);
74  void TexCoord2fv(GLfloat* tc) { TexCoord2f(tc[0],tc[1]); }
75 
76  void TexCoord3f(GLfloat x, GLfloat y, GLfloat z);
77  void TexCoord3fv(GLfloat* tc) { TexCoord3f(tc[0], tc[1], tc[2]); }
78 
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]); }
81 
82  void Begin(GLenum mode);
83  void End();
84 
85  //
86  // glu style building methods
87  //
88  void QuadricDrawStyle(GLenum aDrawStyle);
89  void QuadricNormals(GLenum aNormals);
90  void QuadricOrientation(GLenum aOrientation);
91  void QuadricTexture(GLboolean aTexture);
92 
93  void Cylinder(GLfloat base,
94  GLfloat top,
95  GLfloat height,
96  GLint slices,
97  GLint stacks);
98 
99  void Disk(GLfloat inner,
100  GLfloat outer,
101  GLint slices,
102  GLint loops);
103 
104  void PartialDisk(GLfloat inner,
105  GLfloat outer,
106  GLint slices,
107  GLint loops,
108  GLfloat start,
109  GLfloat sweep);
110 
111  void Sphere(GLfloat radius,
112  GLint slices,
113  GLint stacks);
114 
115 
116  //
117  // methods for obtaining the built scene graph
118  //
119  osg::Node* getScene();
120  osg::Node* takeScene();
121 
122  protected:
123 
124  typedef std::vector<osg::Matrixd> Matrices;
125 
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);
133  void newGeometry();
134 
135  void allocateGeometry();
136  void completeGeometry();
137 
138  void allocateStateSet();
139 
140  Matrices _matrixStack;
143 
146 
147  bool _colorSet;
149 
152 
158 
160  {
162  _drawStyle(GLU_FILL),
163  _normals(GLU_SMOOTH),
164  _orientation(GLU_OUTSIDE),
165  _texture(GLU_FALSE) {}
166 
167  GLenum _drawStyle;
168  GLenum _normals;
169  GLenum _orientation;
170  GLboolean _texture;
171  };
172 
174 
175 
180 
181 };
182 
183 
184 }
185 
186 #endif
osg::ref_ptr< osg::MatrixTransform > _transform
void TexCoord2fv(GLfloat *tc)
osg::ref_ptr< osg::Vec3Array > _vertices
osg::ref_ptr< osg::Geometry > _geometry
#define GLU_SMOOTH
Definition: GLU.h:100
osg::ref_ptr< osg::Geode > _geode
osg::ref_ptr< osg::StateSet > _stateset
void TexCoord4fv(GLfloat *tc)
std::vector< osg::Matrixd > Matrices
#define GLU_FILL
Definition: GLU.h:93
osg::ref_ptr< osg::Vec4Array > _colors
double GLdouble
Definition: GL.h:159
void TexCoord3fv(GLfloat *tc)
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71
#define GLU_FALSE
Definition: GLU.h:87
Definition: Node.h:71
#define GLU_OUTSIDE
Definition: GLU.h:105
osg::ref_ptr< osg::Group > _group
#define OSGUTIL_EXPORT
Definition: Export.h:40
void TexCoord1fv(GLfloat *tc)
osg::ref_ptr< osg::Vec3Array > _normals
osg::ref_ptr< osg::Vec4Array > _texCoords
Shader generator framework.
Definition: RenderInfo.h:20