opennurbs_gl.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2011 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 ////////////////////////////////////////////////////////////////
18 //
19 // Definitions of ON_GL() functions that demonstrate how to
20 // use GL to display OpenNURBS objects.
21 //
22 ////////////////////////////////////////////////////////////////
23 
24 #include "opennurbs.h"
25 
26 #if defined(ON_COMPILER_MSC)
27 
28 // Tested compilers:
29 // Microsoft Developer Studio 6.0
30 // Microsoft Visual Studio 2005
31 // Support for other Windows compilers is not available.
32 
33 // Windows Open GL files require windows.h to be included before the
34 // Open GL header files.
35 #pragma ON_PRAGMA_WARNING_PUSH
36 #include <windows.h>
37 #include <GL/gl.h> // Open GL basic definitions
38 #include <GL/glu.h> // Open GL utilities (for GL NURBS stuff)
39 #pragma ON_PRAGMA_WARNING_POP
40 
41 #elif defined(ON_COMPILER_CLANG)
42 
43 // Tested compilers:
44 // Apple Xcode 2.4.1
45 // Support for other Apple compilers is not available.
46 #include <GLUT/glut.h> // Open GL auxillary functions
47 
48 #else
49 
50 // Unsupported compiler:
51 // Support for other compilers is not available
52 #include <GL/gl.h> // Open GL basic definitions
53 #include <GL/glu.h> // Open GL utilities (for GL NURBS stuff)
54 
55 #endif
56 
57 
58 #if !defined(OPENNURBS_GL_INC_)
59 #define OPENNURBS_GL_INC_
60 
61 
62 // Use ON_GL( const ON_Point, ...) to render single points.
63 void ON_GL(
64  const ON_Point&
65  );
66 
67 // Use ON_GL( const ON_PointCloud, ...) to render Rhino point sets.
68 void ON_GL(
69  const ON_PointCloud&
70  );
71 
72 // Use ON_GL( const ON_Mesh&, ...) to render OpenNURBS meshes.
73 void ON_GL(
74  const ON_Mesh&
75  );
76 
77 // Use ON_GL( const ON_Brep&, ...) to render OpenNURBS b-reps.
78 void ON_GL(
79  const ON_Brep&,
80  GLUnurbsObj*
81  );
82 
83 // must be bracketed by calls to glBegin(GL_POINTS) / glEnd()
84 void ON_GL(
85  const ON_3dPoint&
86  );
87 
88 void ON_GL(
89  const ON_Curve&, //
90  GLUnurbsObj*, // created with gluNewNurbsRenderer
91  GLenum = 0, // type of curve (if 0, type is automatically set)
92  double[][4] = nullptr // optional transformation applied to curve
93  );
94 
95 // must be bracketed by calls to gluBeginSurface( nobj )/gluEndSurface( nobj )
96 void ON_GL(
97  const ON_Surface&, //
98  GLUnurbsObj* // created with gluNewNurbsRenderer
99  );
100 
101 // Use ON_GL( const ON_NurbsCurve&,...) in place of
102 // gluNurbsCurve(). See your system's gluNurbsCurve() documentation
103 // for details. In particular, for 3d curves the call to
104 // ON_GL( const ON_NurbsCurve&, nobj,...) should appear inside
105 // of a gluBeginCurve( nobj )/gluEndCurve( nobj ) pair.
106 // Generally, the GL "type" should be set using the formula
107 // ON_NurbsCurve:IsRational()
108 // ? GL_MAP1_VERTEX_4
109 // : GL_MAP1_VERTEX_3;
110 void ON_GL(
111  const ON_NurbsCurve&, //
112  GLUnurbsObj*, // created with gluNewNurbsRenderer
113  GLenum = 0, // type of curve (if 0, type is automatically set)
114  int = 1, // bPermitKnotScaling - If true, curve knots may
115  // be rescaled to avoid knot vectors GL cannot handle.
116  double* = nullptr, // knot_scale[2] - If not nullptr and bPermitKnotScaling,
117  // the scaling applied to the knot vector is
118  // returned here.
119  double[][4] = nullptr // optional transformation applied to curve
120  );
121 
122 void ON_GL( // low level NURBS curve renderer
123  int, int, int, int, // dim, is_rat, cv_count, order
124  const double*, // knot_vector[]
125  int, // cv_stride
126  const double*, // cv
127  GLUnurbsObj*, // created with gluNewNurbsRenderer
128  GLenum = 0, // type of curve (if 0, type is automatically set)
129  int = 1, // bPermitKnotScaling - If true, curve knots may
130  // be rescaled to avoid knot vectors GL cannot handle.
131  double* = nullptr, // knot_scale[2] - If not nullptr and bPermitKnotScaling,
132  // the scaling applied to the knot vector is
133  // returned here.
134  double[][4] = nullptr // optional transformation applied to curve
135  );
136 
137 
138 // Use ON_GL( const ON_NurbsSurface&,...) in place of
139 // gluNurbsSurface(). See your system's gluNurbsSurface() documentation
140 // for details. In particular, the call to
141 // ON_GL( const ON_NurbsSurface&, nobj, ...) should appear inside
142 // of a gluBeginSurface( nobj )/gluEndSurface( nobj ) pair.
143 // Generally, the GL "type" should be set using the formula
144 // ON_NurbsSurface:IsRational()
145 // ? GL_MAP2_VERTEX_4
146 // : GL_MAP2_VERTEX_3;
147 void ON_GL(
148  const ON_NurbsSurface&, //
149  GLUnurbsObj*, // created with gluNewNurbsRenderer
150  GLenum = 0, // type of surface
151  // (if 0, type is automatically set)
152  int = 1, // bPermitKnotScaling - If true, surface knots may
153  // be rescaled to avoid knot vectors GL cannot handle.
154  double* = nullptr, // knot_scale0[2] - If not nullptr and bPermitKnotScaling,
155  // the scaleing applied to the first parameter is
156  // returned here.
157  double* = nullptr // knot_scale0[2] - If not nullptr and bPermitKnotScaling,
158  // the scaleing applied to the second parameter is
159  // returned here.
160  );
161 
162 
163 // Use ON_GL( const ON_BrepFace&, nobj ) to render
164 // the trimmed NURBS surface that defines a ON_Brep face's geometry.
165 // The call to ON_GL( const ON_BrepFace&, nobj ) should
166 // appear inside of a gluBeginSurface( nobj )/gluEndSurface( nobj )
167 // pair.
168 void ON_GL(
169  const ON_BrepFace&, //
170  GLUnurbsObj* // created with gluNewNurbsRenderer
171  );
172 
173 // Use ON_GL( const ON_Color ...) to set GL color to OpenNURBS color
174 void ON_GL( const ON_Color&,
175  GLfloat[4]
176  );
177 void ON_GL( const ON_Color&,
178  double, // alpha
179  GLfloat[4]
180  );
181 
182 // Use ON_GL( const ON_Material ...) to set GL material to OpenNURBS material
183 void ON_GL(
184  const ON_Material&
185  );
186 
187 void ON_GL(
188  const ON_Material* // pass nullptr to get OpenNURBS's default material
189  );
190 
191 // Use ON_GL( const ON_Light, ...) to add OpenNURBS spotlights to
192 // GL lighting model
193 void ON_GL(
194  const ON_Light*, // pass nullptr to disable the light
195  GLenum // GL_LIGHTi where 0 <= i <= GL_MAX_LIGHTS
196  // See glLight*() documentation for details
197  );
198 void ON_GL(
199  const ON_Light&,
200  GLenum // GL_LIGHTi where 0 <= i <= GL_MAX_LIGHTS
201  // See glLight*() documentation for details
202  );
203 
204 //////////////////////////////////////////////////////////////////////////
205 // Use ON_GL( ON_Viewport& ... ) to set the GL projections to match
206 // those used in the OpenNURBS viewport.
207 
208 ////////////
209 //
210 // Use ON_GL( ON_Viewport&, in, int, int, int ) to specify the size of the
211 // GL window and loads the GL projection matrix (camera to clip
212 // transformation). If the aspect ratio of the GL window and
213 // ON_Viewport's frustum do not match, the viewport's frustum is
214 // adjusted to get things back to 1:1.
215 //
216 // For systems where the upper left corner of a window has
217 // coordinates (0,0) use:
218 // port_left = 0
219 // port_right = width-1
220 // port_bottom = height-1
221 // port_top = 0
222 void ON_GL( ON_Viewport&,
223  int, int, // port_left, port_right (port_left != port_right)
224  int, int // port_bottom, port_top (port_bottom != port_top)
225  );
226 
227 ////////////
228 //
229 // Use ON_GL( ON_Viewport& ) to load the GL model view matrix (world to
230 // camera transformation).
231 void ON_GL( const ON_Viewport& );
232 
233 // Use ON_GL( order, cv_count, knot, bPermitScaling, glknot )
234 // to create knot vectors suitable for GL NURBS rendering.
235 void ON_GL(
236  const int, // order, ON_NurbsCurve... order
237  const int, // cv_count, ON_NurbsCurve... cv count
238  const double*, // knot, ON_NurbsCurve... knot vector
239  GLfloat*, // glknot[] - GL knot vector
240  int = 0, // bPermitScaling - true if re-scaling is allowed
241  double* = nullptr // scale[2] - If not nullptr and bPermitScaling is true,
242  // then the scaling parameters are returned here.
243  // ( glknot = (knot = scale[0])*scale[1] )
244  );
245 
246 #endif
Definition: opennurbs_material.h:25
Definition: opennurbs_brep.h:917
Definition: opennurbs_nurbssurface.h:62
ON_Curve is a pure virtual class for curve objects
Definition: opennurbs_curve.h:93
Definition: opennurbs_light.h:20
Definition: opennurbs_color.h:24
Definition: opennurbs_pointcloud.h:26
Definition: opennurbs_mesh.h:2188
Definition: opennurbs_brep.h:1472
Definition: opennurbs_nurbscurve.h:26
Definition: opennurbs_viewport.h:31
Definition: opennurbs_point.h:460
Definition: opennurbs_pointgeometry.h:24
Definition: opennurbs_surface.h:57