gl_linux.tem 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. {
  2. $Id$
  3. Translation of the Mesa GL headers for FreePascal
  4. Copyright (C) 1999 Sebastian Guenther
  5. Mesa 3-D graphics library
  6. Version: 3.0
  7. Copyright (C) 1995-1998 Brian Paul
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public
  10. License as published by the Free Software Foundation; either
  11. version 2 of the License, or (at your option) any later version.
  12. This library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Library General Public License for more details.
  16. You should have received a copy of the GNU Library General Public
  17. License along with this library; if not, write to the Free
  18. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. }
  20. {$MODE delphi} // objfpc would not work because of direct proc var assignments
  21. {You have to enable Macros (compiler switch "-Sm") for compiling this unit!
  22. This is necessary for supporting different platforms with different calling
  23. conventions via a single unit.}
  24. unit GL;
  25. interface
  26. {$DEFINE GL1_0}
  27. {$DEFINE GL1_1}
  28. {$DEFINE GL1_2}
  29. {$DEFINE MESA} {enable if you want to use some special mesa extensions}
  30. {$DEFINE EXTENSIONS} {enable if you need one/all of extensions}
  31. {$DEFINE SGI_EXTENSIONS} {enable if you need one/all of extensions}
  32. {$MACRO ON}
  33. {$IFDEF Linux}
  34. {$LINKLIB c}
  35. {$ELSE}
  36. {$MESSAGE Unsupported platform.}
  37. {$ENDIF}
  38. // =======================================================
  39. // Unit specific extensions
  40. // =======================================================
  41. function InitGLFromLibrary(libname: PChar): Boolean;
  42. // determines automatically which libraries to use:
  43. function InitGL: Boolean;
  44. var
  45. GLDumpUnresolvedFunctions,
  46. GLInitialized: Boolean;
  47. // =======================================================
  48. // GL consts, types and functions
  49. // =======================================================
  50. // -------------------------------------------------------
  51. // GL types
  52. // -------------------------------------------------------
  53. type
  54. PSingle = ^Single;
  55. PDouble = ^Double;
  56. GLvoid = Pointer;
  57. GLboolean = Byte;
  58. GLbyte = ShortInt; // 1-byte signed
  59. GLshort = Integer; // 2-byte signed
  60. GLint = LongInt; // 4-byte signed
  61. GLubyte = Byte; // 1-byte unsigned
  62. GLushort = Word; // 2-byte unsigned
  63. GLuint = DWord; // 4-byte signed
  64. GLsizei = LongInt; // 4-byte signed
  65. GLfloat = Single; // single precision float
  66. GLclampf = Single; // single precision float in [0,1]
  67. GLdouble = Double; // double precision float
  68. GLclampd = Double; // double precision float in [0,1]
  69. GLenum = DWord;
  70. PGLBoolean = ^GLBoolean;
  71. PGLFloat = ^GLfloat;
  72. PGLDouble = ^GLDouble;
  73. type
  74. GLbitfield = DWord; { was an enum - no corresponding thing in pascal }
  75. const
  76. GL_CURRENT_BIT = $00000001;
  77. GL_POINT_BIT = $00000002;
  78. GL_LINE_BIT = $00000004;
  79. GL_POLYGON_BIT = $00000008;
  80. GL_POLYGON_STIPPLE_BIT= $00000010;
  81. GL_PIXEL_MODE_BIT = $00000020;
  82. GL_LIGHTING_BIT = $00000040;
  83. GL_FOG_BIT = $00000080;
  84. GL_DEPTH_BUFFER_BIT = $00000100;
  85. GL_ACCUM_BUFFER_BIT = $00000200;
  86. GL_STENCIL_BUFFER_BIT = $00000400;
  87. GL_VIEWPORT_BIT = $00000800;
  88. GL_TRANSFORM_BIT = $00001000;
  89. GL_ENABLE_BIT = $00002000;
  90. GL_COLOR_BUFFER_BIT = $00004000;
  91. GL_HINT_BIT = $00008000;
  92. GL_EVAL_BIT = $00010000;
  93. GL_LIST_BIT = $00020000;
  94. GL_TEXTURE_BIT = $00040000;
  95. GL_SCISSOR_BIT = $00080000;
  96. GL_ALL_ATTRIB_BITS = $000fffff;
  97. // -------------------------------------------------------
  98. // GL constants
  99. // -------------------------------------------------------
  100. {$IFDEF GL1_0}
  101. %GLDeclsIF10
  102. {$ENDIF GL1_0}
  103. {$IFDEF GL1_1}
  104. %GLDeclsIF11
  105. {$ENDIF GL1_1}
  106. {$IFDEF GL1_2}
  107. %GLDeclsIF12
  108. {$ENDIF GL1_2}
  109. const
  110. // Utility
  111. GL_VENDOR = $1F00;
  112. GL_RENDERER = $1F01;
  113. GL_VERSION = $1F02;
  114. GL_EXTENSIONS = $1F03;
  115. // Errors
  116. GL_INVALID_VALUE = $0501;
  117. GL_INVALID_ENUM = $0500;
  118. GL_INVALID_OPERATION = $0502;
  119. GL_STACK_OVERFLOW = $0503;
  120. GL_STACK_UNDERFLOW = $0504;
  121. GL_OUT_OF_MEMORY = $0505;
  122. // -------------------------------------------------------
  123. // GL extensions constants
  124. // -------------------------------------------------------
  125. {$IFDEF EXTENSIONS}
  126. %GLDeclsIF10Ext
  127. {$ENDIF EXTENSIONS}
  128. {$IFDEF SGI_EXTENSIONS}
  129. %GLDeclsIF10SGI
  130. {$ENDIF SGI_EXTENSIONS}
  131. {$IFDEF MESA}
  132. %GLDeclsIF10Mesa
  133. {$ENDIF MESA}
  134. // -------------------------------------------------------
  135. // GL procedures and functions
  136. // -------------------------------------------------------
  137. {$IFDEF GL1_0}
  138. var
  139. %GLProcsPD10
  140. {$ENDIF GL1_0}
  141. {$IFDEF GL1_1}
  142. var
  143. %GLProcsPD11
  144. {$ENDIF GL1_1}
  145. {$IFDEF GL1_2}
  146. var
  147. %GLProcsPD12
  148. {$ENDIF GL1_2}
  149. // -------------------------------------------------------
  150. // GL Extensions
  151. // -------------------------------------------------------
  152. {$IFDEF EXTENSIONS}
  153. var
  154. %GLProcsPD10Ext
  155. {$ENDIF EXTENSIONS}
  156. // library dependent extensions
  157. {$IFDEF SGI_EXTENSIONS}
  158. var
  159. %GLProcsPD10SGI
  160. {$ENDIF SGI_EXTENSIONS}
  161. {$ifdef MESA}
  162. var
  163. %GLProcsPD10Mesa
  164. {$endif MESA}
  165. // =======================================================
  166. // =======================================================
  167. implementation
  168. {$LINKLIB m}
  169. function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
  170. function dlclose(handle: Pointer): LongInt; external 'dl';
  171. function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
  172. function LoadLibrary(name: PChar): Pointer;
  173. begin
  174. Result := dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY});
  175. end;
  176. function GetProc(handle: Pointer; name: PChar): Pointer;
  177. begin
  178. Result := dlsym(handle, name);
  179. if (Result = nil) and GLDumpUnresolvedFunctions then
  180. WriteLn('Unresolved: ', name);
  181. end;
  182. var
  183. libGL : Pointer;
  184. function InitGLFromLibrary(libname: PChar): Boolean;
  185. begin
  186. Result := False;
  187. libGL := LoadLibrary(libname);
  188. if not Assigned(libGL) then exit;
  189. {$ifdef GL1_0}
  190. %GLProcsPL10
  191. {$endif GL1_0}
  192. {$ifdef GL1_1}
  193. %GLProcsPL11
  194. {$endif GL1_1}
  195. {$ifdef GL1_2}
  196. %GLProcsPL12
  197. {$endif GL1_2}
  198. {$ifdef EXTENSIONS}
  199. %GLProcsPL10Ext
  200. {$endif EXTENSIONS}
  201. {$ifdef SGI_EXTENSIONS}
  202. %GLProcsPL10SGI
  203. {$endif SGI_EXTENSIONS}
  204. {$ifdef MESA}
  205. %GLProcsPL10Mesa
  206. {$endif MESA}
  207. GLInitialized := True;
  208. Result := True;
  209. end;
  210. function InitGL: Boolean;
  211. begin
  212. Result := InitGLFromLibrary('libGL.so') or
  213. InitGLFromLibrary('libGL.so.1') or
  214. InitGLFromLibrary('libMesaGL.so') or
  215. InitGLFromLibrary('libMesaGL.so.3');
  216. end;
  217. initialization
  218. InitGL;
  219. finalization
  220. if Assigned(libGL) then dlclose(libGL);
  221. end.
  222. {
  223. $Log$
  224. Revision 1.1 2000-09-03 21:25:45 peter
  225. * new updated version
  226. * gtkglarea unit and demo
  227. * win32 opengl headers
  228. * morph3d demo
  229. Revision 1.1 2000/07/13 06:34:17 michael
  230. + Initial import
  231. Revision 1.2 2000/05/31 00:34:28 alex
  232. made templates work
  233. }