glut.pp 29 KB

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