gl_linux.tpl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. {
  2. $Id$
  3. Translation of the Mesa GL, GLU and GLX headers for Free Pascal, Linux version
  4. Copyright (C) 1999-2000 Sebastian Guenther, [email protected]
  5. Mesa 3-D graphics library
  6. Version: 3.1
  7. Copyright (C) 1999 Brian Paul All Rights Reserved.
  8. Permission is hereby granted, free of charge, to any person obtaining a
  9. copy of this software and associated documentation files (the "Software"),
  10. to deal in the Software without restriction, including without limitation
  11. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. and/or sell copies of the Software, and to permit persons to whom the
  13. Software is furnished to do so, subject to the following conditions:
  14. The above copyright notice and this permission notice shall be included
  15. in all copies or substantial portions of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. }
  23. unit GL;
  24. {$MODE delphi} // objfpc would not work because of direct proc var assignments
  25. interface
  26. uses X, XLib, XUtil;
  27. // ===================================================================
  28. // Unit specific extensions
  29. // ===================================================================
  30. function InitGLFromLibrary(const libname: PChar): Boolean;
  31. function InitGLUFromLibrary(const libname: PChar): Boolean;
  32. // Requires that the GL library has already been initialized:
  33. function InitGLX: Boolean;
  34. // determines automatically which libraries to use:
  35. function InitGL: Boolean;
  36. function InitGLU: Boolean;
  37. var
  38. GLInitialized, GLUInitialized, GLXInitialized: Boolean;
  39. { Set the following value to True if you want to have a list of all
  40. unresolved GL/GLU/GLX functions dumped to the console }
  41. GLDumpUnresolvedFunctions: Boolean;
  42. %GLDecls
  43. %GLProcs1
  44. const
  45. %GLExtDecls
  46. %GLExtProcs1
  47. %GLUDecls
  48. %GLUProcs1
  49. %GLXDecls
  50. %GLXProcs1
  51. // ===================================================================
  52. // ===================================================================
  53. implementation
  54. {$LINKLIB m}
  55. function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
  56. function dlclose(handle: Pointer): LongInt; external 'dl';
  57. function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
  58. function LoadLibrary(const name: PChar): Pointer;
  59. begin
  60. Result := dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY});
  61. end;
  62. function GetProc(handle: Pointer; const name: PChar): Pointer;
  63. begin
  64. Result := dlsym(handle, name);
  65. if not Assigned(Result) and GLDumpUnresolvedFunctions then
  66. WriteLn('Unresolved: ', name);
  67. end;
  68. var
  69. libGL, libGLU, libGLX: Pointer;
  70. function InitGLFromLibrary(const libname: PChar): Boolean;
  71. begin
  72. Result := False;
  73. libGL := LoadLibrary(libname);
  74. if not Assigned(libGL) then
  75. exit;
  76. %GLProcs2
  77. # // Extensions:
  78. #%GLExtProcs2
  79. GLInitialized := True;
  80. Result := True;
  81. end;
  82. function InitGLUFromLibrary(const libname: PChar): Boolean;
  83. begin
  84. Result := False;
  85. libGLU := LoadLibrary(libname);
  86. if not Assigned(libGLU) then
  87. exit;
  88. %GLUProcs2
  89. GLUInitialized := True;
  90. Result := True;
  91. end;
  92. function InitGLX: Boolean;
  93. begin
  94. Result := False;
  95. if not Assigned(libGL) then
  96. exit;
  97. %GLXProcs2
  98. GLXInitialized := True;
  99. Result := True;
  100. end;
  101. function InitGL: Boolean;
  102. begin
  103. Result := InitGLFromLibrary('libGL.so') or InitGLFromLibrary('libGL.so.1') or
  104. InitGLFromLibrary('libMesaGL.so.3');
  105. end;
  106. function InitGLU: Boolean;
  107. begin
  108. Result := InitGLUFromLibrary('libGLU.so') or
  109. InitGLUFromLibrary('libGLU.so.1') or InitGLUFromLibrary('libMesaGLU.so.3');
  110. end;
  111. finalization
  112. // Free all loaded libraries
  113. if Assigned(libGLX) then
  114. dlclose(libGLX);
  115. if Assigned(libGLU) then
  116. dlclose(libGLU);
  117. if Assigned(libGL) then
  118. dlclose(libGL);
  119. end.