glut.nim 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. #
  2. #
  3. # Adaption of the delphi3d.net OpenGL units to FreePascal
  4. # Sebastian Guenther (sg@freepascal.org) in 2002
  5. # These units are free to use
  6. #
  7. # Copyright (c) Mark J. Kilgard, 1994, 1995, 1996.
  8. # This program is freely distributable without licensing fees and is
  9. # provided without guarantee or warrantee expressed or implied. This
  10. # program is -not- in the public domain.
  11. #******************************************************************************
  12. # Converted to Delphi by Tom Nuydens (tom@delphi3d.net)
  13. # Contributions by Igor Karpov (glygrik@hotbox.ru)
  14. # For the latest updates, visit Delphi3D: http://www.delphi3d.net
  15. #******************************************************************************
  16. import ../opengl
  17. {.deadCodeElim: on.}
  18. when defined(windows):
  19. const
  20. dllname = "(freeglut.dll|glut32.dll)"
  21. elif defined(macosx):
  22. const
  23. dllname = "/System/Library/Frameworks/GLUT.framework/GLUT"
  24. else:
  25. const
  26. dllname = "libglut.so.3"
  27. type
  28. TGlutVoidCallback* = proc (){.cdecl.}
  29. TGlut1IntCallback* = proc (value: cint){.cdecl.}
  30. TGlut2IntCallback* = proc (v1, v2: cint){.cdecl.}
  31. TGlut3IntCallback* = proc (v1, v2, v3: cint){.cdecl.}
  32. TGlut4IntCallback* = proc (v1, v2, v3, v4: cint){.cdecl.}
  33. TGlut1Char2IntCallback* = proc (c: int8, v1, v2: cint){.cdecl.}
  34. TGlut1UInt3IntCallback* = proc (u, v1, v2, v3: cint){.cdecl.}
  35. {.deprecated: [Pointer: pointer].}
  36. const
  37. GLUT_API_VERSION* = 3
  38. GLUT_XLIB_IMPLEMENTATION* = 12 # Display mode bit masks.
  39. GLUT_RGB* = 0
  40. GLUT_RGBA* = GLUT_RGB
  41. GLUT_INDEX* = 1
  42. GLUT_SINGLE* = 0
  43. GLUT_DOUBLE* = 2
  44. GLUT_ACCUM* = 4
  45. GLUT_ALPHA* = 8
  46. GLUT_DEPTH* = 16
  47. GLUT_STENCIL* = 32
  48. GLUT_MULTISAMPLE* = 128
  49. GLUT_STEREO* = 256
  50. GLUT_LUMINANCE* = 512 # Mouse buttons.
  51. GLUT_LEFT_BUTTON* = 0
  52. GLUT_MIDDLE_BUTTON* = 1
  53. GLUT_RIGHT_BUTTON* = 2 # Mouse button state.
  54. GLUT_DOWN* = 0
  55. GLUT_UP* = 1 # function keys
  56. GLUT_KEY_F1* = 1
  57. GLUT_KEY_F2* = 2
  58. GLUT_KEY_F3* = 3
  59. GLUT_KEY_F4* = 4
  60. GLUT_KEY_F5* = 5
  61. GLUT_KEY_F6* = 6
  62. GLUT_KEY_F7* = 7
  63. GLUT_KEY_F8* = 8
  64. GLUT_KEY_F9* = 9
  65. GLUT_KEY_F10* = 10
  66. GLUT_KEY_F11* = 11
  67. GLUT_KEY_F12* = 12 # directional keys
  68. GLUT_KEY_LEFT* = 100
  69. GLUT_KEY_UP* = 101
  70. GLUT_KEY_RIGHT* = 102
  71. GLUT_KEY_DOWN* = 103
  72. GLUT_KEY_PAGE_UP* = 104
  73. GLUT_KEY_PAGE_DOWN* = 105
  74. GLUT_KEY_HOME* = 106
  75. GLUT_KEY_END* = 107
  76. GLUT_KEY_INSERT* = 108 # Entry/exit state.
  77. GLUT_LEFT* = 0
  78. GLUT_ENTERED* = 1 # Menu usage state.
  79. GLUT_MENU_NOT_IN_USE* = 0
  80. GLUT_MENU_IN_USE* = 1 # Visibility state.
  81. GLUT_NOT_VISIBLE* = 0
  82. GLUT_VISIBLE* = 1 # Window status state.
  83. GLUT_HIDDEN* = 0
  84. GLUT_FULLY_RETAINED* = 1
  85. GLUT_PARTIALLY_RETAINED* = 2
  86. GLUT_FULLY_COVERED* = 3 # Color index component selection values.
  87. GLUT_RED* = 0
  88. GLUT_GREEN* = 1
  89. GLUT_BLUE* = 2 # Layers for use.
  90. GLUT_NORMAL* = 0
  91. GLUT_OVERLAY* = 1
  92. {.push dynlib: dllname, importc.}
  93. when defined(Windows):
  94. const # Stroke font constants (use these in GLUT program).
  95. GLUT_STROKE_ROMAN* = cast[pointer](0)
  96. GLUT_STROKE_MONO_ROMAN* = cast[pointer](1) # Bitmap font constants (use these in GLUT program).
  97. GLUT_BITMAP_9_BY_15* = cast[pointer](2)
  98. GLUT_BITMAP_8_BY_13* = cast[pointer](3)
  99. GLUT_BITMAP_TIMES_ROMAN_10* = cast[pointer](4)
  100. GLUT_BITMAP_TIMES_ROMAN_24* = cast[pointer](5)
  101. GLUT_BITMAP_HELVETICA_10* = cast[pointer](6)
  102. GLUT_BITMAP_HELVETICA_12* = cast[pointer](7)
  103. GLUT_BITMAP_HELVETICA_18* = cast[pointer](8)
  104. else:
  105. var # Stroke font constants (use these in GLUT program).
  106. glutStrokeRoman {.importc: "glutStrokeRoman".}: pointer
  107. glutStrokeMonoRoman {.importc: "glutStrokeMonoRoman".}: pointer # Bitmap font constants (use these in GLUT program).
  108. glutBitmap9By15 {.importc: "glutBitmap9By15".}: pointer
  109. glutBitmap8By13 {.importc: "glutBitmap8By13".}: pointer
  110. glutBitmapTimesRoman10 {.importc: "glutBitmapTimesRoman10".}: pointer
  111. glutBitmapTimesRoman24 {.importc: "glutBitmapTimesRoman24".}: pointer
  112. glutBitmapHelvetica10 {.importc: "glutBitmapHelvetica10".}: pointer
  113. glutBitmapHelvetica12 {.importc: "glutBitmapHelvetica12".}: pointer
  114. glutBitmapHelvetica18 {.importc: "glutBitmapHelvetica18".}: pointer
  115. let
  116. GLUT_STROKE_ROMAN* = cast[pointer](addr glutStrokeRoman)
  117. GLUT_STROKE_MONO_ROMAN* = cast[pointer](addr glutStrokeMonoRoman)
  118. GLUT_BITMAP_9_BY_15* = cast[pointer](addr glutBitmap9By15)
  119. GLUT_BITMAP_8_BY_13* = cast[pointer](addr glutBitmap8By13)
  120. GLUT_BITMAP_TIMES_ROMAN_10* = cast[pointer](addr glutBitmapTimesRoman10)
  121. GLUT_BITMAP_TIMES_ROMAN_24* = cast[pointer](addr glutBitmapTimesRoman24)
  122. GLUT_BITMAP_HELVETICA_10* = cast[pointer](addr glutBitmapHelvetica10)
  123. GLUT_BITMAP_HELVETICA_12* = cast[pointer](addr glutBitmapHelvetica12)
  124. GLUT_BITMAP_HELVETICA_18* = cast[pointer](addr glutBitmapHelvetica18)
  125. const # glutGet parameters.
  126. GLUT_WINDOW_X* = 100
  127. GLUT_WINDOW_Y* = 101
  128. GLUT_WINDOW_WIDTH* = 102
  129. GLUT_WINDOW_HEIGHT* = 103
  130. GLUT_WINDOW_BUFFER_SIZE* = 104
  131. GLUT_WINDOW_STENCIL_SIZE* = 105
  132. GLUT_WINDOW_DEPTH_SIZE* = 106
  133. GLUT_WINDOW_RED_SIZE* = 107
  134. GLUT_WINDOW_GREEN_SIZE* = 108
  135. GLUT_WINDOW_BLUE_SIZE* = 109
  136. GLUT_WINDOW_ALPHA_SIZE* = 110
  137. GLUT_WINDOW_ACCUM_RED_SIZE* = 111
  138. GLUT_WINDOW_ACCUM_GREEN_SIZE* = 112
  139. GLUT_WINDOW_ACCUM_BLUE_SIZE* = 113
  140. GLUT_WINDOW_ACCUM_ALPHA_SIZE* = 114
  141. GLUT_WINDOW_DOUBLEBUFFER* = 115
  142. GLUT_WINDOW_RGBA* = 116
  143. GLUT_WINDOW_PARENT* = 117
  144. GLUT_WINDOW_NUM_CHILDREN* = 118
  145. GLUT_WINDOW_COLORMAP_SIZE* = 119
  146. GLUT_WINDOW_NUM_SAMPLES* = 120
  147. GLUT_WINDOW_STEREO* = 121
  148. GLUT_WINDOW_CURSOR* = 122
  149. GLUT_SCREEN_WIDTH* = 200
  150. GLUT_SCREEN_HEIGHT* = 201
  151. GLUT_SCREEN_WIDTH_MM* = 202
  152. GLUT_SCREEN_HEIGHT_MM* = 203
  153. GLUT_MENU_NUM_ITEMS* = 300
  154. GLUT_DISPLAY_MODE_POSSIBLE* = 400
  155. GLUT_INIT_WINDOW_X* = 500
  156. GLUT_INIT_WINDOW_Y* = 501
  157. GLUT_INIT_WINDOW_WIDTH* = 502
  158. GLUT_INIT_WINDOW_HEIGHT* = 503
  159. constGLUT_INIT_DISPLAY_MODE* = 504
  160. GLUT_ELAPSED_TIME* = 700
  161. GLUT_WINDOW_FORMAT_ID* = 123 # glutDeviceGet parameters.
  162. GLUT_HAS_KEYBOARD* = 600
  163. GLUT_HAS_MOUSE* = 601
  164. GLUT_HAS_SPACEBALL* = 602
  165. GLUT_HAS_DIAL_AND_BUTTON_BOX* = 603
  166. GLUT_HAS_TABLET* = 604
  167. GLUT_NUM_MOUSE_BUTTONS* = 605
  168. GLUT_NUM_SPACEBALL_BUTTONS* = 606
  169. GLUT_NUM_BUTTON_BOX_BUTTONS* = 607
  170. GLUT_NUM_DIALS* = 608
  171. GLUT_NUM_TABLET_BUTTONS* = 609
  172. GLUT_DEVICE_IGNORE_KEY_REPEAT* = 610
  173. GLUT_DEVICE_KEY_REPEAT* = 611
  174. GLUT_HAS_JOYSTICK* = 612
  175. GLUT_OWNS_JOYSTICK* = 613
  176. GLUT_JOYSTICK_BUTTONS* = 614
  177. GLUT_JOYSTICK_AXES* = 615
  178. GLUT_JOYSTICK_POLL_RATE* = 616 # glutLayerGet parameters.
  179. GLUT_OVERLAY_POSSIBLE* = 800
  180. GLUT_LAYER_IN_USE* = 801
  181. GLUT_HAS_OVERLAY* = 802
  182. GLUT_TRANSPARENT_INDEX* = 803
  183. GLUT_NORMAL_DAMAGED* = 804
  184. GLUT_OVERLAY_DAMAGED* = 805 # glutVideoResizeGet parameters.
  185. GLUT_VIDEO_RESIZE_POSSIBLE* = 900
  186. GLUT_VIDEO_RESIZE_IN_USE* = 901
  187. GLUT_VIDEO_RESIZE_X_DELTA* = 902
  188. GLUT_VIDEO_RESIZE_Y_DELTA* = 903
  189. GLUT_VIDEO_RESIZE_WIDTH_DELTA* = 904
  190. GLUT_VIDEO_RESIZE_HEIGHT_DELTA* = 905
  191. GLUT_VIDEO_RESIZE_X* = 906
  192. GLUT_VIDEO_RESIZE_Y* = 907
  193. GLUT_VIDEO_RESIZE_WIDTH* = 908
  194. GLUT_VIDEO_RESIZE_HEIGHT* = 909 # glutGetModifiers return mask.
  195. GLUT_ACTIVE_SHIFT* = 1
  196. GLUT_ACTIVE_CTRL* = 2
  197. GLUT_ACTIVE_ALT* = 4 # glutSetCursor parameters.
  198. # Basic arrows.
  199. GLUT_CURSOR_RIGHT_ARROW* = 0
  200. GLUT_CURSOR_LEFT_ARROW* = 1 # Symbolic cursor shapes.
  201. GLUT_CURSOR_INFO* = 2
  202. GLUT_CURSOR_DESTROY* = 3
  203. GLUT_CURSOR_HELP* = 4
  204. GLUT_CURSOR_CYCLE* = 5
  205. GLUT_CURSOR_SPRAY* = 6
  206. GLUT_CURSOR_WAIT* = 7
  207. GLUT_CURSOR_TEXT* = 8
  208. GLUT_CURSOR_CROSSHAIR* = 9 # Directional cursors.
  209. GLUT_CURSOR_UP_DOWN* = 10
  210. GLUT_CURSOR_LEFT_RIGHT* = 11 # Sizing cursors.
  211. GLUT_CURSOR_TOP_SIDE* = 12
  212. GLUT_CURSOR_BOTTOM_SIDE* = 13
  213. GLUT_CURSOR_LEFT_SIDE* = 14
  214. GLUT_CURSOR_RIGHT_SIDE* = 15
  215. GLUT_CURSOR_TOP_LEFT_CORNER* = 16
  216. GLUT_CURSOR_TOP_RIGHT_CORNER* = 17
  217. GLUT_CURSOR_BOTTOM_RIGHT_CORNER* = 18
  218. GLUT_CURSOR_BOTTOM_LEFT_CORNER* = 19 # Inherit from parent window.
  219. GLUT_CURSOR_INHERIT* = 100 # Blank cursor.
  220. GLUT_CURSOR_NONE* = 101 # Fullscreen crosshair (if available).
  221. GLUT_CURSOR_FULL_CROSSHAIR* = 102 # GLUT device control sub-API.
  222. # glutSetKeyRepeat modes.
  223. GLUT_KEY_REPEAT_OFF* = 0
  224. GLUT_KEY_REPEAT_ON* = 1
  225. GLUT_KEY_REPEAT_DEFAULT* = 2 # Joystick button masks.
  226. GLUT_JOYSTICK_BUTTON_A* = 1
  227. GLUT_JOYSTICK_BUTTON_B* = 2
  228. GLUT_JOYSTICK_BUTTON_C* = 4
  229. GLUT_JOYSTICK_BUTTON_D* = 8 # GLUT game mode sub-API.
  230. # glutGameModeGet.
  231. GLUT_GAME_MODE_ACTIVE* = 0
  232. GLUT_GAME_MODE_POSSIBLE* = 1
  233. GLUT_GAME_MODE_WIDTH* = 2
  234. GLUT_GAME_MODE_HEIGHT* = 3
  235. GLUT_GAME_MODE_PIXEL_DEPTH* = 4
  236. GLUT_GAME_MODE_REFRESH_RATE* = 5
  237. GLUT_GAME_MODE_DISPLAY_CHANGED* = 6 # GLUT initialization sub-API.
  238. proc glutInit*(argcp: ptr cint, argv: pointer)
  239. proc glutInitDisplayMode*(mode: int16)
  240. proc glutInitDisplayString*(str: cstring)
  241. proc glutInitWindowPosition*(x, y: int)
  242. proc glutInitWindowSize*(width, height: int)
  243. proc glutMainLoop*()
  244. # GLUT window sub-API.
  245. proc glutCreateWindow*(title: cstring): int
  246. proc glutCreateSubWindow*(win, x, y, width, height: int): int
  247. proc glutDestroyWindow*(win: int)
  248. proc glutPostRedisplay*()
  249. proc glutPostWindowRedisplay*(win: int)
  250. proc glutSwapBuffers*()
  251. proc glutSetWindow*(win: int)
  252. proc glutSetWindowTitle*(title: cstring)
  253. proc glutSetIconTitle*(title: cstring)
  254. proc glutPositionWindow*(x, y: int)
  255. proc glutReshapeWindow*(width, height: int)
  256. proc glutPopWindow*()
  257. proc glutPushWindow*()
  258. proc glutIconifyWindow*()
  259. proc glutShowWindow*()
  260. proc glutHideWindow*()
  261. proc glutFullScreen*()
  262. proc glutSetCursor*(cursor: int)
  263. proc glutWarpPointer*(x, y: int)
  264. # GLUT overlay sub-API.
  265. proc glutEstablishOverlay*()
  266. proc glutRemoveOverlay*()
  267. proc glutUseLayer*(layer: GLenum)
  268. proc glutPostOverlayRedisplay*()
  269. proc glutPostWindowOverlayRedisplay*(win: int)
  270. proc glutShowOverlay*()
  271. proc glutHideOverlay*()
  272. # GLUT menu sub-API.
  273. proc glutCreateMenu*(callback: TGlut1IntCallback): int
  274. proc glutDestroyMenu*(menu: int)
  275. proc glutSetMenu*(menu: int)
  276. proc glutAddMenuEntry*(caption: cstring, value: int)
  277. proc glutAddSubMenu*(caption: cstring, submenu: int)
  278. proc glutChangeToMenuEntry*(item: int, caption: cstring, value: int)
  279. proc glutChangeToSubMenu*(item: int, caption: cstring, submenu: int)
  280. proc glutRemoveMenuItem*(item: int)
  281. proc glutAttachMenu*(button: int)
  282. proc glutDetachMenu*(button: int)
  283. # GLUT window callback sub-API.
  284. proc glutDisplayFunc*(f: TGlutVoidCallback)
  285. proc glutReshapeFunc*(f: TGlut2IntCallback)
  286. proc glutKeyboardFunc*(f: TGlut1Char2IntCallback)
  287. proc glutMouseFunc*(f: TGlut4IntCallback)
  288. proc glutMouseWheelFunc*(f: TGlut4IntCallback)
  289. proc glutMotionFunc*(f: TGlut2IntCallback)
  290. proc glutPassiveMotionFunc*(f: TGlut2IntCallback)
  291. proc glutEntryFunc*(f: TGlut1IntCallback)
  292. proc glutVisibilityFunc*(f: TGlut1IntCallback)
  293. proc glutIdleFunc*(f: TGlutVoidCallback)
  294. proc glutTimerFunc*(millis: int16, f: TGlut1IntCallback, value: int)
  295. proc glutMenuStateFunc*(f: TGlut1IntCallback)
  296. proc glutSpecialFunc*(f: TGlut3IntCallback)
  297. proc glutSpaceballMotionFunc*(f: TGlut3IntCallback)
  298. proc glutSpaceballRotateFunc*(f: TGlut3IntCallback)
  299. proc glutSpaceballButtonFunc*(f: TGlut2IntCallback)
  300. proc glutButtonBoxFunc*(f: TGlut2IntCallback)
  301. proc glutDialsFunc*(f: TGlut2IntCallback)
  302. proc glutTabletMotionFunc*(f: TGlut2IntCallback)
  303. proc glutTabletButtonFunc*(f: TGlut4IntCallback)
  304. proc glutMenuStatusFunc*(f: TGlut3IntCallback)
  305. proc glutOverlayDisplayFunc*(f: TGlutVoidCallback)
  306. proc glutWindowStatusFunc*(f: TGlut1IntCallback)
  307. proc glutKeyboardUpFunc*(f: TGlut1Char2IntCallback)
  308. proc glutSpecialUpFunc*(f: TGlut3IntCallback)
  309. proc glutJoystickFunc*(f: TGlut1UInt3IntCallback, pollInterval: int)
  310. # GLUT color index sub-API.
  311. proc glutSetColor*(cell: int, red, green, blue: GLfloat)
  312. proc glutGetColor*(ndx, component: int): GLfloat
  313. proc glutCopyColormap*(win: int)
  314. # GLUT state retrieval sub-API.
  315. # GLUT extension support sub-API
  316. proc glutExtensionSupported*(name: cstring): int
  317. # GLUT font sub-API
  318. proc glutBitmapCharacter*(font: pointer, character: int)
  319. proc glutBitmapWidth*(font: pointer, character: int): int
  320. proc glutStrokeCharacter*(font: pointer, character: int)
  321. proc glutStrokeWidth*(font: pointer, character: int): int
  322. proc glutBitmapLength*(font: pointer, str: cstring): int
  323. proc glutStrokeLength*(font: pointer, str: cstring): int
  324. # GLUT pre-built models sub-API
  325. proc glutWireSphere*(radius: GLdouble, slices, stacks: GLint)
  326. proc glutSolidSphere*(radius: GLdouble, slices, stacks: GLint)
  327. proc glutWireCone*(base, height: GLdouble, slices, stacks: GLint)
  328. proc glutSolidCone*(base, height: GLdouble, slices, stacks: GLint)
  329. proc glutWireCube*(size: GLdouble)
  330. proc glutSolidCube*(size: GLdouble)
  331. proc glutWireTorus*(innerRadius, outerRadius: GLdouble, sides, rings: GLint)
  332. proc glutSolidTorus*(innerRadius, outerRadius: GLdouble, sides, rings: GLint)
  333. proc glutWireDodecahedron*()
  334. proc glutSolidDodecahedron*()
  335. proc glutWireTeapot*(size: GLdouble)
  336. proc glutSolidTeapot*(size: GLdouble)
  337. proc glutWireOctahedron*()
  338. proc glutSolidOctahedron*()
  339. proc glutWireTetrahedron*()
  340. proc glutSolidTetrahedron*()
  341. proc glutWireIcosahedron*()
  342. proc glutSolidIcosahedron*()
  343. # GLUT video resize sub-API.
  344. proc glutVideoResizeGet*(param: GLenum): int
  345. proc glutSetupVideoResizing*()
  346. proc glutStopVideoResizing*()
  347. proc glutVideoResize*(x, y, width, height: int)
  348. proc glutVideoPan*(x, y, width, height: int)
  349. # GLUT debugging sub-API.
  350. proc glutReportErrors*()
  351. # GLUT device control sub-API.
  352. proc glutIgnoreKeyRepeat*(ignore: int)
  353. proc glutSetKeyRepeat*(repeatMode: int)
  354. proc glutForceJoystickFunc*()
  355. # GLUT game mode sub-API.
  356. #example glutGameModeString('1280x1024:32@75');
  357. proc glutGameModeString*(AString: cstring)
  358. proc glutLeaveGameMode*()
  359. proc glutGameModeGet*(mode: GLenum): int
  360. # implementation
  361. {.pop.} # dynlib: dllname, importc
  362. # Convenience procs
  363. proc glutInit*() =
  364. ## version that passes `argc` and `argc` implicitely.
  365. var
  366. cmdLine {.importc: "cmdLine".}: array[0..255, cstring]
  367. cmdCount {.importc: "cmdCount".}: cint
  368. glutInit(addr(cmdCount), addr(cmdLine))