2
0

glu.pp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. {
  2. $Id$
  3. Translation of the Mesa GLU headers for FreePascal
  4. Copyright (C) 1999 Sebastian Guenther
  5. Mesa 3-D graphics library
  6. Version: 3.0
  7. Copyright (C) 1995-1998 Brian Paul
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public
  10. License as published by the Free Software Foundation; either
  11. version 2 of the License, or (at your option) any later version.
  12. This library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Library General Public License for more details.
  16. You should have received a copy of the GNU Library General Public
  17. License along with this library; if not, write to the Free
  18. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. }
  20. {$MODE delphi} // objfpc would not work because of direct proc var assignments
  21. {You have to enable Macros (compiler switch "-Sm") for compiling this unit!
  22. This is necessary for supporting different platforms with different calling
  23. conventions via a single unit.}
  24. unit GLU;
  25. interface
  26. {$MACRO ON}
  27. {$IFDEF Linux}
  28. uses GL;
  29. {$ELSE}
  30. {$MESSAGE Unsupported platform.}
  31. {$ENDIF}
  32. // =======================================================
  33. // Unit specific extensions
  34. // =======================================================
  35. function InitGLUFromLibrary(libname: PChar): Boolean;
  36. // determines automatically which libraries to use:
  37. function InitGLU: Boolean;
  38. var
  39. GLUDumpUnresolvedFunctions,
  40. GLUInitialized: Boolean;
  41. // =======================================================
  42. // GLU consts, types and functions
  43. // =======================================================
  44. const
  45. GLU_TRUE = GL_TRUE;
  46. GLU_FALSE = GL_FALSE;
  47. // Normal vectors
  48. GLU_SMOOTH = 100000;
  49. GLU_FLAT = 100001;
  50. GLU_NONE = 100002;
  51. // Quadric draw styles
  52. GLU_POINT = 100010;
  53. GLU_LINE = 100011;
  54. GLU_FILL = 100012;
  55. GLU_SILHOUETTE = 100013;
  56. // Quadric orientation
  57. GLU_OUTSIDE = 100020;
  58. GLU_INSIDE = 100021;
  59. // Tesselator
  60. GLU_BEGIN = 100100;
  61. GLU_VERTEX = 100101;
  62. GLU_END = 100102;
  63. GLU_ERROR = 100103;
  64. GLU_EDGE_FLAG = 100104;
  65. // Contour types
  66. GLU_CW = 100120;
  67. GLU_CCW = 100121;
  68. GLU_INTERIOR = 100122;
  69. GLU_EXTERIOR = 100123;
  70. GLU_UNKNOWN = 100124;
  71. // Tesselation errors
  72. GLU_TESS_ERROR1 = 100151; // missing gluEndPolygon
  73. GLU_TESS_ERROR2 = 100152; // missing gluBeginPolygon
  74. GLU_TESS_ERROR3 = 100153; // misoriented contour
  75. GLU_TESS_ERROR4 = 100154; // vertex/edge intersection
  76. GLU_TESS_ERROR5 = 100155; // misoriented or self-intersecting loops
  77. GLU_TESS_ERROR6 = 100156; // coincident vertices
  78. GLU_TESS_ERROR7 = 100157; // all vertices collinear
  79. GLU_TESS_ERROR8 = 100158; // intersecting edges
  80. GLU_TESS_ERROR9 = 100159; // not coplanar contours
  81. // NURBS
  82. GLU_AUTO_LOAD_MATRIX = 100200;
  83. GLU_CULLING = 100201;
  84. GLU_PARAMETRIC_TOLERANCE = 100202;
  85. GLU_SAMPLING_TOLERANCE = 100203;
  86. GLU_DISPLAY_MODE = 100204;
  87. GLU_SAMPLING_METHOD = 100205;
  88. GLU_U_STEP = 100206;
  89. GLU_V_STEP = 100207;
  90. GLU_PATH_LENGTH = 100215;
  91. GLU_PARAMETRIC_ERROR = 100216;
  92. GLU_DOMAIN_DISTANCE = 100217;
  93. GLU_MAP1_TRIM_2 = 100210;
  94. GLU_MAP1_TRIM_3 = 100211;
  95. GLU_OUTLINE_POLYGON = 100240;
  96. GLU_OUTLINE_PATCH = 100241;
  97. GLU_NURBS_ERROR1 = 100251; // spline order un-supported
  98. GLU_NURBS_ERROR2 = 100252; // too few knots
  99. GLU_NURBS_ERROR3 = 100253; // valid knot range is empty
  100. GLU_NURBS_ERROR4 = 100254; // decreasing knot sequence
  101. GLU_NURBS_ERROR5 = 100255; // knot multiplicity > spline order
  102. GLU_NURBS_ERROR6 = 100256; // endcurve() must follow bgncurve()
  103. GLU_NURBS_ERROR7 = 100257; // bgncurve() must precede endcurve()
  104. GLU_NURBS_ERROR8 = 100258; // ctrlarray or knot vector is NULL
  105. GLU_NURBS_ERROR9 = 100259; // cannot draw pwlcurves
  106. GLU_NURBS_ERROR10 = 100260; // missing gluNurbsCurve()
  107. GLU_NURBS_ERROR11 = 100261; // missing gluNurbsSurface()
  108. GLU_NURBS_ERROR12 = 100262; // endtrim() must precede endsurface()
  109. GLU_NURBS_ERROR13 = 100263; // bgnsurface() must precede endsurface()
  110. GLU_NURBS_ERROR14 = 100264; // curve of improper type passed as trim curve
  111. GLU_NURBS_ERROR15 = 100265; // bgnsurface() must precede bgntrim()
  112. GLU_NURBS_ERROR16 = 100266; // endtrim() must follow bgntrim()
  113. GLU_NURBS_ERROR17 = 100267; // bgntrim() must precede endtrim()*/
  114. GLU_NURBS_ERROR18 = 100268; // invalid or missing trim curve*/
  115. GLU_NURBS_ERROR19 = 100269; // bgntrim() must precede pwlcurve()
  116. GLU_NURBS_ERROR20 = 100270; // pwlcurve referenced twice*/
  117. GLU_NURBS_ERROR21 = 100271; // pwlcurve and nurbscurve mixed
  118. GLU_NURBS_ERROR22 = 100272; // improper usage of trim data type
  119. GLU_NURBS_ERROR23 = 100273; // nurbscurve referenced twice
  120. GLU_NURBS_ERROR24 = 100274; // nurbscurve and pwlcurve mixed
  121. GLU_NURBS_ERROR25 = 100275; // nurbssurface referenced twice
  122. GLU_NURBS_ERROR26 = 100276; // invalid property
  123. GLU_NURBS_ERROR27 = 100277; // endsurface() must follow bgnsurface()
  124. GLU_NURBS_ERROR28 = 100278; // intersecting or misoriented trim curves
  125. GLU_NURBS_ERROR29 = 100279; // intersecting trim curves
  126. GLU_NURBS_ERROR30 = 100280; // UNUSED
  127. GLU_NURBS_ERROR31 = 100281; // unconnected trim curves
  128. GLU_NURBS_ERROR32 = 100282; // unknown knot error
  129. GLU_NURBS_ERROR33 = 100283; // negative vertex count encountered
  130. GLU_NURBS_ERROR34 = 100284; // negative byte-stride
  131. GLU_NURBS_ERROR35 = 100285; // unknown type descriptor
  132. GLU_NURBS_ERROR36 = 100286; // null control point reference
  133. GLU_NURBS_ERROR37 = 100287; // duplicate point on pwlcurve
  134. // Errors
  135. GLU_INVALID_ENUM = 100900;
  136. GLU_INVALID_VALUE = 100901;
  137. GLU_OUT_OF_MEMORY = 100902;
  138. GLU_INCOMPATIBLE_GL_VERSION = 100903;
  139. // New in GLU 1.1
  140. GLU_VERSION = 100800;
  141. GLU_EXTENSIONS = 100801;
  142. type
  143. PGLUquadricObj = ^TGLUquadricObj;
  144. TGLUquadricObj = record end;
  145. PGLUtriangulatorObj = ^TGLUtriangulatorObj;
  146. TGLUtriangulatorObj = record end;
  147. PGLUnurbsObj = ^TGLUnurbsObj;
  148. TGLUnurbsObj = record end;
  149. TGLUQuadricCallback = procedure; cdecl;
  150. TGLUNurbsCallback = procedure; cdecl;
  151. TGLUTessCallback = procedure; cdecl;
  152. TGLUViewport = array[0..3] of LongInt;
  153. TGLUMatrixd = array[0..15] of Double;
  154. TGLUMatrixf = array[0..15] of Single;
  155. TGLUVectord = array[0..2] of Double;
  156. var
  157. // Miscellaneous functions
  158. gluLookAt: procedure(eye, eyey, eyez, centerx, centery, centerz, upx, upy, upz: Double); cdecl;
  159. gluOrtho2D: procedure(left, right, bottom, top: Double); cdecl;
  160. gluPerspective: procedure(fovy, aspect, zNear, zFar: Double); cdecl;
  161. gluPickMatrix: procedure(x, y, width, height: Double; const viewport: TGLUViewport); cdecl;
  162. gluProject: procedure(objx, objy, objz: Double; const modelMatrix, projMatrix: TGLUMatrixd; const viewport: TGLUViewport; winx, winy, winz: Double); cdecl;
  163. gluUnProject: procedure(winx, winy, winz: Double; const modelMatrix, projMatrix: TGLUMatrixd; const viewport: TGLUViewport; objx, objy, objz: Double); cdecl;
  164. gluErrorString: procedure(errorCode: GLenum); cdecl;
  165. // Mipmapping and image scaling
  166. gluScaleImage: procedure(format: GLenum; within, heightin: LongInt; typein: GLenum; var datain; widthout, heightout: LongInt; typeout: GLenum; var dataout); cdecl;
  167. gluBuild1DMipmaps: procedure(target: GLenum; components, width: LongInt; format, AType: GLEnum; var data); cdecl;
  168. gluBuild2DMipmaps: procedure(target: GLenum; components, width, height: LongInt; format, AType: GLEnum; var data); cdecl;
  169. // Quadrics
  170. gluNewQuadric: function: PGLUquadricObj; cdecl;
  171. gluDeleteQuadric: procedure(state: PGLUquadricObj); cdecl;
  172. gluQuadricDrawStyle: procedure(quadObject: PGLUquadricObj; drawStyle: GLenum); cdecl;
  173. gluQuadricOrientation: procedure(quadObject: PGLUquadricObj; orientation: GLenum); cdecl;
  174. gluQuadricNormals: procedure(quadObject: PGLUquadricObj; normals: GLenum); cdecl;
  175. gluQuadricTexture: procedure(quadObject: PGLUquadricObj; textureCoords: Boolean); cdecl;
  176. gluQuadricCallback: procedure(quadObject: PGLUquadricObj; which: GLenum; fn: TGLUQuadricCallback); cdecl;
  177. gluCylinder: procedure(qobj: PGLUquadricObj; baseRadius, topRadius, height: Double; slices, stacks: LongInt); cdecl;
  178. gluSphere: procedure(qobj: PGLUquadricObj; radius: Double; slices, stacks: LongInt); cdecl;
  179. gluDisk: procedure(qobj: PGLUquadricObj; innerRadius, outerRadius: Double; slices, loops: LongInt); cdecl;
  180. gluPartialDisk: procedure(qobj: PGLUquadricObj; innerRadius, outerRadius: Double; slices, loops: LongInt; startAngle, sweepAngle: Double); cdecl;
  181. // Nurbs
  182. gluNewNurbsRenderer: function: PGLUnurbsObj; cdecl;
  183. gluDeleteNurbsRenderer: procedure(nobj: PGLUnurbsObj); cdecl;
  184. gluLoadSamplingMatrices: procedure(nobj: PGLUnurbsObj; const modelMatrix, projMatrix: TGLUMatrixf; const viewport: TGLUViewport); cdecl;
  185. gluNurbsProperty: procedure(nobj: PGLUnurbsObj; AProperty: GLenum; value: Single); cdecl;
  186. gluGetNurbsProperty: procedure(nobj: PGLUnurbsObj; AProperty: GLEnum; var value: Single); cdecl;
  187. gluBeginCurve: procedure(nobj: PGLUnurbsObj); cdecl;
  188. gluEndCurve: procedure(nobj: PGLUnurbsObj); cdecl;
  189. gluNurbsCurve: procedure(nobj: PGLUnurbsObj; nknots: LongInt; var know: Single; stride: LongInt; var ctlarray: Single; order: LongInt; AType: GLenum); cdecl;
  190. gluBeginSurface: procedure(nobj: PGLUnurbsObj); cdecl;
  191. gluEndSurface: procedure(nobj: PGLUnurbsObj); cdecl;
  192. gluNurbsSurface: procedure(nobj: PGLUnurbsObj; sknot_count: LongInt; var sknot: Single; tknot_count: LongInt; var tknot: Single; s_stride, t_stride: LongInt; var ctlarray: Single; sorder, torder: LongInt; AType: GLenum); cdecl;
  193. gluBeginTrim: procedure(nobj: PGLUnurbsObj); cdecl;
  194. gluEndTrim: procedure(nobj: PGLUnurbsObj); cdecl;
  195. gluPwlCurve: procedure(nobj: PGLUnurbsObj; count: LongInt; var AArray: Single; stride: LongInt; AType: GLenum); cdecl;
  196. gluNurbsCallback: procedure(nobj: PGLUnurbsObj; which: GLenum; fn: TGLUNurbsCallback); cdecl;
  197. // Polygon tesselation
  198. gluNewTess: function: PGLUtriangulatorObj; cdecl;
  199. gluTessCallback: procedure(tobj: PGLUtriangulatorObj; which: GLenum; fn: TGLUTessCallback); cdecl;
  200. gluDeleteTess: procedure(tobj: PGLUtriangulatorObj); cdecl;
  201. gluBeginPolygon: procedure(tobj: PGLUtriangulatorObj); cdecl;
  202. gluEndPolygon: procedure(tobj: PGLUtriangulatorObj); cdecl;
  203. gluNextContour: procedure(tobj: PGLUtriangulatorObj; AType: GLenum); cdecl;
  204. gluTessVertex: procedure(tobj: PGLUtriangulatorObj; v: TGLUVectord; var data); cdecl;
  205. // New functions in GLU 1.1
  206. gluGetString: function(name: GLenum): PChar; cdecl;
  207. // =======================================================
  208. //
  209. // =======================================================
  210. implementation
  211. {$LINKLIB m}
  212. function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
  213. function dlclose(handle: Pointer): LongInt; external 'dl';
  214. function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
  215. function LoadLibrary(name: PChar): Pointer;
  216. begin
  217. Result := dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY});
  218. end;
  219. function GetProc(handle: Pointer; name: PChar): Pointer;
  220. begin
  221. Result := dlsym(handle, name);
  222. if (Result = nil) and GLUDumpUnresolvedFunctions then
  223. WriteLn('Unresolved: ', name);
  224. end;
  225. var
  226. libGLU : Pointer;
  227. function InitGLUFromLibrary(libname: PChar): Boolean;
  228. begin
  229. Result := False;
  230. libGLU := LoadLibrary(libname);
  231. if not Assigned(libGLU) then exit;
  232. // Miscellaneous functions
  233. gluLookAt := GetProc(libglu, 'gluLookAt');
  234. gluOrtho2D := GetProc(libglu, 'gluOrtho2D');
  235. gluPerspective := GetProc(libglu, 'gluPerspective');
  236. gluPickMatrix := GetProc(libglu, 'gluPickMatrix');
  237. gluProject := GetProc(libglu, 'gluProject');
  238. gluUnProject := GetProc(libglu, 'gluUnProject');
  239. gluErrorString := GetProc(libglu, 'gluErrorString');
  240. // Mipmapping and image scaling
  241. gluScaleImage := GetProc(libglu, 'gluScaleImage');
  242. gluBuild1DMipmaps := GetProc(libglu, 'gluBuild1DMipmaps');
  243. gluBuild2DMipmaps := GetProc(libglu, 'gluBuild2DMipmaps');
  244. // Quadrics
  245. gluNewQuadric := GetProc(libglu, 'gluNewQuadric');
  246. gluDeleteQuadric := GetProc(libglu, 'gluDeleteQuadric');
  247. gluQuadricDrawStyle := GetProc(libglu, 'gluQuadricDrawStyle');
  248. gluQuadricOrientation := GetProc(libglu, 'gluQuadricOrientation');
  249. gluQuadricNormals := GetProc(libglu, 'gluQuadricNormals');
  250. gluQuadricTexture := GetProc(libglu, 'gluQuadricTexture');
  251. gluQuadricCallback := GetProc(libglu, 'gluQuadricCallback');
  252. gluCylinder := GetProc(libglu, 'gluCylinder');
  253. gluSphere := GetProc(libglu, 'gluSphere');
  254. gluDisk := GetProc(libglu, 'gluDisk');
  255. gluPartialDisk := GetProc(libglu, 'gluPartialDisk');
  256. // Nurbs
  257. gluNewNurbsRenderer := GetProc(libglu, 'gluNewNurbsRenderer');
  258. gluDeleteNurbsRenderer := GetProc(libglu, 'gluDeleteNurbsRenderer');
  259. gluLoadSamplingMatrices := GetProc(libglu, 'gluLoadSamplingMatrices');
  260. gluNurbsProperty := GetProc(libglu, 'gluNurbsProperty');
  261. gluGetNurbsProperty := GetProc(libglu, 'gluGetNurbsProperty');
  262. gluBeginCurve := GetProc(libglu, 'gluBeginCurve');
  263. gluEndCurve := GetProc(libglu, 'gluEndCurve');
  264. gluNurbsCurve := GetProc(libglu, 'gluNurbsCurve');
  265. gluBeginSurface := GetProc(libglu, 'gluBeginSurface');
  266. gluEndSurface := GetProc(libglu, 'gluEndSurface');
  267. gluNurbsSurface := GetProc(libglu, 'gluNurbsSurface');
  268. gluBeginTrim := GetProc(libglu, 'gluBeginTrim');
  269. gluEndTrim := GetProc(libglu, 'gluEndTrim');
  270. gluPwlCurve := GetProc(libglu, 'gluPwlCurve');
  271. gluNurbsCallback := GetProc(libglu, 'gluNurbsCallback');
  272. // Polygon tesselation
  273. gluNewTess := GetProc(libglu, 'gluNewTess');
  274. gluTessCallback := GetProc(libglu, 'gluTessCallback');
  275. gluDeleteTess := GetProc(libglu, 'gluDeleteTess');
  276. gluBeginPolygon := GetProc(libglu, 'gluBeginPolygon');
  277. gluEndPolygon := GetProc(libglu, 'gluEndPolygon');
  278. gluNextContour := GetProc(libglu, 'gluNextContour');
  279. gluTessVertex := GetProc(libglu, 'gluTessVertex');
  280. // New functions in GLU 1.1
  281. gluGetString := GetProc(libglu, 'gluGetString');
  282. GLUInitialized := True;
  283. Result := True;
  284. end;
  285. function InitGLU: Boolean;
  286. begin
  287. Result := InitGLUFromLibrary('libGLU.so') or
  288. InitGLUFromLibrary('libGLU.so.1') or
  289. InitGLUFromLibrary('libMesaGLU.so') or
  290. InitGLUFromLibrary('libMesaGLU.so.3');
  291. end;
  292. initialization
  293. InitGlU;
  294. finalization
  295. if Assigned(libGLU) then dlclose(libGLU);
  296. end.
  297. {
  298. $Log$
  299. Revision 1.2 2000-10-01 22:17:59 peter
  300. * new bounce demo
  301. Revision 1.1.2.1 2000/10/01 22:12:28 peter
  302. * new demo
  303. Revision 1.1 2000/07/13 06:34:18 michael
  304. + Initial import
  305. Revision 1.1 2000/05/31 00:35:14 alex
  306. added working templates
  307. }
  308. {
  309. $Log$
  310. Revision 1.2 2000-10-01 22:17:59 peter
  311. * new bounce demo
  312. Revision 1.1.2.1 2000/10/01 22:12:28 peter
  313. * new demo
  314. }