PageRenderTime 36ms CodeModel.GetById 15ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/support/chicken/glu/glu.scm

http://github.com/dharmatech/abstracting
Scheme | 355 lines | 309 code | 38 blank | 8 comment | 0 complexity | 3d5810562086c5e5c8c5080c44f020ed MD5 | raw file
  1;;;; glu.scm
  2
  3(use easyffi)
  4
  5(cond-expand
  6 (msvc
  7  #>
  8  #define WIN32_LEAN_AND_MEAN 1
  9  #include <windows.h>
 10  #include <GL/glu.h>
 11  <#)
 12 (else
 13  #>
 14  #ifdef C_MACOSX
 15  #include <OpenGL/glu.h>
 16  #else
 17  #include <GL/glu.h>
 18  #endif
 19  <#))
 20
 21(foreign-parse #<<EOF
 22
 23___declare(export_constants, yes)
 24
 25/* ___declare(substitute, "^(GLU_|glu);glu:") */
 26
 27typedef unsigned int	GLenum;
 28typedef unsigned char	GLboolean;
 29typedef unsigned int	GLbitfield;
 30typedef void		GLvoid;
 31typedef ___byte	GLbyte;		/* 1-byte signed */
 32typedef short		GLshort;	/* 2-byte signed */
 33typedef int		GLint;		/* 4-byte signed */
 34typedef unsigned ___byte	GLubyte;	/* 1-byte unsigned */
 35typedef unsigned short	GLushort;	/* 2-byte unsigned */
 36typedef unsigned int	GLuint;		/* 4-byte unsigned */
 37typedef int		GLsizei;	/* 4-byte signed */
 38typedef float		GLfloat;	/* single precision float */
 39typedef float		GLclampf;	/* single precision float in [0,1] */
 40typedef double		GLdouble;	/* double precision float */
 41typedef double		GLclampd;	/* double precision float in [0,1] */
 42
 43/* Boolean */
 44#define GLU_FALSE                          0
 45#define GLU_TRUE                           1
 46
 47/* StringName */
 48#define GLU_VERSION                        100800
 49#define GLU_EXTENSIONS                     100801
 50
 51/* ErrorCode */
 52#define GLU_INVALID_ENUM                   100900
 53#define GLU_INVALID_VALUE                  100901
 54#define GLU_OUT_OF_MEMORY                  100902
 55#define GLU_INVALID_OPERATION              100904
 56
 57/* NurbsDisplay */
 58/*      GLU_FILL */
 59#define GLU_OUTLINE_POLYGON                100240
 60#define GLU_OUTLINE_PATCH                  100241
 61
 62/* NurbsCallback */
 63#define GLU_NURBS_ERROR                    100103
 64#define GLU_ERROR                          100103
 65#define GLU_NURBS_BEGIN                    100164
 66#define GLU_NURBS_BEGIN_EXT                100164
 67#define GLU_NURBS_VERTEX                   100165
 68#define GLU_NURBS_VERTEX_EXT               100165
 69#define GLU_NURBS_NORMAL                   100166
 70#define GLU_NURBS_NORMAL_EXT               100166
 71#define GLU_NURBS_COLOR                    100167
 72#define GLU_NURBS_COLOR_EXT                100167
 73#define GLU_NURBS_TEXTURE_COORD            100168
 74#define GLU_NURBS_TEX_COORD_EXT            100168
 75#define GLU_NURBS_END                      100169
 76#define GLU_NURBS_END_EXT                  100169
 77#define GLU_NURBS_BEGIN_DATA               100170
 78#define GLU_NURBS_BEGIN_DATA_EXT           100170
 79#define GLU_NURBS_VERTEX_DATA              100171
 80#define GLU_NURBS_VERTEX_DATA_EXT          100171
 81#define GLU_NURBS_NORMAL_DATA              100172
 82#define GLU_NURBS_NORMAL_DATA_EXT          100172
 83#define GLU_NURBS_COLOR_DATA               100173
 84#define GLU_NURBS_COLOR_DATA_EXT           100173
 85#define GLU_NURBS_TEXTURE_COORD_DATA       100174
 86#define GLU_NURBS_TEX_COORD_DATA_EXT       100174
 87#define GLU_NURBS_END_DATA                 100175
 88#define GLU_NURBS_END_DATA_EXT             100175
 89
 90/* NurbsError */
 91#define GLU_NURBS_ERROR1                   100251
 92#define GLU_NURBS_ERROR2                   100252
 93#define GLU_NURBS_ERROR3                   100253
 94#define GLU_NURBS_ERROR4                   100254
 95#define GLU_NURBS_ERROR5                   100255
 96#define GLU_NURBS_ERROR6                   100256
 97#define GLU_NURBS_ERROR7                   100257
 98#define GLU_NURBS_ERROR8                   100258
 99#define GLU_NURBS_ERROR9                   100259
100#define GLU_NURBS_ERROR10                  100260
101#define GLU_NURBS_ERROR11                  100261
102#define GLU_NURBS_ERROR12                  100262
103#define GLU_NURBS_ERROR13                  100263
104#define GLU_NURBS_ERROR14                  100264
105#define GLU_NURBS_ERROR15                  100265
106#define GLU_NURBS_ERROR16                  100266
107#define GLU_NURBS_ERROR17                  100267
108#define GLU_NURBS_ERROR18                  100268
109#define GLU_NURBS_ERROR19                  100269
110#define GLU_NURBS_ERROR20                  100270
111#define GLU_NURBS_ERROR21                  100271
112#define GLU_NURBS_ERROR22                  100272
113#define GLU_NURBS_ERROR23                  100273
114#define GLU_NURBS_ERROR24                  100274
115#define GLU_NURBS_ERROR25                  100275
116#define GLU_NURBS_ERROR26                  100276
117#define GLU_NURBS_ERROR27                  100277
118#define GLU_NURBS_ERROR28                  100278
119#define GLU_NURBS_ERROR29                  100279
120#define GLU_NURBS_ERROR30                  100280
121#define GLU_NURBS_ERROR31                  100281
122#define GLU_NURBS_ERROR32                  100282
123#define GLU_NURBS_ERROR33                  100283
124#define GLU_NURBS_ERROR34                  100284
125#define GLU_NURBS_ERROR35                  100285
126#define GLU_NURBS_ERROR36                  100286
127#define GLU_NURBS_ERROR37                  100287
128
129/* NurbsProperty */
130#define GLU_AUTO_LOAD_MATRIX               100200
131#define GLU_CULLING                        100201
132#define GLU_SAMPLING_TOLERANCE             100203
133#define GLU_DISPLAY_MODE                   100204
134#define GLU_PARAMETRIC_TOLERANCE           100202
135#define GLU_SAMPLING_METHOD                100205
136#define GLU_U_STEP                         100206
137#define GLU_V_STEP                         100207
138#define GLU_NURBS_MODE                     100160
139#define GLU_NURBS_MODE_EXT                 100160
140#define GLU_NURBS_TESSELLATOR              100161
141#define GLU_NURBS_TESSELLATOR_EXT          100161
142#define GLU_NURBS_RENDERER                 100162
143#define GLU_NURBS_RENDERER_EXT             100162
144
145/* NurbsSampling */
146#define GLU_OBJECT_PARAMETRIC_ERROR        100208
147#define GLU_OBJECT_PARAMETRIC_ERROR_EXT    100208
148#define GLU_OBJECT_PATH_LENGTH             100209
149#define GLU_OBJECT_PATH_LENGTH_EXT         100209
150#define GLU_PATH_LENGTH                    100215
151#define GLU_PARAMETRIC_ERROR               100216
152#define GLU_DOMAIN_DISTANCE                100217
153
154/* NurbsTrim */
155#define GLU_MAP1_TRIM_2                    100210
156#define GLU_MAP1_TRIM_3                    100211
157
158/* QuadricDrawStyle */
159#define GLU_POINT                          100010
160#define GLU_LINE                           100011
161#define GLU_FILL                           100012
162#define GLU_SILHOUETTE                     100013
163
164/* QuadricCallback */
165/*      GLU_ERROR */
166
167/* QuadricNormal */
168#define GLU_SMOOTH                         100000
169#define GLU_FLAT                           100001
170#define GLU_NONE                           100002
171
172/* QuadricOrientation */
173#define GLU_OUTSIDE                        100020
174#define GLU_INSIDE                         100021
175
176/* TessCallback */
177#define GLU_TESS_BEGIN                     100100
178#define GLU_BEGIN                          100100
179#define GLU_TESS_VERTEX                    100101
180#define GLU_VERTEX                         100101
181#define GLU_TESS_END                       100102
182#define GLU_END                            100102
183#define GLU_TESS_ERROR                     100103
184#define GLU_TESS_EDGE_FLAG                 100104
185#define GLU_EDGE_FLAG                      100104
186#define GLU_TESS_COMBINE                   100105
187#define GLU_TESS_BEGIN_DATA                100106
188#define GLU_TESS_VERTEX_DATA               100107
189#define GLU_TESS_END_DATA                  100108
190#define GLU_TESS_ERROR_DATA                100109
191#define GLU_TESS_EDGE_FLAG_DATA            100110
192#define GLU_TESS_COMBINE_DATA              100111
193
194/* TessContour */
195#define GLU_CW                             100120
196#define GLU_CCW                            100121
197#define GLU_INTERIOR                       100122
198#define GLU_EXTERIOR                       100123
199#define GLU_UNKNOWN                        100124
200
201/* TessProperty */
202#define GLU_TESS_WINDING_RULE              100140
203#define GLU_TESS_BOUNDARY_ONLY             100141
204#define GLU_TESS_TOLERANCE                 100142
205
206/* TessError */
207#define GLU_TESS_ERROR1                    100151
208#define GLU_TESS_ERROR2                    100152
209#define GLU_TESS_ERROR3                    100153
210#define GLU_TESS_ERROR4                    100154
211#define GLU_TESS_ERROR5                    100155
212#define GLU_TESS_ERROR6                    100156
213#define GLU_TESS_ERROR7                    100157
214#define GLU_TESS_ERROR8                    100158
215#define GLU_TESS_MISSING_BEGIN_POLYGON     100151
216#define GLU_TESS_MISSING_BEGIN_CONTOUR     100152
217#define GLU_TESS_MISSING_END_POLYGON       100153
218#define GLU_TESS_MISSING_END_CONTOUR       100154
219#define GLU_TESS_COORD_TOO_LARGE           100155
220#define GLU_TESS_NEED_COMBINE_CALLBACK     100156
221
222/* TessWinding */
223#define GLU_TESS_WINDING_ODD               100130
224#define GLU_TESS_WINDING_NONZERO           100131
225#define GLU_TESS_WINDING_POSITIVE          100132
226#define GLU_TESS_WINDING_NEGATIVE          100133
227#define GLU_TESS_WINDING_ABS_GEQ_TWO       100134
228
229/*************************************************************/
230
231
232typedef struct GLUnurbs GLUnurbs;
233typedef struct GLUquadric GLUquadric;
234typedef struct GLUtesselator GLUtesselator;
235
236#define GLU_TESS_MAX_COORD 1.0e+150
237
238/* Internal convenience typedefs */
239
240 void  gluBeginCurve (GLUnurbs* nurb);
241 void  gluBeginPolygon (GLUtesselator* tess);
242 void  gluBeginSurface (GLUnurbs* nurb);
243 void  gluBeginTrim (GLUnurbs* nurb);
244 
245 GLint  gluBuild1DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void *data);
246 GLint  gluBuild2DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data);
247
248 void  gluCylinder (GLUquadric* quad, GLdouble base, GLdouble top, GLdouble height, GLint slices, GLint stacks);
249 void  gluDeleteNurbsRenderer (GLUnurbs* nurb);
250 void  gluDeleteQuadric (GLUquadric* quad);
251 void  gluDeleteTess (GLUtesselator* tess);
252 void  gluDisk (GLUquadric* quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops);
253 void  gluEndCurve (GLUnurbs* nurb);
254 void  gluEndPolygon (GLUtesselator* tess);
255 void  gluEndSurface (GLUnurbs* nurb);
256 void  gluEndTrim (GLUnurbs* nurb);
257 char *  gluErrorString (GLenum err);
258 void  gluGetNurbsProperty (GLUnurbs* nurb, GLenum property, GLfloat* data);
259 char *  gluGetString (GLenum name);
260 void  gluGetTessProperty (GLUtesselator* tess, GLenum which, GLdouble* data);
261 void  gluLoadSamplingMatrices (GLUnurbs* nurb, const GLfloat *model, const GLfloat *perspective, const GLint *view);
262 void  gluLookAt (GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ);
263 GLUnurbs*  gluNewNurbsRenderer (void);
264 GLUquadric*  gluNewQuadric (void);
265 GLUtesselator*  gluNewTess (void);
266 void  gluNextContour (GLUtesselator* tess, GLenum type);
267
268 void  gluNurbsCurve (GLUnurbs* nurb, GLint knotCount, GLfloat *knots, GLint stride, GLfloat *control, GLint order, GLenum type);
269 void  gluNurbsProperty (GLUnurbs* nurb, GLenum property, GLfloat value);
270 void  gluNurbsSurface (GLUnurbs* nurb, GLint sKnotCount, GLfloat* sKnots, GLint tKnotCount, GLfloat* tKnots, GLint sStride, GLint tStride, GLfloat* control, GLint sOrder, GLint tOrder, GLenum type);
271 void  gluOrtho2D (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top);
272 void  gluPartialDisk (GLUquadric* quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops, GLdouble start, GLdouble sweep);
273 void  gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
274 void  gluPickMatrix (GLdouble x, GLdouble y, GLdouble delX, GLdouble delY, GLint *viewport);
275 GLint  gluProject (GLdouble objX, GLdouble objY, GLdouble objZ, const GLdouble *model, const GLdouble *proj, const GLint *view, GLdouble* winX, GLdouble* winY, GLdouble* winZ);
276 void  gluPwlCurve (GLUnurbs* nurb, GLint count, GLfloat* data, GLint stride, GLenum type);
277 void  gluQuadricDrawStyle (GLUquadric* quad, GLenum draw);
278 void  gluQuadricNormals (GLUquadric* quad, GLenum normal);
279 void  gluQuadricOrientation (GLUquadric* quad, GLenum orientation);
280 void  gluQuadricTexture (GLUquadric* quad, GLboolean texture);
281 GLint  gluScaleImage (GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void *dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid* dataOut);
282 void  gluSphere (GLUquadric* quad, GLdouble radius, GLint slices, GLint stacks);
283 void  gluTessBeginContour (GLUtesselator* tess);
284 void  gluTessBeginPolygon (GLUtesselator* tess, GLvoid* data);
285 void  gluTessEndContour (GLUtesselator* tess);
286___safe void  gluTessEndPolygon (GLUtesselator* tess);
287 void  gluTessNormal (GLUtesselator* tess, GLdouble valueX, GLdouble valueY, GLdouble valueZ);
288 void  gluTessProperty (GLUtesselator* tess, GLenum which, GLdouble data);
289 void  gluTessVertex (GLUtesselator* tess, GLdouble *location, GLvoid* data);
290 GLint  gluUnProject (GLdouble winX, GLdouble winY, GLdouble winZ, const GLdouble *model, const GLdouble *proj, const GLint *view, GLdouble* objX, GLdouble* objY, GLdouble* objZ);
291
292EOF
293)
294
295; The GLU that ships with windows is still version 1.2, so I moved all GLU 1.3 functions here.
296(cond-expand
297 (msvc)
298 (cygwin)
299 (else
300  (foreign-parse #<<EOF
301  GLint  gluBuild1DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data);
302   GLint  gluBuild2DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data);
303    GLint  gluBuild3DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data);
304     GLint  gluBuild3DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data);
305 GLboolean  gluCheckExtension (const char *extName, const char *extString);
306 void  gluNurbsCallbackData (GLUnurbs* nurb, GLvoid* userData);
307 void  gluNurbsCallbackDataEXT (GLUnurbs* nurb, GLvoid* userData);
308 GLint  gluUnProject4 (GLdouble winX, GLdouble winY, GLdouble winZ, GLdouble clipW, const GLdouble *model, const GLdouble *proj, const GLint *view, GLdouble nearVal, GLdouble farVal, GLdouble* objX, GLdouble* objY, GLdouble* objZ, GLdouble* objW);
309EOF
310)))
311
312(declare (hide nurbs-func nurbs_cb quadric-func quadric_cb tess-func tess_cb))
313
314(define nurbs-func #f)
315(define quadric-func #f)
316(define tess-func #f)
317
318; The callback passed to gluTess/gluQuadric/gluNurbsCallback must be __stdcall in windows.  Defining the
319; external functions (nurbs_cb, quadric_cb, tess_cb) as __stdcall is done below; however, I couldn't figure
320; out how to get the Easy FFI parser to handle a __stdcall function pointer.  With foreign-safe-lambda,
321; I can specify a calling convention with the function type, but the MSVC compiler doesn't like where
322; chicken puts the __stdcall in the function pointer casts.  To get around this, I created the wrapper
323; functions used below.
324(cond-expand
325 (msvc
326  #>
327  void chicken_wrap_gluTessCallback(GLUtesselator* tess, GLenum which) { gluTessCallback(tess, which, tess_cb); }
328  void chicken_wrap_gluQuadricCallback(GLUquadric* quad, GLenum which) { gluQuadricCallback(quad, which, quadric_cb); }
329  void chicken_wrap_gluNurbsCallback(GLUnurbs* nurb, GLenum which) { gluNurbsCallback(nurb, which, nurbs_cb); }
330  <#
331  (foreign-parse #<<EOF
332  void chicken_wrap_gluNurbsCallback(GLUnurbs* nurb, GLenum which);
333  void chicken_wrap_gluQuadricCallback(GLUquadric* quad, GLenum which);
334  void chicken_wrap_gluNurbsCallback(GLUnurbs* nurb, GLenum which);
335EOF
336)
337  (define-external "__stdcall" (nurbs_cb) void (nurbs-func))
338  (define-external "__stdcall" (quadric_cb) void (quadric-func))
339  (define-external "__stdcall" (tess_cb) void (tess-func))
340  (define (gluNurbsCallback p i proc) (chicken_wrap_gluNurbsCallback p i) (set! nurbs-func proc))
341  (define (gluQuadricCallback p i proc) (chicken_wrap_gluQuadricCallback p i) (set! quadric-func proc))
342  (define (gluTessCallback p i proc) (chicken_wrap_gluTessCallback p i) (set! tess-func proc)))
343 (else
344  (foreign-parse #<<EOF
345  void  gluTessCallback (GLUtesselator* tess, GLenum which, void (*CallBackFunc)());
346  void  gluQuadricCallback (GLUquadric* quad, GLenum which, void (*CallBackFunc)());
347  void  gluNurbsCallback (GLUnurbs* nurb, GLenum which, void (*CallBackFunc)());
348EOF
349)
350  (define-external (nurbs_cb) void (nurbs-func))
351  (define-external (quadric_cb) void (quadric-func))
352  (define-external (tess_cb) void (tess-func))
353  (define gluNurbsCallback (let ([old gluNurbsCallback]) (lambda (p i proc) (old p i (location nurbs_cb)) (set! nurbs-func proc))))
354  (define gluQuadricCallback (let ([old gluQuadricCallback]) (lambda (p i proc) (old p i (location quadric_cb)) (set! quadric-func proc))))
355  (define gluTessCallback (let ([old gluTessCallback]) (lambda (p i proc) (old p i (location tess_cb)) (set! tess-func proc))))))