gl_linux.tpl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. {
  2. $Id$
  3. Translation of the Mesa GL, GLU and GLX headers for Free Pascal
  4. Linux Version, Copyright (C) 1999-2000 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. unit GL;
  22. interface
  23. uses X,XLib,XUtil;
  24. // ===================================================================
  25. // Unit specific extensions
  26. // ===================================================================
  27. function InitGLFromLibrary(libname: PChar): Boolean;
  28. function InitGLUFromLibrary(libname: PChar): Boolean;
  29. // Requires that the GL library has already been initialized:
  30. function InitGLX: Boolean;
  31. // determines automatically which libraries to use:
  32. function InitGL: Boolean;
  33. function InitGLU: Boolean;
  34. var
  35. GLInitialized, GLUInitialized, GLXInitialized: Boolean;
  36. { Set the following value to True if you want to have a list of all
  37. unresolved GL/GLU/GLX functions dumped to the console }
  38. GLDumpUnresolvedFunctions: Boolean;
  39. %GLDecls
  40. %GLProcs1
  41. const
  42. %GLExtDecls
  43. %GLExtProcs1
  44. %GLUDecls
  45. %GLUProcs1
  46. %GLXDecls
  47. %GLXProcs1
  48. // ===================================================================
  49. // ===================================================================
  50. implementation
  51. {$LINKLIB m}
  52. function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
  53. function dlclose(handle: Pointer): LongInt; external 'dl';
  54. function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
  55. function LoadLibrary(name: PChar): Pointer;
  56. begin
  57. Result := dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY});
  58. end;
  59. function GetProc(handle: Pointer; name: PChar): Pointer;
  60. begin
  61. Result := dlsym(handle, name);
  62. if not Assigned(Result) and GLDumpUnresolvedFunctions then
  63. WriteLn('Unresolved: ', name);
  64. end;
  65. var
  66. libGL, libGLU, libGLX: Pointer;
  67. function InitGLFromLibrary(libname: PChar): Boolean;
  68. begin
  69. Result := False;
  70. libGL := LoadLibrary(libname);
  71. if not Assigned(libGL) then exit;
  72. %GLProcs2
  73. # // Extensions:
  74. #%GLExtProcs2
  75. GLInitialized := True;
  76. Result := True;
  77. end;
  78. function InitGLUFromLibrary(libname: PChar): Boolean;
  79. begin
  80. Result := False;
  81. libGLU := LoadLibrary(libname);
  82. if not Assigned(libGLU) then exit;
  83. %GLUProcs2
  84. GLUInitialized := True;
  85. Result := True;
  86. end;
  87. function InitGLX: Boolean;
  88. begin
  89. Result := False;
  90. if not Assigned(libGL) then exit;
  91. %GLXProcs2
  92. GLXInitialized := True;
  93. Result := True;
  94. end;
  95. function InitGL: Boolean;
  96. begin
  97. Result := InitGLFromLibrary('libGL.so') or InitGLFromLibrary('libGL.so.1') or
  98. InitGLFromLibrary('libMesaGL.so.3');
  99. end;
  100. function InitGLU: Boolean;
  101. begin
  102. Result := InitGLUFromLibrary('libGLU.so') or
  103. InitGLUFromLibrary('libGLU.so.1') or InitGLUFromLibrary('libMesaGLU.so.3');
  104. end;
  105. finalization
  106. if Assigned(libGL) then dlclose(libGL);
  107. if Assigned(libGLU) then dlclose(libGLU);
  108. if Assigned(libGLX) then dlclose(libGLX);
  109. end.