2
0

glu.pp 16 KB

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