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