glut.nim 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 = "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. when defined(Windows):
  93. const # Stroke font constants (use these in GLUT program).
  94. GLUT_STROKE_ROMAN* = cast[pointer](0)
  95. GLUT_STROKE_MONO_ROMAN* = cast[pointer](1) # Bitmap font constants (use these in GLUT program).
  96. GLUT_BITMAP_9_BY_15* = cast[pointer](2)
  97. GLUT_BITMAP_8_BY_13* = cast[pointer](3)
  98. GLUT_BITMAP_TIMES_ROMAN_10* = cast[pointer](4)
  99. GLUT_BITMAP_TIMES_ROMAN_24* = cast[pointer](5)
  100. GLUT_BITMAP_HELVETICA_10* = cast[pointer](6)
  101. GLUT_BITMAP_HELVETICA_12* = cast[pointer](7)
  102. GLUT_BITMAP_HELVETICA_18* = cast[pointer](8)
  103. else:
  104. var # Stroke font constants (use these in GLUT program).
  105. GLUT_STROKE_ROMAN*: pointer
  106. GLUT_STROKE_MONO_ROMAN*: pointer # Bitmap font constants (use these in GLUT program).
  107. GLUT_BITMAP_9_BY_15*: pointer
  108. GLUT_BITMAP_8_BY_13*: pointer
  109. GLUT_BITMAP_TIMES_ROMAN_10*: pointer
  110. GLUT_BITMAP_TIMES_ROMAN_24*: pointer
  111. GLUT_BITMAP_HELVETICA_10*: pointer
  112. GLUT_BITMAP_HELVETICA_12*: pointer
  113. GLUT_BITMAP_HELVETICA_18*: pointer
  114. const # glutGet parameters.
  115. GLUT_WINDOW_X* = 100
  116. GLUT_WINDOW_Y* = 101
  117. GLUT_WINDOW_WIDTH* = 102
  118. GLUT_WINDOW_HEIGHT* = 103
  119. GLUT_WINDOW_BUFFER_SIZE* = 104
  120. GLUT_WINDOW_STENCIL_SIZE* = 105
  121. GLUT_WINDOW_DEPTH_SIZE* = 106
  122. GLUT_WINDOW_RED_SIZE* = 107
  123. GLUT_WINDOW_GREEN_SIZE* = 108
  124. GLUT_WINDOW_BLUE_SIZE* = 109
  125. GLUT_WINDOW_ALPHA_SIZE* = 110
  126. GLUT_WINDOW_ACCUM_RED_SIZE* = 111
  127. GLUT_WINDOW_ACCUM_GREEN_SIZE* = 112
  128. GLUT_WINDOW_ACCUM_BLUE_SIZE* = 113
  129. GLUT_WINDOW_ACCUM_ALPHA_SIZE* = 114
  130. GLUT_WINDOW_DOUBLEBUFFER* = 115
  131. GLUT_WINDOW_RGBA* = 116
  132. GLUT_WINDOW_PARENT* = 117
  133. GLUT_WINDOW_NUM_CHILDREN* = 118
  134. GLUT_WINDOW_COLORMAP_SIZE* = 119
  135. GLUT_WINDOW_NUM_SAMPLES* = 120
  136. GLUT_WINDOW_STEREO* = 121
  137. GLUT_WINDOW_CURSOR* = 122
  138. GLUT_SCREEN_WIDTH* = 200
  139. GLUT_SCREEN_HEIGHT* = 201
  140. GLUT_SCREEN_WIDTH_MM* = 202
  141. GLUT_SCREEN_HEIGHT_MM* = 203
  142. GLUT_MENU_NUM_ITEMS* = 300
  143. GLUT_DISPLAY_MODE_POSSIBLE* = 400
  144. GLUT_INIT_WINDOW_X* = 500
  145. GLUT_INIT_WINDOW_Y* = 501
  146. GLUT_INIT_WINDOW_WIDTH* = 502
  147. GLUT_INIT_WINDOW_HEIGHT* = 503
  148. constGLUT_INIT_DISPLAY_MODE* = 504
  149. GLUT_ELAPSED_TIME* = 700
  150. GLUT_WINDOW_FORMAT_ID* = 123 # glutDeviceGet parameters.
  151. GLUT_HAS_KEYBOARD* = 600
  152. GLUT_HAS_MOUSE* = 601
  153. GLUT_HAS_SPACEBALL* = 602
  154. GLUT_HAS_DIAL_AND_BUTTON_BOX* = 603
  155. GLUT_HAS_TABLET* = 604
  156. GLUT_NUM_MOUSE_BUTTONS* = 605
  157. GLUT_NUM_SPACEBALL_BUTTONS* = 606
  158. GLUT_NUM_BUTTON_BOX_BUTTONS* = 607
  159. GLUT_NUM_DIALS* = 608
  160. GLUT_NUM_TABLET_BUTTONS* = 609
  161. GLUT_DEVICE_IGNORE_KEY_REPEAT* = 610
  162. GLUT_DEVICE_KEY_REPEAT* = 611
  163. GLUT_HAS_JOYSTICK* = 612
  164. GLUT_OWNS_JOYSTICK* = 613
  165. GLUT_JOYSTICK_BUTTONS* = 614
  166. GLUT_JOYSTICK_AXES* = 615
  167. GLUT_JOYSTICK_POLL_RATE* = 616 # glutLayerGet parameters.
  168. GLUT_OVERLAY_POSSIBLE* = 800
  169. GLUT_LAYER_IN_USE* = 801
  170. GLUT_HAS_OVERLAY* = 802
  171. GLUT_TRANSPARENT_INDEX* = 803
  172. GLUT_NORMAL_DAMAGED* = 804
  173. GLUT_OVERLAY_DAMAGED* = 805 # glutVideoResizeGet parameters.
  174. GLUT_VIDEO_RESIZE_POSSIBLE* = 900
  175. GLUT_VIDEO_RESIZE_IN_USE* = 901
  176. GLUT_VIDEO_RESIZE_X_DELTA* = 902
  177. GLUT_VIDEO_RESIZE_Y_DELTA* = 903
  178. GLUT_VIDEO_RESIZE_WIDTH_DELTA* = 904
  179. GLUT_VIDEO_RESIZE_HEIGHT_DELTA* = 905
  180. GLUT_VIDEO_RESIZE_X* = 906
  181. GLUT_VIDEO_RESIZE_Y* = 907
  182. GLUT_VIDEO_RESIZE_WIDTH* = 908
  183. GLUT_VIDEO_RESIZE_HEIGHT* = 909 # glutGetModifiers return mask.
  184. GLUT_ACTIVE_SHIFT* = 1
  185. GLUT_ACTIVE_CTRL* = 2
  186. GLUT_ACTIVE_ALT* = 4 # glutSetCursor parameters.
  187. # Basic arrows.
  188. GLUT_CURSOR_RIGHT_ARROW* = 0
  189. GLUT_CURSOR_LEFT_ARROW* = 1 # Symbolic cursor shapes.
  190. GLUT_CURSOR_INFO* = 2
  191. GLUT_CURSOR_DESTROY* = 3
  192. GLUT_CURSOR_HELP* = 4
  193. GLUT_CURSOR_CYCLE* = 5
  194. GLUT_CURSOR_SPRAY* = 6
  195. GLUT_CURSOR_WAIT* = 7
  196. GLUT_CURSOR_TEXT* = 8
  197. GLUT_CURSOR_CROSSHAIR* = 9 # Directional cursors.
  198. GLUT_CURSOR_UP_DOWN* = 10
  199. GLUT_CURSOR_LEFT_RIGHT* = 11 # Sizing cursors.
  200. GLUT_CURSOR_TOP_SIDE* = 12
  201. GLUT_CURSOR_BOTTOM_SIDE* = 13
  202. GLUT_CURSOR_LEFT_SIDE* = 14
  203. GLUT_CURSOR_RIGHT_SIDE* = 15
  204. GLUT_CURSOR_TOP_LEFT_CORNER* = 16
  205. GLUT_CURSOR_TOP_RIGHT_CORNER* = 17
  206. GLUT_CURSOR_BOTTOM_RIGHT_CORNER* = 18
  207. GLUT_CURSOR_BOTTOM_LEFT_CORNER* = 19 # Inherit from parent window.
  208. GLUT_CURSOR_INHERIT* = 100 # Blank cursor.
  209. GLUT_CURSOR_NONE* = 101 # Fullscreen crosshair (if available).
  210. GLUT_CURSOR_FULL_CROSSHAIR* = 102 # GLUT device control sub-API.
  211. # glutSetKeyRepeat modes.
  212. GLUT_KEY_REPEAT_OFF* = 0
  213. GLUT_KEY_REPEAT_ON* = 1
  214. GLUT_KEY_REPEAT_DEFAULT* = 2 # Joystick button masks.
  215. GLUT_JOYSTICK_BUTTON_A* = 1
  216. GLUT_JOYSTICK_BUTTON_B* = 2
  217. GLUT_JOYSTICK_BUTTON_C* = 4
  218. GLUT_JOYSTICK_BUTTON_D* = 8 # GLUT game mode sub-API.
  219. # glutGameModeGet.
  220. GLUT_GAME_MODE_ACTIVE* = 0
  221. GLUT_GAME_MODE_POSSIBLE* = 1
  222. GLUT_GAME_MODE_WIDTH* = 2
  223. GLUT_GAME_MODE_HEIGHT* = 3
  224. GLUT_GAME_MODE_PIXEL_DEPTH* = 4
  225. GLUT_GAME_MODE_REFRESH_RATE* = 5
  226. GLUT_GAME_MODE_DISPLAY_CHANGED* = 6 # GLUT initialization sub-API.
  227. {.push dynlib: dllname, importc.}
  228. proc glutInit*(argcp: ptr cint, argv: pointer)
  229. proc glutInit*() =
  230. ## version that passes `argc` and `argc` implicitely.
  231. var
  232. cmdLine {.importc: "cmdLine".}: array[0..255, cstring]
  233. cmdCount {.importc: "cmdCount".}: cint
  234. glutInit(addr(cmdCount), addr(cmdLine))
  235. proc glutInitDisplayMode*(mode: int16)
  236. proc glutInitDisplayString*(str: cstring)
  237. proc glutInitWindowPosition*(x, y: int)
  238. proc glutInitWindowSize*(width, height: int)
  239. proc glutMainLoop*()
  240. # GLUT window sub-API.
  241. proc glutCreateWindow*(title: cstring): int
  242. proc glutCreateSubWindow*(win, x, y, width, height: int): int
  243. proc glutDestroyWindow*(win: int)
  244. proc glutPostRedisplay*()
  245. proc glutPostWindowRedisplay*(win: int)
  246. proc glutSwapBuffers*()
  247. proc glutSetWindow*(win: int)
  248. proc glutSetWindowTitle*(title: cstring)
  249. proc glutSetIconTitle*(title: cstring)
  250. proc glutPositionWindow*(x, y: int)
  251. proc glutReshapeWindow*(width, height: int)
  252. proc glutPopWindow*()
  253. proc glutPushWindow*()
  254. proc glutIconifyWindow*()
  255. proc glutShowWindow*()
  256. proc glutHideWindow*()
  257. proc glutFullScreen*()
  258. proc glutSetCursor*(cursor: int)
  259. proc glutWarpPointer*(x, y: int)
  260. # GLUT overlay sub-API.
  261. proc glutEstablishOverlay*()
  262. proc glutRemoveOverlay*()
  263. proc glutUseLayer*(layer: GLenum)
  264. proc glutPostOverlayRedisplay*()
  265. proc glutPostWindowOverlayRedisplay*(win: int)
  266. proc glutShowOverlay*()
  267. proc glutHideOverlay*()
  268. # GLUT menu sub-API.
  269. proc glutCreateMenu*(callback: TGlut1IntCallback): int
  270. proc glutDestroyMenu*(menu: int)
  271. proc glutSetMenu*(menu: int)
  272. proc glutAddMenuEntry*(caption: cstring, value: int)
  273. proc glutAddSubMenu*(caption: cstring, submenu: int)
  274. proc glutChangeToMenuEntry*(item: int, caption: cstring, value: int)
  275. proc glutChangeToSubMenu*(item: int, caption: cstring, submenu: int)
  276. proc glutRemoveMenuItem*(item: int)
  277. proc glutAttachMenu*(button: int)
  278. proc glutDetachMenu*(button: int)
  279. # GLUT window callback sub-API.
  280. proc glutDisplayFunc*(f: TGlutVoidCallback)
  281. proc glutReshapeFunc*(f: TGlut2IntCallback)
  282. proc glutKeyboardFunc*(f: TGlut1Char2IntCallback)
  283. proc glutMouseFunc*(f: TGlut4IntCallback)
  284. proc glutMotionFunc*(f: TGlut2IntCallback)
  285. proc glutPassiveMotionFunc*(f: TGlut2IntCallback)
  286. proc glutEntryFunc*(f: TGlut1IntCallback)
  287. proc glutVisibilityFunc*(f: TGlut1IntCallback)
  288. proc glutIdleFunc*(f: TGlutVoidCallback)
  289. proc glutTimerFunc*(millis: int16, f: TGlut1IntCallback, value: int)
  290. proc glutMenuStateFunc*(f: TGlut1IntCallback)
  291. proc glutSpecialFunc*(f: TGlut3IntCallback)
  292. proc glutSpaceballMotionFunc*(f: TGlut3IntCallback)
  293. proc glutSpaceballRotateFunc*(f: TGlut3IntCallback)
  294. proc glutSpaceballButtonFunc*(f: TGlut2IntCallback)
  295. proc glutButtonBoxFunc*(f: TGlut2IntCallback)
  296. proc glutDialsFunc*(f: TGlut2IntCallback)
  297. proc glutTabletMotionFunc*(f: TGlut2IntCallback)
  298. proc glutTabletButtonFunc*(f: TGlut4IntCallback)
  299. proc glutMenuStatusFunc*(f: TGlut3IntCallback)
  300. proc glutOverlayDisplayFunc*(f: TGlutVoidCallback)
  301. proc glutWindowStatusFunc*(f: TGlut1IntCallback)
  302. proc glutKeyboardUpFunc*(f: TGlut1Char2IntCallback)
  303. proc glutSpecialUpFunc*(f: TGlut3IntCallback)
  304. proc glutJoystickFunc*(f: TGlut1UInt3IntCallback, pollInterval: int)
  305. # GLUT color index sub-API.
  306. proc glutSetColor*(cell: int, red, green, blue: GLfloat)
  307. proc glutGetColor*(ndx, component: int): GLfloat
  308. proc glutCopyColormap*(win: int)
  309. # GLUT state retrieval sub-API.
  310. # GLUT extension support sub-API
  311. proc glutExtensionSupported*(name: cstring): int
  312. # GLUT font sub-API
  313. proc glutBitmapCharacter*(font: pointer, character: int)
  314. proc glutBitmapWidth*(font: pointer, character: int): int
  315. proc glutStrokeCharacter*(font: pointer, character: int)
  316. proc glutStrokeWidth*(font: pointer, character: int): int
  317. proc glutBitmapLength*(font: pointer, str: cstring): int
  318. proc glutStrokeLength*(font: pointer, str: cstring): int
  319. # GLUT pre-built models sub-API
  320. proc glutWireSphere*(radius: GLdouble, slices, stacks: GLint)
  321. proc glutSolidSphere*(radius: GLdouble, slices, stacks: GLint)
  322. proc glutWireCone*(base, height: GLdouble, slices, stacks: GLint)
  323. proc glutSolidCone*(base, height: GLdouble, slices, stacks: GLint)
  324. proc glutWireCube*(size: GLdouble)
  325. proc glutSolidCube*(size: GLdouble)
  326. proc glutWireTorus*(innerRadius, outerRadius: GLdouble, sides, rings: GLint)
  327. proc glutSolidTorus*(innerRadius, outerRadius: GLdouble, sides, rings: GLint)
  328. proc glutWireDodecahedron*()
  329. proc glutSolidDodecahedron*()
  330. proc glutWireTeapot*(size: GLdouble)
  331. proc glutSolidTeapot*(size: GLdouble)
  332. proc glutWireOctahedron*()
  333. proc glutSolidOctahedron*()
  334. proc glutWireTetrahedron*()
  335. proc glutSolidTetrahedron*()
  336. proc glutWireIcosahedron*()
  337. proc glutSolidIcosahedron*()
  338. # GLUT video resize sub-API.
  339. proc glutVideoResizeGet*(param: GLenum): int
  340. proc glutSetupVideoResizing*()
  341. proc glutStopVideoResizing*()
  342. proc glutVideoResize*(x, y, width, height: int)
  343. proc glutVideoPan*(x, y, width, height: int)
  344. # GLUT debugging sub-API.
  345. proc glutReportErrors*()
  346. # GLUT device control sub-API.
  347. proc glutIgnoreKeyRepeat*(ignore: int)
  348. proc glutSetKeyRepeat*(repeatMode: int)
  349. proc glutForceJoystickFunc*()
  350. # GLUT game mode sub-API.
  351. #example glutGameModeString('1280x1024:32@75');
  352. proc glutGameModeString*(AString: cstring)
  353. proc glutLeaveGameMode*()
  354. proc glutGameModeGet*(mode: GLenum): int
  355. # implementation
  356. {.pop.} # dynlib: dllname, importc