glut.pp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. {
  2. Adaption of the delphi3d.net OpenGL units to FreePascal
  3. Sebastian Guenther ([email protected]) in 2002
  4. These units are free to use
  5. }
  6. {$MACRO ON}
  7. {$MODE Delphi}
  8. {$IFDEF Windows}
  9. {$DEFINE extdecl := stdcall}
  10. {$ELSE}
  11. {$DEFINE extdecl := cdecl}
  12. {$ENDIF}
  13. {$IFDEF MORPHOS}
  14. {$INLINE ON}
  15. {$DEFINE GLUT_UNIT}
  16. {$ENDIF}
  17. unit Glut;
  18. // Copyright (c) Mark J. Kilgard, 1994, 1995, 1996. */
  19. (* This program is freely distributable without licensing fees and is
  20. provided without guarantee or warrantee expressed or implied. This
  21. program is -not- in the public domain. *)
  22. {******************************************************************************}
  23. { Converted to Delphi by Tom Nuydens ([email protected]) }
  24. { Contributions by Igor Karpov ([email protected]) }
  25. { For the latest updates, visit Delphi3D: http://www.delphi3d.net }
  26. {******************************************************************************}
  27. interface
  28. uses
  29. SysUtils,
  30. {$IFDEF Windows}
  31. Windows, dynlibs,
  32. {$ELSE}
  33. {$IFDEF MORPHOS}
  34. TinyGL,
  35. {$ELSE}
  36. dynlibs,
  37. {$ENDIF}
  38. {$ENDIF}
  39. GL;
  40. type
  41. TGlutVoidCallback = procedure; cdecl;
  42. TGlut1IntCallback = procedure(value: Integer); cdecl;
  43. TGlut2IntCallback = procedure(v1, v2: Integer); cdecl;
  44. TGlut3IntCallback = procedure(v1, v2, v3: Integer); cdecl;
  45. TGlut4IntCallback = procedure(v1, v2, v3, v4: Integer); cdecl;
  46. TGlut1Char2IntCallback = procedure(c: Byte; v1, v2: Integer); cdecl;
  47. TGlut1UInt3IntCallback = procedure(u: Cardinal; v1, v2, v3: Integer); cdecl;
  48. const
  49. GLUT_API_VERSION = 3;
  50. GLUT_XLIB_IMPLEMENTATION = 12;
  51. // Display mode bit masks.
  52. GLUT_RGB = 0;
  53. GLUT_RGBA = GLUT_RGB;
  54. GLUT_INDEX = 1;
  55. GLUT_SINGLE = 0;
  56. GLUT_DOUBLE = 2;
  57. GLUT_ACCUM = 4;
  58. GLUT_ALPHA = 8;
  59. GLUT_DEPTH = 16;
  60. GLUT_STENCIL = 32;
  61. GLUT_MULTISAMPLE = 128;
  62. GLUT_STEREO = 256;
  63. GLUT_LUMINANCE = 512;
  64. // Mouse buttons.
  65. GLUT_LEFT_BUTTON = 0;
  66. GLUT_MIDDLE_BUTTON = 1;
  67. GLUT_RIGHT_BUTTON = 2;
  68. // Mouse button state.
  69. GLUT_DOWN = 0;
  70. GLUT_UP = 1;
  71. // function keys
  72. GLUT_KEY_F1 = 1;
  73. GLUT_KEY_F2 = 2;
  74. GLUT_KEY_F3 = 3;
  75. GLUT_KEY_F4 = 4;
  76. GLUT_KEY_F5 = 5;
  77. GLUT_KEY_F6 = 6;
  78. GLUT_KEY_F7 = 7;
  79. GLUT_KEY_F8 = 8;
  80. GLUT_KEY_F9 = 9;
  81. GLUT_KEY_F10 = 10;
  82. GLUT_KEY_F11 = 11;
  83. GLUT_KEY_F12 = 12;
  84. // directional keys
  85. GLUT_KEY_LEFT = 100;
  86. GLUT_KEY_UP = 101;
  87. GLUT_KEY_RIGHT = 102;
  88. GLUT_KEY_DOWN = 103;
  89. GLUT_KEY_PAGE_UP = 104;
  90. GLUT_KEY_PAGE_DOWN = 105;
  91. GLUT_KEY_HOME = 106;
  92. GLUT_KEY_END = 107;
  93. GLUT_KEY_INSERT = 108;
  94. // Entry/exit state.
  95. GLUT_LEFT = 0;
  96. GLUT_ENTERED = 1;
  97. // Menu usage state.
  98. GLUT_MENU_NOT_IN_USE = 0;
  99. GLUT_MENU_IN_USE = 1;
  100. // Visibility state.
  101. GLUT_NOT_VISIBLE = 0;
  102. GLUT_VISIBLE = 1;
  103. // Window status state.
  104. GLUT_HIDDEN = 0;
  105. GLUT_FULLY_RETAINED = 1;
  106. GLUT_PARTIALLY_RETAINED = 2;
  107. GLUT_FULLY_COVERED = 3;
  108. // Color index component selection values.
  109. GLUT_RED = 0;
  110. GLUT_GREEN = 1;
  111. GLUT_BLUE = 2;
  112. // Layers for use.
  113. GLUT_NORMAL = 0;
  114. GLUT_OVERLAY = 1;
  115. {$ifdef Windows}
  116. // Stroke font constants (use these in GLUT program).
  117. GLUT_STROKE_ROMAN = Pointer(0);
  118. GLUT_STROKE_MONO_ROMAN = Pointer(1);
  119. // Bitmap font constants (use these in GLUT program).
  120. GLUT_BITMAP_9_BY_15 = Pointer(2);
  121. GLUT_BITMAP_8_BY_13 = Pointer(3);
  122. GLUT_BITMAP_TIMES_ROMAN_10 = Pointer(4);
  123. GLUT_BITMAP_TIMES_ROMAN_24 = Pointer(5);
  124. GLUT_BITMAP_HELVETICA_10 = Pointer(6);
  125. GLUT_BITMAP_HELVETICA_12 = Pointer(7);
  126. GLUT_BITMAP_HELVETICA_18 = Pointer(8);
  127. {$else Windows}
  128. var
  129. // Stroke font constants (use these in GLUT program).
  130. GLUT_STROKE_ROMAN : Pointer;
  131. GLUT_STROKE_MONO_ROMAN : Pointer;
  132. // Bitmap font constants (use these in GLUT program).
  133. GLUT_BITMAP_9_BY_15 : Pointer;
  134. GLUT_BITMAP_8_BY_13 : Pointer;
  135. GLUT_BITMAP_TIMES_ROMAN_10 : Pointer;
  136. GLUT_BITMAP_TIMES_ROMAN_24 : Pointer;
  137. GLUT_BITMAP_HELVETICA_10 : Pointer;
  138. GLUT_BITMAP_HELVETICA_12 : Pointer;
  139. GLUT_BITMAP_HELVETICA_18 : Pointer;
  140. const
  141. {$endif Windows}
  142. // glutGet parameters.
  143. GLUT_WINDOW_X = 100;
  144. GLUT_WINDOW_Y = 101;
  145. GLUT_WINDOW_WIDTH = 102;
  146. GLUT_WINDOW_HEIGHT = 103;
  147. GLUT_WINDOW_BUFFER_SIZE = 104;
  148. GLUT_WINDOW_STENCIL_SIZE = 105;
  149. GLUT_WINDOW_DEPTH_SIZE = 106;
  150. GLUT_WINDOW_RED_SIZE = 107;
  151. GLUT_WINDOW_GREEN_SIZE = 108;
  152. GLUT_WINDOW_BLUE_SIZE = 109;
  153. GLUT_WINDOW_ALPHA_SIZE = 110;
  154. GLUT_WINDOW_ACCUM_RED_SIZE = 111;
  155. GLUT_WINDOW_ACCUM_GREEN_SIZE = 112;
  156. GLUT_WINDOW_ACCUM_BLUE_SIZE = 113;
  157. GLUT_WINDOW_ACCUM_ALPHA_SIZE = 114;
  158. GLUT_WINDOW_DOUBLEBUFFER = 115;
  159. GLUT_WINDOW_RGBA = 116;
  160. GLUT_WINDOW_PARENT = 117;
  161. GLUT_WINDOW_NUM_CHILDREN = 118;
  162. GLUT_WINDOW_COLORMAP_SIZE = 119;
  163. GLUT_WINDOW_NUM_SAMPLES = 120;
  164. GLUT_WINDOW_STEREO = 121;
  165. GLUT_WINDOW_CURSOR = 122;
  166. GLUT_SCREEN_WIDTH = 200;
  167. GLUT_SCREEN_HEIGHT = 201;
  168. GLUT_SCREEN_WIDTH_MM = 202;
  169. GLUT_SCREEN_HEIGHT_MM = 203;
  170. GLUT_MENU_NUM_ITEMS = 300;
  171. GLUT_DISPLAY_MODE_POSSIBLE = 400;
  172. GLUT_INIT_WINDOW_X = 500;
  173. GLUT_INIT_WINDOW_Y = 501;
  174. GLUT_INIT_WINDOW_WIDTH = 502;
  175. GLUT_INIT_WINDOW_HEIGHT = 503;
  176. GLUT_INIT_DISPLAY_MODE = 504;
  177. GLUT_ELAPSED_TIME = 700;
  178. GLUT_WINDOW_FORMAT_ID = 123;
  179. // glutDeviceGet parameters.
  180. GLUT_HAS_KEYBOARD = 600;
  181. GLUT_HAS_MOUSE = 601;
  182. GLUT_HAS_SPACEBALL = 602;
  183. GLUT_HAS_DIAL_AND_BUTTON_BOX = 603;
  184. GLUT_HAS_TABLET = 604;
  185. GLUT_NUM_MOUSE_BUTTONS = 605;
  186. GLUT_NUM_SPACEBALL_BUTTONS = 606;
  187. GLUT_NUM_BUTTON_BOX_BUTTONS = 607;
  188. GLUT_NUM_DIALS = 608;
  189. GLUT_NUM_TABLET_BUTTONS = 609;
  190. GLUT_DEVICE_IGNORE_KEY_REPEAT = 610;
  191. GLUT_DEVICE_KEY_REPEAT = 611;
  192. GLUT_HAS_JOYSTICK = 612;
  193. GLUT_OWNS_JOYSTICK = 613;
  194. GLUT_JOYSTICK_BUTTONS = 614;
  195. GLUT_JOYSTICK_AXES = 615;
  196. GLUT_JOYSTICK_POLL_RATE = 616;
  197. // glutLayerGet parameters.
  198. GLUT_OVERLAY_POSSIBLE = 800;
  199. GLUT_LAYER_IN_USE = 801;
  200. GLUT_HAS_OVERLAY = 802;
  201. GLUT_TRANSPARENT_INDEX = 803;
  202. GLUT_NORMAL_DAMAGED = 804;
  203. GLUT_OVERLAY_DAMAGED = 805;
  204. // glutVideoResizeGet parameters.
  205. GLUT_VIDEO_RESIZE_POSSIBLE = 900;
  206. GLUT_VIDEO_RESIZE_IN_USE = 901;
  207. GLUT_VIDEO_RESIZE_X_DELTA = 902;
  208. GLUT_VIDEO_RESIZE_Y_DELTA = 903;
  209. GLUT_VIDEO_RESIZE_WIDTH_DELTA = 904;
  210. GLUT_VIDEO_RESIZE_HEIGHT_DELTA = 905;
  211. GLUT_VIDEO_RESIZE_X = 906;
  212. GLUT_VIDEO_RESIZE_Y = 907;
  213. GLUT_VIDEO_RESIZE_WIDTH = 908;
  214. GLUT_VIDEO_RESIZE_HEIGHT = 909;
  215. // glutGetModifiers return mask.
  216. GLUT_ACTIVE_SHIFT = 1;
  217. GLUT_ACTIVE_CTRL = 2;
  218. GLUT_ACTIVE_ALT = 4;
  219. // glutSetCursor parameters.
  220. // Basic arrows.
  221. GLUT_CURSOR_RIGHT_ARROW = 0;
  222. GLUT_CURSOR_LEFT_ARROW = 1;
  223. // Symbolic cursor shapes.
  224. GLUT_CURSOR_INFO = 2;
  225. GLUT_CURSOR_DESTROY = 3;
  226. GLUT_CURSOR_HELP = 4;
  227. GLUT_CURSOR_CYCLE = 5;
  228. GLUT_CURSOR_SPRAY = 6;
  229. GLUT_CURSOR_WAIT = 7;
  230. GLUT_CURSOR_TEXT = 8;
  231. GLUT_CURSOR_CROSSHAIR = 9;
  232. // Directional cursors.
  233. GLUT_CURSOR_UP_DOWN = 10;
  234. GLUT_CURSOR_LEFT_RIGHT = 11;
  235. // Sizing cursors.
  236. GLUT_CURSOR_TOP_SIDE = 12;
  237. GLUT_CURSOR_BOTTOM_SIDE = 13;
  238. GLUT_CURSOR_LEFT_SIDE = 14;
  239. GLUT_CURSOR_RIGHT_SIDE = 15;
  240. GLUT_CURSOR_TOP_LEFT_CORNER = 16;
  241. GLUT_CURSOR_TOP_RIGHT_CORNER = 17;
  242. GLUT_CURSOR_BOTTOM_RIGHT_CORNER = 18;
  243. GLUT_CURSOR_BOTTOM_LEFT_CORNER = 19;
  244. // Inherit from parent window.
  245. GLUT_CURSOR_INHERIT = 100;
  246. // Blank cursor.
  247. GLUT_CURSOR_NONE = 101;
  248. // Fullscreen crosshair (if available).
  249. GLUT_CURSOR_FULL_CROSSHAIR = 102;
  250. // GLUT device control sub-API.
  251. // glutSetKeyRepeat modes.
  252. GLUT_KEY_REPEAT_OFF = 0;
  253. GLUT_KEY_REPEAT_ON = 1;
  254. GLUT_KEY_REPEAT_DEFAULT = 2;
  255. // Joystick button masks.
  256. GLUT_JOYSTICK_BUTTON_A = 1;
  257. GLUT_JOYSTICK_BUTTON_B = 2;
  258. GLUT_JOYSTICK_BUTTON_C = 4;
  259. GLUT_JOYSTICK_BUTTON_D = 8;
  260. // GLUT game mode sub-API.
  261. // glutGameModeGet.
  262. GLUT_GAME_MODE_ACTIVE = 0;
  263. GLUT_GAME_MODE_POSSIBLE = 1;
  264. GLUT_GAME_MODE_WIDTH = 2;
  265. GLUT_GAME_MODE_HEIGHT = 3;
  266. GLUT_GAME_MODE_PIXEL_DEPTH = 4;
  267. GLUT_GAME_MODE_REFRESH_RATE = 5;
  268. GLUT_GAME_MODE_DISPLAY_CHANGED = 6;
  269. {$IFDEF MORPHOS}
  270. { MorphOS GL works differently due to different dynamic-library handling on Amiga-like }
  271. { systems, so its headers are included here. }
  272. {$INCLUDE tinyglh.inc}
  273. {$ELSE MORPHOS}
  274. var
  275. // GLUT initialization sub-API.
  276. glutInit: procedure(argcp: PInteger; argv: PPAnsiChar); extdecl;
  277. glutInitDisplayMode: procedure(mode: Cardinal); extdecl;
  278. glutInitDisplayString: procedure(const str: PAnsiChar); extdecl;
  279. glutInitWindowPosition: procedure(x, y: Integer); extdecl;
  280. glutInitWindowSize: procedure(width, height: Integer); extdecl;
  281. glutMainLoop: procedure; extdecl;
  282. // GLUT window sub-API.
  283. glutCreateWindow: function(const title: PAnsiChar): Integer; extdecl;
  284. glutCreateSubWindow: function(win, x, y, width, height: Integer): Integer; extdecl;
  285. glutDestroyWindow: procedure(win: Integer); extdecl;
  286. glutPostRedisplay: procedure; extdecl;
  287. glutPostWindowRedisplay: procedure(win: Integer); extdecl;
  288. glutSwapBuffers: procedure; extdecl;
  289. glutGetWindow: function: Integer; extdecl;
  290. glutSetWindow: procedure(win: Integer); extdecl;
  291. glutSetWindowTitle: procedure(const title: PAnsiChar); extdecl;
  292. glutSetIconTitle: procedure(const title: PAnsiChar); extdecl;
  293. glutPositionWindow: procedure(x, y: Integer); extdecl;
  294. glutReshapeWindow: procedure(width, height: Integer); extdecl;
  295. glutPopWindow: procedure; extdecl;
  296. glutPushWindow: procedure; extdecl;
  297. glutIconifyWindow: procedure; extdecl;
  298. glutShowWindow: procedure; extdecl;
  299. glutHideWindow: procedure; extdecl;
  300. glutFullScreen: procedure; extdecl;
  301. glutSetCursor: procedure(cursor: Integer); extdecl;
  302. glutWarpPointer: procedure(x, y: Integer); extdecl;
  303. // GLUT overlay sub-API.
  304. glutEstablishOverlay: procedure; extdecl;
  305. glutRemoveOverlay: procedure; extdecl;
  306. glutUseLayer: procedure(layer: GLenum); extdecl;
  307. glutPostOverlayRedisplay: procedure; extdecl;
  308. glutPostWindowOverlayRedisplay: procedure(win: Integer); extdecl;
  309. glutShowOverlay: procedure; extdecl;
  310. glutHideOverlay: procedure; extdecl;
  311. // GLUT menu sub-API.
  312. glutCreateMenu: function(callback: TGlut1IntCallback): Integer; extdecl;
  313. glutDestroyMenu: procedure(menu: Integer); extdecl;
  314. glutGetMenu: function: Integer; extdecl;
  315. glutSetMenu: procedure(menu: Integer); extdecl;
  316. glutAddMenuEntry: procedure(const caption: PAnsiChar; value: Integer); extdecl;
  317. glutAddSubMenu: procedure(const caption: PAnsiChar; submenu: Integer); extdecl;
  318. glutChangeToMenuEntry: procedure(item: Integer; const caption: PAnsiChar; value: Integer); extdecl;
  319. glutChangeToSubMenu: procedure(item: Integer; const caption: PAnsiChar; submenu: Integer); extdecl;
  320. glutRemoveMenuItem: procedure(item: Integer); extdecl;
  321. glutAttachMenu: procedure(button: Integer); extdecl;
  322. glutDetachMenu: procedure(button: Integer); extdecl;
  323. // GLUT window callback sub-API.
  324. glutDisplayFunc: procedure(f: TGlutVoidCallback); extdecl;
  325. glutReshapeFunc: procedure(f: TGlut2IntCallback); extdecl;
  326. glutKeyboardFunc: procedure(f: TGlut1Char2IntCallback); extdecl;
  327. glutMouseFunc: procedure(f: TGlut4IntCallback); extdecl;
  328. glutMotionFunc: procedure(f: TGlut2IntCallback); extdecl;
  329. glutPassiveMotionFunc: procedure(f: TGlut2IntCallback); extdecl;
  330. glutEntryFunc: procedure(f: TGlut1IntCallback); extdecl;
  331. glutVisibilityFunc: procedure(f: TGlut1IntCallback); extdecl;
  332. glutIdleFunc: procedure(f: TGlutVoidCallback); extdecl;
  333. glutTimerFunc: procedure(millis: Cardinal; f: TGlut1IntCallback; value: Integer); extdecl;
  334. glutMenuStateFunc: procedure(f: TGlut1IntCallback); extdecl;
  335. glutSpecialFunc: procedure(f: TGlut3IntCallback); extdecl;
  336. glutSpaceballMotionFunc: procedure(f: TGlut3IntCallback); extdecl;
  337. glutSpaceballRotateFunc: procedure(f: TGlut3IntCallback); extdecl;
  338. glutSpaceballButtonFunc: procedure(f: TGlut2IntCallback); extdecl;
  339. glutButtonBoxFunc: procedure(f: TGlut2IntCallback); extdecl;
  340. glutDialsFunc: procedure(f: TGlut2IntCallback); extdecl;
  341. glutTabletMotionFunc: procedure(f: TGlut2IntCallback); extdecl;
  342. glutTabletButtonFunc: procedure(f: TGlut4IntCallback); extdecl;
  343. glutMenuStatusFunc: procedure(f: TGlut3IntCallback); extdecl;
  344. glutOverlayDisplayFunc: procedure(f:TGlutVoidCallback); extdecl;
  345. glutWindowStatusFunc: procedure(f: TGlut1IntCallback); extdecl;
  346. glutKeyboardUpFunc: procedure(f: TGlut1Char2IntCallback); extdecl;
  347. glutSpecialUpFunc: procedure(f: TGlut3IntCallback); extdecl;
  348. glutJoystickFunc: procedure(f: TGlut1UInt3IntCallback; pollInterval: Integer); extdecl;
  349. // GLUT color index sub-API.
  350. glutSetColor: procedure(cell: Integer; red, green, blue: GLfloat); extdecl;
  351. glutGetColor: function(ndx, component: Integer): GLfloat; extdecl;
  352. glutCopyColormap: procedure(win: Integer); extdecl;
  353. // GLUT state retrieval sub-API.
  354. glutGet: function(t: GLenum): Integer; extdecl;
  355. glutDeviceGet: function(t: GLenum): Integer; extdecl;
  356. // GLUT extension support sub-API
  357. glutExtensionSupported: function(const name: PAnsiChar): Integer; extdecl;
  358. glutGetModifiers: function: Integer; extdecl;
  359. glutLayerGet: function(t: GLenum): Integer; extdecl;
  360. // GLUT font sub-API
  361. glutBitmapCharacter: procedure(font : pointer; character: Integer); extdecl;
  362. glutBitmapWidth: function(font : pointer; character: Integer): Integer; extdecl;
  363. glutStrokeCharacter: procedure(font : pointer; character: Integer); extdecl;
  364. glutStrokeWidth: function(font : pointer; character: Integer): Integer; extdecl;
  365. glutBitmapLength: function(font: pointer; const str: PAnsiChar): Integer; extdecl;
  366. glutStrokeLength: function(font: pointer; const str: PAnsiChar): Integer; extdecl;
  367. // GLUT pre-built models sub-API
  368. glutWireSphere: procedure(radius: GLdouble; slices, stacks: GLint); extdecl;
  369. glutSolidSphere: procedure(radius: GLdouble; slices, stacks: GLint); extdecl;
  370. glutWireCone: procedure(base, height: GLdouble; slices, stacks: GLint); extdecl;
  371. glutSolidCone: procedure(base, height: GLdouble; slices, stacks: GLint); extdecl;
  372. glutWireCube: procedure(size: GLdouble); extdecl;
  373. glutSolidCube: procedure(size: GLdouble); extdecl;
  374. glutWireTorus: procedure(innerRadius, outerRadius: GLdouble; sides, rings: GLint); extdecl;
  375. glutSolidTorus: procedure(innerRadius, outerRadius: GLdouble; sides, rings: GLint); extdecl;
  376. glutWireDodecahedron: procedure; extdecl;
  377. glutSolidDodecahedron: procedure; extdecl;
  378. glutWireTeapot: procedure(size: GLdouble); extdecl;
  379. glutSolidTeapot: procedure(size: GLdouble); extdecl;
  380. glutWireOctahedron: procedure; extdecl;
  381. glutSolidOctahedron: procedure; extdecl;
  382. glutWireTetrahedron: procedure; extdecl;
  383. glutSolidTetrahedron: procedure; extdecl;
  384. glutWireIcosahedron: procedure; extdecl;
  385. glutSolidIcosahedron: procedure; extdecl;
  386. // GLUT video resize sub-API.
  387. glutVideoResizeGet: function(param: GLenum): Integer; extdecl;
  388. glutSetupVideoResizing: procedure; extdecl;
  389. glutStopVideoResizing: procedure; extdecl;
  390. glutVideoResize: procedure(x, y, width, height: Integer); extdecl;
  391. glutVideoPan: procedure(x, y, width, height: Integer); extdecl;
  392. // GLUT debugging sub-API.
  393. glutReportErrors: procedure; extdecl;
  394. // GLUT device control sub-API.
  395. glutIgnoreKeyRepeat: procedure(ignore: Integer); extdecl;
  396. glutSetKeyRepeat: procedure(repeatMode: Integer); extdecl;
  397. glutForceJoystickFunc: procedure; extdecl;
  398. // GLUT game mode sub-API.
  399. //example glutGameModeString('1280x1024:32@75');
  400. glutGameModeString : procedure (const AString : PAnsiChar); extdecl;
  401. glutEnterGameMode : function : integer; extdecl;
  402. glutLeaveGameMode : procedure; extdecl;
  403. glutGameModeGet : function (mode : GLenum) : integer; extdecl;
  404. {$ENDIF MORPHOS}
  405. procedure LoadGlut(const dll: String);
  406. procedure UnloadGlut;
  407. implementation
  408. {$IFDEF MORPHOS}
  409. { MorphOS GL works differently due to different dynamic-library handling on Amiga-like }
  410. { systems, so its functions are included here. }
  411. {$INCLUDE tinygl.inc}
  412. {$ELSE MORPHOS}
  413. uses FreeGlut;
  414. var
  415. hDLL: TLibHandle;
  416. {$ENDIF MORPHOS}
  417. procedure UnloadGlut;
  418. begin
  419. {$IFDEF MORPHOS}
  420. // MorphOS's GL will closed down by TinyGL unit, nothing is needed here.
  421. {$ELSE MORPHOS}
  422. if (hDLL <> 0) then
  423. FreeLibrary(hDLL);
  424. @glutInit := nil;
  425. @glutInitDisplayMode := nil;
  426. @glutInitDisplayString := nil;
  427. @glutInitWindowPosition := nil;
  428. @glutInitWindowSize := nil;
  429. @glutMainLoop := nil;
  430. @glutCreateWindow := nil;
  431. @glutCreateSubWindow := nil;
  432. @glutDestroyWindow := nil;
  433. @glutPostRedisplay := nil;
  434. @glutPostWindowRedisplay := nil;
  435. @glutSwapBuffers := nil;
  436. @glutGetWindow := nil;
  437. @glutSetWindow := nil;
  438. @glutSetWindowTitle := nil;
  439. @glutSetIconTitle := nil;
  440. @glutPositionWindow := nil;
  441. @glutReshapeWindow := nil;
  442. @glutPopWindow := nil;
  443. @glutPushWindow := nil;
  444. @glutIconifyWindow := nil;
  445. @glutShowWindow := nil;
  446. @glutHideWindow := nil;
  447. @glutFullScreen := nil;
  448. @glutSetCursor := nil;
  449. @glutWarpPointer := nil;
  450. @glutEstablishOverlay := nil;
  451. @glutRemoveOverlay := nil;
  452. @glutUseLayer := nil;
  453. @glutPostOverlayRedisplay := nil;
  454. @glutPostWindowOverlayRedisplay := nil;
  455. @glutShowOverlay := nil;
  456. @glutHideOverlay := nil;
  457. @glutCreateMenu := nil;
  458. @glutDestroyMenu := nil;
  459. @glutGetMenu := nil;
  460. @glutSetMenu := nil;
  461. @glutAddMenuEntry := nil;
  462. @glutAddSubMenu := nil;
  463. @glutChangeToMenuEntry := nil;
  464. @glutChangeToSubMenu := nil;
  465. @glutRemoveMenuItem := nil;
  466. @glutAttachMenu := nil;
  467. @glutDetachMenu := nil;
  468. @glutDisplayFunc := nil;
  469. @glutReshapeFunc := nil;
  470. @glutKeyboardFunc := nil;
  471. @glutMouseFunc := nil;
  472. @glutMotionFunc := nil;
  473. @glutPassiveMotionFunc := nil;
  474. @glutEntryFunc := nil;
  475. @glutVisibilityFunc := nil;
  476. @glutIdleFunc := nil;
  477. @glutTimerFunc := nil;
  478. @glutMenuStateFunc := nil;
  479. @glutSpecialFunc := nil;
  480. @glutSpaceballMotionFunc := nil;
  481. @glutSpaceballRotateFunc := nil;
  482. @glutSpaceballButtonFunc := nil;
  483. @glutButtonBoxFunc := nil;
  484. @glutDialsFunc := nil;
  485. @glutTabletMotionFunc := nil;
  486. @glutTabletButtonFunc := nil;
  487. @glutMenuStatusFunc := nil;
  488. @glutOverlayDisplayFunc := nil;
  489. @glutWindowStatusFunc := nil;
  490. @glutKeyboardUpFunc := nil;
  491. @glutSpecialUpFunc := nil;
  492. @glutJoystickFunc := nil;
  493. @glutSetColor := nil;
  494. @glutGetColor := nil;
  495. @glutCopyColormap := nil;
  496. @glutGet := nil;
  497. @glutDeviceGet := nil;
  498. @glutExtensionSupported := nil;
  499. @glutGetModifiers := nil;
  500. @glutLayerGet := nil;
  501. @glutBitmapCharacter := nil;
  502. @glutBitmapWidth := nil;
  503. @glutStrokeCharacter := nil;
  504. @glutStrokeWidth := nil;
  505. @glutBitmapLength := nil;
  506. @glutStrokeLength := nil;
  507. @glutWireSphere := nil;
  508. @glutSolidSphere := nil;
  509. @glutWireCone := nil;
  510. @glutSolidCone := nil;
  511. @glutWireCube := nil;
  512. @glutSolidCube := nil;
  513. @glutWireTorus := nil;
  514. @glutSolidTorus := nil;
  515. @glutWireDodecahedron := nil;
  516. @glutSolidDodecahedron := nil;
  517. @glutWireTeapot := nil;
  518. @glutSolidTeapot := nil;
  519. @glutWireOctahedron := nil;
  520. @glutSolidOctahedron := nil;
  521. @glutWireTetrahedron := nil;
  522. @glutSolidTetrahedron := nil;
  523. @glutWireIcosahedron := nil;
  524. @glutSolidIcosahedron := nil;
  525. @glutVideoResizeGet := nil;
  526. @glutSetupVideoResizing := nil;
  527. @glutStopVideoResizing := nil;
  528. @glutVideoResize := nil;
  529. @glutVideoPan := nil;
  530. @glutReportErrors := nil;
  531. @glutIgnoreKeyRepeat := nil;
  532. @glutSetKeyRepeat := nil;
  533. @glutForceJoystickFunc := nil;
  534. @glutGameModeString := nil;
  535. @glutEnterGameMode := nil;
  536. @glutLeaveGameMode := nil;
  537. @glutGameModeGet := nil;
  538. UnloadFreeGlut;
  539. {$ENDIF MORPHOS}
  540. end;
  541. procedure LoadGlut(const dll: String);
  542. {$IFDEF MORPHOS}
  543. begin
  544. // MorphOS's GL has own initialization in TinyGL unit, nothing is needed here.
  545. end;
  546. {$ELSE MORPHOS}
  547. var
  548. MethodName: string = '';
  549. function GetGLutProcAddress(Lib: PtrInt; ProcName: PAnsiChar): Pointer;
  550. begin
  551. MethodName:=ProcName;
  552. Result:=GetProcAddress(Lib, ProcName);
  553. end;
  554. begin
  555. UnloadGlut;
  556. hDLL := LoadLibrary(PAnsiChar(dll));
  557. if hDLL = 0 then raise Exception.Create('Could not load Glut from ' + dll);
  558. try
  559. @glutInit := GetGLutProcAddress(hDLL, 'glutInit');
  560. @glutInitDisplayMode := GetGLutProcAddress(hDLL, 'glutInitDisplayMode');
  561. @glutInitDisplayString := GetGLutProcAddress(hDLL, 'glutInitDisplayString');
  562. @glutInitWindowPosition := GetGLutProcAddress(hDLL, 'glutInitWindowPosition');
  563. @glutInitWindowSize := GetGLutProcAddress(hDLL, 'glutInitWindowSize');
  564. @glutMainLoop := GetGLutProcAddress(hDLL, 'glutMainLoop');
  565. @glutCreateWindow := GetGLutProcAddress(hDLL, 'glutCreateWindow');
  566. @glutCreateSubWindow := GetGLutProcAddress(hDLL, 'glutCreateSubWindow');
  567. @glutDestroyWindow := GetGLutProcAddress(hDLL, 'glutDestroyWindow');
  568. @glutPostRedisplay := GetGLutProcAddress(hDLL, 'glutPostRedisplay');
  569. @glutPostWindowRedisplay := GetGLutProcAddress(hDLL, 'glutPostWindowRedisplay');
  570. @glutSwapBuffers := GetGLutProcAddress(hDLL, 'glutSwapBuffers');
  571. @glutGetWindow := GetGLutProcAddress(hDLL, 'glutGetWindow');
  572. @glutSetWindow := GetGLutProcAddress(hDLL, 'glutSetWindow');
  573. @glutSetWindowTitle := GetGLutProcAddress(hDLL, 'glutSetWindowTitle');
  574. @glutSetIconTitle := GetGLutProcAddress(hDLL, 'glutSetIconTitle');
  575. @glutPositionWindow := GetGLutProcAddress(hDLL, 'glutPositionWindow');
  576. @glutReshapeWindow := GetGLutProcAddress(hDLL, 'glutReshapeWindow');
  577. @glutPopWindow := GetGLutProcAddress(hDLL, 'glutPopWindow');
  578. @glutPushWindow := GetGLutProcAddress(hDLL, 'glutPushWindow');
  579. @glutIconifyWindow := GetGLutProcAddress(hDLL, 'glutIconifyWindow');
  580. @glutShowWindow := GetGLutProcAddress(hDLL, 'glutShowWindow');
  581. @glutHideWindow := GetGLutProcAddress(hDLL, 'glutHideWindow');
  582. @glutFullScreen := GetGLutProcAddress(hDLL, 'glutFullScreen');
  583. @glutSetCursor := GetGLutProcAddress(hDLL, 'glutSetCursor');
  584. @glutWarpPointer := GetGLutProcAddress(hDLL, 'glutWarpPointer');
  585. @glutEstablishOverlay := GetGLutProcAddress(hDLL, 'glutEstablishOverlay');
  586. @glutRemoveOverlay := GetGLutProcAddress(hDLL, 'glutRemoveOverlay');
  587. @glutUseLayer := GetGLutProcAddress(hDLL, 'glutUseLayer');
  588. @glutPostOverlayRedisplay := GetGLutProcAddress(hDLL, 'glutPostOverlayRedisplay');
  589. @glutPostWindowOverlayRedisplay := GetGLutProcAddress(hDLL, 'glutPostWindowOverlayRedisplay');
  590. @glutShowOverlay := GetGLutProcAddress(hDLL, 'glutShowOverlay');
  591. @glutHideOverlay := GetGLutProcAddress(hDLL, 'glutHideOverlay');
  592. @glutCreateMenu := GetGLutProcAddress(hDLL, 'glutCreateMenu');
  593. @glutDestroyMenu := GetGLutProcAddress(hDLL, 'glutDestroyMenu');
  594. @glutGetMenu := GetGLutProcAddress(hDLL, 'glutGetMenu');
  595. @glutSetMenu := GetGLutProcAddress(hDLL, 'glutSetMenu');
  596. @glutAddMenuEntry := GetGLutProcAddress(hDLL, 'glutAddMenuEntry');
  597. @glutAddSubMenu := GetGLutProcAddress(hDLL, 'glutAddSubMenu');
  598. @glutChangeToMenuEntry := GetGLutProcAddress(hDLL, 'glutChangeToMenuEntry');
  599. @glutChangeToSubMenu := GetGLutProcAddress(hDLL, 'glutChangeToSubMenu');
  600. @glutRemoveMenuItem := GetGLutProcAddress(hDLL, 'glutRemoveMenuItem');
  601. @glutAttachMenu := GetGLutProcAddress(hDLL, 'glutAttachMenu');
  602. @glutDetachMenu := GetGLutProcAddress(hDLL, 'glutDetachMenu');
  603. @glutDisplayFunc := GetGLutProcAddress(hDLL, 'glutDisplayFunc');
  604. @glutReshapeFunc := GetGLutProcAddress(hDLL, 'glutReshapeFunc');
  605. @glutKeyboardFunc := GetGLutProcAddress(hDLL, 'glutKeyboardFunc');
  606. @glutMouseFunc := GetGLutProcAddress(hDLL, 'glutMouseFunc');
  607. @glutMotionFunc := GetGLutProcAddress(hDLL, 'glutMotionFunc');
  608. @glutPassiveMotionFunc := GetGLutProcAddress(hDLL, 'glutPassiveMotionFunc');
  609. @glutEntryFunc := GetGLutProcAddress(hDLL, 'glutEntryFunc');
  610. @glutVisibilityFunc := GetGLutProcAddress(hDLL, 'glutVisibilityFunc');
  611. @glutIdleFunc := GetGLutProcAddress(hDLL, 'glutIdleFunc');
  612. @glutTimerFunc := GetGLutProcAddress(hDLL, 'glutTimerFunc');
  613. @glutMenuStateFunc := GetGLutProcAddress(hDLL, 'glutMenuStateFunc');
  614. @glutSpecialFunc := GetGLutProcAddress(hDLL, 'glutSpecialFunc');
  615. @glutSpaceballMotionFunc := GetGLutProcAddress(hDLL, 'glutSpaceballMotionFunc');
  616. @glutSpaceballRotateFunc := GetGLutProcAddress(hDLL, 'glutSpaceballRotateFunc');
  617. @glutSpaceballButtonFunc := GetGLutProcAddress(hDLL, 'glutSpaceballButtonFunc');
  618. @glutButtonBoxFunc := GetGLutProcAddress(hDLL, 'glutButtonBoxFunc');
  619. @glutDialsFunc := GetGLutProcAddress(hDLL, 'glutDialsFunc');
  620. @glutTabletMotionFunc := GetGLutProcAddress(hDLL, 'glutTabletMotionFunc');
  621. @glutTabletButtonFunc := GetGLutProcAddress(hDLL, 'glutTabletButtonFunc');
  622. @glutMenuStatusFunc := GetGLutProcAddress(hDLL, 'glutMenuStatusFunc');
  623. @glutOverlayDisplayFunc := GetGLutProcAddress(hDLL, 'glutOverlayDisplayFunc');
  624. @glutWindowStatusFunc := GetGLutProcAddress(hDLL, 'glutWindowStatusFunc');
  625. @glutKeyboardUpFunc := GetGLutProcAddress(hDLL, 'glutKeyboardUpFunc');
  626. @glutSpecialUpFunc := GetGLutProcAddress(hDLL, 'glutSpecialUpFunc');
  627. @glutJoystickFunc := GetGLutProcAddress(hDLL, 'glutJoystickFunc');
  628. @glutSetColor := GetGLutProcAddress(hDLL, 'glutSetColor');
  629. @glutGetColor := GetGLutProcAddress(hDLL, 'glutGetColor');
  630. @glutCopyColormap := GetGLutProcAddress(hDLL, 'glutCopyColormap');
  631. @glutGet := GetGLutProcAddress(hDLL, 'glutGet');
  632. @glutDeviceGet := GetGLutProcAddress(hDLL, 'glutDeviceGet');
  633. @glutExtensionSupported := GetGLutProcAddress(hDLL, 'glutExtensionSupported');
  634. @glutGetModifiers := GetGLutProcAddress(hDLL, 'glutGetModifiers');
  635. @glutLayerGet := GetGLutProcAddress(hDLL, 'glutLayerGet');
  636. @glutBitmapCharacter := GetGLutProcAddress(hDLL, 'glutBitmapCharacter');
  637. @glutBitmapWidth := GetGLutProcAddress(hDLL, 'glutBitmapWidth');
  638. @glutStrokeCharacter := GetGLutProcAddress(hDLL, 'glutStrokeCharacter');
  639. @glutStrokeWidth := GetGLutProcAddress(hDLL, 'glutStrokeWidth');
  640. @glutBitmapLength := GetGLutProcAddress(hDLL, 'glutBitmapLength');
  641. @glutStrokeLength := GetGLutProcAddress(hDLL, 'glutStrokeLength');
  642. @glutWireSphere := GetGLutProcAddress(hDLL, 'glutWireSphere');
  643. @glutSolidSphere := GetGLutProcAddress(hDLL, 'glutSolidSphere');
  644. @glutWireCone := GetGLutProcAddress(hDLL, 'glutWireCone');
  645. @glutSolidCone := GetGLutProcAddress(hDLL, 'glutSolidCone');
  646. @glutWireCube := GetGLutProcAddress(hDLL, 'glutWireCube');
  647. @glutSolidCube := GetGLutProcAddress(hDLL, 'glutSolidCube');
  648. @glutWireTorus := GetGLutProcAddress(hDLL, 'glutWireTorus');
  649. @glutSolidTorus := GetGLutProcAddress(hDLL, 'glutSolidTorus');
  650. @glutWireDodecahedron := GetGLutProcAddress(hDLL, 'glutWireDodecahedron');
  651. @glutSolidDodecahedron := GetGLutProcAddress(hDLL, 'glutSolidDodecahedron');
  652. @glutWireTeapot := GetGLutProcAddress(hDLL, 'glutWireTeapot');
  653. @glutSolidTeapot := GetGLutProcAddress(hDLL, 'glutSolidTeapot');
  654. @glutWireOctahedron := GetGLutProcAddress(hDLL, 'glutWireOctahedron');
  655. @glutSolidOctahedron := GetGLutProcAddress(hDLL, 'glutSolidOctahedron');
  656. @glutWireTetrahedron := GetGLutProcAddress(hDLL, 'glutWireTetrahedron');
  657. @glutSolidTetrahedron := GetGLutProcAddress(hDLL, 'glutSolidTetrahedron');
  658. @glutWireIcosahedron := GetGLutProcAddress(hDLL, 'glutWireIcosahedron');
  659. @glutSolidIcosahedron := GetGLutProcAddress(hDLL, 'glutSolidIcosahedron');
  660. @glutVideoResizeGet := GetGLutProcAddress(hDLL, 'glutVideoResizeGet');
  661. @glutSetupVideoResizing := GetGLutProcAddress(hDLL, 'glutSetupVideoResizing');
  662. @glutStopVideoResizing := GetGLutProcAddress(hDLL, 'glutStopVideoResizing');
  663. @glutVideoResize := GetGLutProcAddress(hDLL, 'glutVideoResize');
  664. @glutVideoPan := GetGLutProcAddress(hDLL, 'glutVideoPan');
  665. @glutReportErrors := GetGLutProcAddress(hDLL, 'glutReportErrors');
  666. @glutIgnoreKeyRepeat := GetGLutProcAddress(hDLL, 'glutIgnoreKeyRepeat');
  667. @glutSetKeyRepeat := GetGLutProcAddress(hDLL, 'glutSetKeyRepeat');
  668. @glutForceJoystickFunc := GetGLutProcAddress(hDLL, 'glutForceJoystickFunc');
  669. @glutGameModeString := GetGLutProcAddress(hDLL, 'glutGameModeString');
  670. @glutEnterGameMode := GetGLutProcAddress(hDLL, 'glutEnterGameMode');
  671. @glutLeaveGameMode := GetGLutProcAddress(hDLL, 'glutLeaveGameMode');
  672. @glutGameModeGet := GetGLutProcAddress(hDLL, 'glutGameModeGet');
  673. {$ifndef Windows}
  674. GLUT_STROKE_ROMAN := GetGLutProcAddress(hDll, 'glutStrokeRoman');
  675. GLUT_STROKE_MONO_ROMAN := GetGLutProcAddress(hDll,'glutStrokeMonoRoman');
  676. GLUT_BITMAP_9_BY_15 := GetGLutProcAddress(hDll, 'glutBitmap9By15');
  677. GLUT_BITMAP_8_BY_13 := GetGLutProcAddress(hDll, 'glutBitmap8By13');
  678. GLUT_BITMAP_TIMES_ROMAN_10 := GetGLutProcAddress(hDll, 'glutBitmapTimesRoman10');
  679. GLUT_BITMAP_TIMES_ROMAN_24 := GetGLutProcAddress(hDll, 'glutBitmapTimesRoman24');
  680. GLUT_BITMAP_HELVETICA_10 := GetGLutProcAddress(hDll, 'glutBitmapHelvetica10');
  681. GLUT_BITMAP_HELVETICA_12 := GetGLutProcAddress(hDll, 'glutBitmapHelvetica12');
  682. GLUT_BITMAP_HELVETICA_18 := GetGLutProcAddress(hDll, 'glutBitmapHelvetica18');
  683. {$endif Windows}
  684. except
  685. raise Exception.Create('Could not load ' + MethodName + ' from ' + dll);
  686. end;
  687. LoadFreeGlut(hDLL);
  688. end;
  689. {$ENDIF MORPHOS}
  690. initialization
  691. {$if defined(Windows)}
  692. LoadGlut('glut32.dll');
  693. {$elseif defined(OS2)}
  694. LoadGlut('glut.dll');
  695. {$elseif defined(darwin)}
  696. LoadGlut('/System/Library/Frameworks/GLUT.framework/GLUT');
  697. {$elseif defined(haiku) or defined(OpenBSD)}
  698. LoadGlut('libglut.so');
  699. {$elseif defined(MORPHOS)}
  700. {nothing}
  701. {$else}
  702. LoadGlut('libglut.so.3');
  703. {$endif}
  704. finalization
  705. UnloadGlut;
  706. end.