freeglut.pp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. { FreeGlut extensions, see http://freeglut.sourceforge.net/ .
  2. Complements the Glut unit that defines standard Glut functionality.
  3. Function entry points will be nil if freeglut is not
  4. actually available (or if freeglut version necessary for specific extension
  5. is not available).
  6. Includes all the extensions up to FreeGlut 2.6.0 version.
  7. Omitted is only deprecated stuff, and glutGetProcAddress
  8. (which is not needed as we have nice glext unit in FPC). }
  9. {$IFNDEF FPC_DOTTEDUNITS}
  10. unit FreeGlut;
  11. {$ENDIF FPC_DOTTEDUNITS}
  12. {$mode Delphi} {< to keep assignments to proc vars look the same as in glut.pp }
  13. {$MACRO ON}
  14. { Keep this synched with glut.pp "extdecl" definition. }
  15. {$IFDEF Windows}
  16. {$DEFINE extdecl := stdcall}
  17. {$ELSE}
  18. {$DEFINE extdecl := cdecl}
  19. {$ENDIF}
  20. interface
  21. {$IFDEF FPC_DOTTEDUNITS}
  22. uses System.DynLibs, Api.OpenGL.Gl, Api.OpenGL.Glut;
  23. {$ELSE FPC_DOTTEDUNITS}
  24. uses DynLibs, GL, Glut;
  25. {$ENDIF FPC_DOTTEDUNITS}
  26. type
  27. TGLdouble3 = array [0..2] of GLdouble;
  28. PGLdouble3 = ^TGLdouble3;
  29. const
  30. // Additional GLUT Key definitions for the Special key function
  31. GLUT_KEY_NUM_LOCK = $006D;
  32. GLUT_KEY_BEGIN = $006E;
  33. GLUT_KEY_DELETE = $006F;
  34. // GLUT API Extension macro definitions -- behaviour when the user clicks on an "x" to close a window
  35. GLUT_ACTION_EXIT = 0;
  36. GLUT_ACTION_GLUTMAINLOOP_RETURNS = 1;
  37. GLUT_ACTION_CONTINUE_EXECUTION = 2;
  38. // Create a new rendering context when the user opens a new window?
  39. GLUT_CREATE_NEW_CONTEXT = 0;
  40. GLUT_USE_CURRENT_CONTEXT = 1;
  41. // Direct/Indirect rendering context options (has meaning only in Unix/X11)
  42. GLUT_FORCE_INDIRECT_CONTEXT = 0;
  43. GLUT_ALLOW_DIRECT_CONTEXT = 1;
  44. GLUT_TRY_DIRECT_CONTEXT = 2;
  45. GLUT_FORCE_DIRECT_CONTEXT = 3;
  46. // GLUT API Extension macro definitions -- the glutGet parameters
  47. GLUT_INIT_STATE = $007C;
  48. GLUT_ACTION_ON_WINDOW_CLOSE = $01F9;
  49. GLUT_WINDOW_BORDER_WIDTH = $01FA;
  50. GLUT_WINDOW_HEADER_HEIGHT = $01FB;
  51. GLUT_VERSION = $01FC;
  52. GLUT_RENDERING_CONTEXT = $01FD;
  53. GLUT_DIRECT_RENDERING = $01FE;
  54. GLUT_FULL_SCREEN = $01FF;
  55. // New tokens for glutInitDisplayMode.
  56. // Only one GLUT_AUXn bit may be used at a time.
  57. // Value 0x0400 is defined in OpenGLUT.
  58. GLUT_AUX = $1000;
  59. GLUT_AUX1 = $1000;
  60. GLUT_AUX2 = $2000;
  61. GLUT_AUX3 = $4000;
  62. GLUT_AUX4 = $8000;
  63. // Context-related flags
  64. GLUT_INIT_MAJOR_VERSION = $0200;
  65. GLUT_INIT_MINOR_VERSION = $0201;
  66. GLUT_INIT_FLAGS = $0202;
  67. GLUT_INIT_PROFILE = $0203;
  68. // Flags for glutInitContextFlags
  69. GLUT_DEBUG = $0001;
  70. GLUT_FORWARD_COMPATIBLE = $0002;
  71. // Flags for glutInitContextProfile
  72. GLUT_CORE_PROFILE = $0001;
  73. GLUT_COMPATIBILITY_PROFILE = $0002;
  74. // GLUT API macro definitions -- the display mode definitions
  75. GLUT_CAPTIONLESS = $0400;
  76. GLUT_BORDERLESS = $0800;
  77. GLUT_SRGB = $1000;
  78. var
  79. // Process loop function
  80. glutMainLoopEvent: procedure; extdecl;
  81. glutLeaveMainLoop: procedure; extdecl;
  82. glutExit: procedure; extdecl;
  83. // Window management functions
  84. glutFullScreenToggle: procedure; extdecl;
  85. // Window-specific callback functions
  86. glutMouseWheelFunc: procedure(callback: TGlut4IntCallback); extdecl;
  87. glutCloseFunc: procedure(callback: TGlutVoidCallback); extdecl;
  88. // A. Donev: Also a destruction callback for menus
  89. glutMenuDestroyFunc: procedure(callback: TGlutVoidCallback); extdecl;
  90. // State setting and retrieval functions
  91. glutSetOption: procedure(option_flag: GLenum; value: Integer); extdecl;
  92. glutGetModeValues: function(mode: GLenum; size: PInteger): Integer; extdecl;
  93. // A.Donev: User-data manipulation
  94. glutGetWindowData: function: Pointer; extdecl;
  95. glutSetWindowData: procedure(data: Pointer); extdecl;
  96. glutGetMenuData: function: Pointer; extdecl;
  97. glutSetMenuData: procedure(data: Pointer); extdecl;
  98. // Font stuff
  99. glutBitmapHeight: function(font : pointer): Integer; extdecl;
  100. glutStrokeHeight: function(font : pointer): GLfloat; extdecl;
  101. glutBitmapString: procedure(font : pointer; const str: PAnsiChar); extdecl;
  102. glutStrokeString: procedure(font : pointer; const str: PAnsiChar); extdecl;
  103. // Geometry functions
  104. glutWireRhombicDodecahedron: procedure; extdecl;
  105. glutSolidRhombicDodecahedron: procedure; extdecl;
  106. glutWireSierpinskiSponge: procedure(num_levels: Integer; offset: PGLdouble3; scale: GLdouble); extdecl;
  107. glutSolidSierpinskiSponge: procedure(num_levels: Integer; offset: PGLdouble3; scale: GLdouble); extdecl;
  108. glutWireCylinder: procedure(radius: GLdouble; height: GLdouble; slices: GLint; stacks: GLint); extdecl;
  109. glutSolidCylinder: procedure(radius: GLdouble; height: GLdouble; slices: GLint; stacks: GLint); extdecl;
  110. // Initialization functions
  111. glutInitContextVersion: procedure(majorVersion: Integer; minorVersion: Integer); extdecl;
  112. glutInitContextFlags: procedure(flags: Integer); extdecl;
  113. glutInitContextProfile: procedure(profile: Integer); extdecl;
  114. { Load all freeglut functions from given library.
  115. Called automatically from Glut unit when standard Glut stuff is loaded. }
  116. procedure LoadFreeGlut(hDLL: TLibHandle);
  117. { Set to nil all freeglut functions.
  118. Called automatically from Glut unit when standard Glut stuff is unloaded. }
  119. procedure UnloadFreeGlut;
  120. implementation
  121. procedure LoadFreeGlut(hDLL: TLibHandle);
  122. begin
  123. @glutMainLoopEvent := GetProcAddress(hDLL, 'glutMainLoopEvent');
  124. @glutLeaveMainLoop := GetProcAddress(hDLL, 'glutLeaveMainLoop');
  125. @glutExit := GetProcAddress(hDLL, 'glutExit');
  126. @glutFullScreenToggle := GetProcAddress(hDLL, 'glutFullScreenToggle');
  127. @glutMouseWheelFunc := GetProcAddress(hDLL, 'glutMouseWheelFunc');
  128. @glutCloseFunc := GetProcAddress(hDLL, 'glutCloseFunc');
  129. @glutMenuDestroyFunc := GetProcAddress(hDLL, 'glutMenuDestroyFunc');
  130. @glutSetOption := GetProcAddress(hDLL, 'glutSetOption');
  131. @glutGetModeValues := GetProcAddress(hDLL, 'glutGetModeValues');
  132. @glutGetWindowData := GetProcAddress(hDLL, 'glutGetWindowData');
  133. @glutSetWindowData := GetProcAddress(hDLL, 'glutSetWindowData');
  134. @glutGetMenuData := GetProcAddress(hDLL, 'glutGetMenuData');
  135. @glutSetMenuData := GetProcAddress(hDLL, 'glutSetMenuData');
  136. @glutBitmapHeight := GetProcAddress(hDLL, 'glutBitmapHeight');
  137. @glutStrokeHeight := GetProcAddress(hDLL, 'glutStrokeHeight');
  138. @glutBitmapString := GetProcAddress(hDLL, 'glutBitmapString');
  139. @glutStrokeString := GetProcAddress(hDLL, 'glutStrokeString');
  140. @glutWireRhombicDodecahedron := GetProcAddress(hDLL, 'glutWireRhombicDodecahedron');
  141. @glutSolidRhombicDodecahedron := GetProcAddress(hDLL, 'glutSolidRhombicDodecahedron');
  142. @glutWireSierpinskiSponge := GetProcAddress(hDLL, 'glutWireSierpinskiSponge');
  143. @glutSolidSierpinskiSponge := GetProcAddress(hDLL, 'glutSolidSierpinskiSponge');
  144. @glutWireCylinder := GetProcAddress(hDLL, 'glutWireCylinder');
  145. @glutSolidCylinder := GetProcAddress(hDLL, 'glutSolidCylinder');
  146. @glutInitContextVersion := GetProcAddress(hDLL, 'glutInitContextVersion');
  147. @glutInitContextFlags := GetProcAddress(hDLL, 'glutInitContextFlags');
  148. @glutInitContextProfile := GetProcAddress(hDLL, 'glutInitContextProfile');
  149. end;
  150. procedure UnloadFreeGlut;
  151. begin
  152. @glutMainLoopEvent := nil;
  153. @glutLeaveMainLoop := nil;
  154. @glutExit := nil;
  155. @glutFullScreenToggle := nil;
  156. @glutMouseWheelFunc := nil;
  157. @glutCloseFunc := nil;
  158. @glutMenuDestroyFunc := nil;
  159. @glutSetOption := nil;
  160. @glutGetModeValues := nil;
  161. @glutGetWindowData := nil;
  162. @glutSetWindowData := nil;
  163. @glutGetMenuData := nil;
  164. @glutSetMenuData := nil;
  165. @glutBitmapHeight := nil;
  166. @glutStrokeHeight := nil;
  167. @glutBitmapString := nil;
  168. @glutStrokeString := nil;
  169. @glutWireRhombicDodecahedron := nil;
  170. @glutSolidRhombicDodecahedron := nil;
  171. @glutWireSierpinskiSponge := nil;
  172. @glutSolidSierpinskiSponge := nil;
  173. @glutWireCylinder := nil;
  174. @glutSolidCylinder := nil;
  175. @glutInitContextVersion := nil;
  176. @glutInitContextFlags := nil;
  177. @glutInitContextProfile := nil;
  178. end;
  179. end.