gl_linux.tpl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. {
  2. $Id$
  3. Translation of the Mesa GL, GLU and GLX headers for Free Pascal
  4. Linux Version, 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. unit GL;
  22. interface
  23. uses XLib;
  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. %GLDecls
  37. %GLProcs1
  38. const
  39. %GLExtDecls
  40. %GLExtProcs1
  41. %GLUDecls
  42. %GLUProcs1
  43. %GLXDecls
  44. %GLXProcs1
  45. // ===================================================================
  46. // ===================================================================
  47. implementation
  48. {$LINKLIB m}
  49. function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
  50. function dlclose(handle: Pointer): LongInt; external 'dl';
  51. function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
  52. function LoadLibrary(name: PChar): Pointer;
  53. begin
  54. Result := dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY});
  55. end;
  56. function GetProc(handle: Pointer; name: PChar): Pointer;
  57. begin
  58. Result := dlsym(handle, name);
  59. if Result = nil then WriteLn('Unresolved: ', name);
  60. end;
  61. var
  62. libGL, libGLU, libGLX: Pointer;
  63. function InitGLFromLibrary(libname: PChar): Boolean;
  64. begin
  65. Result := False;
  66. libGL := LoadLibrary(libname);
  67. if not Assigned(libGL) then exit;
  68. %GLProcs2
  69. # // Extensions:
  70. #%GLExtProcs2
  71. GLInitialized := True;
  72. Result := True;
  73. end;
  74. function InitGLUFromLibrary(libname: PChar): Boolean;
  75. begin
  76. Result := False;
  77. libGLU := LoadLibrary(libname);
  78. if not Assigned(libGLU) then exit;
  79. %GLUProcs2
  80. GLUInitialized := True;
  81. Result := True;
  82. end;
  83. function InitGLX: Boolean;
  84. begin
  85. Result := False;
  86. if not Assigned(libGL) then exit;
  87. %GLXProcs2
  88. GLXInitialized := True;
  89. Result := True;
  90. end;
  91. function InitGL: Boolean;
  92. begin
  93. Result := InitGLFromLibrary('libGL.so') or InitGLFromLibrary('libMesaGL.so');
  94. end;
  95. function InitGLU: Boolean;
  96. begin
  97. Result := InitGLUFromLibrary('libGLU.so') or InitGLUFromLibrary('libMesaGLU.so');
  98. end;
  99. finalization
  100. if Assigned(libGL) then dlclose(libGL);
  101. if Assigned(libGLU) then dlclose(libGLU);
  102. if Assigned(libGLX) then dlclose(libGLX);
  103. end.