gl_linux.tem 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 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. %GLDeclsIF
  37. %GLProcsPD
  38. %GLExtDeclsIF
  39. %GLExtProcsPD
  40. %GLUDeclsIF
  41. %GLUProcsPD
  42. %GLXDeclsIF
  43. %GLXProcsPD
  44. // ===================================================================
  45. // ===================================================================
  46. implementation
  47. {$LINKLIB m}
  48. function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
  49. function dlclose(handle: Pointer): LongInt; external 'dl';
  50. function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
  51. function LoadLibrary(name: PChar): Pointer;
  52. begin
  53. Result := dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY});
  54. end;
  55. function GetProc(handle: Pointer; name: PChar): Pointer;
  56. begin
  57. Result := dlsym(handle, name);
  58. if Result = nil then WriteLn('Unresolved: ', name);
  59. end;
  60. var
  61. libGL, libGLU, libGLX: Pointer;
  62. function InitGLFromLibrary(libname: PChar): Boolean;
  63. begin
  64. Result := False;
  65. libGL := LoadLibrary(libname);
  66. if not Assigned(libGL) then exit;
  67. %GLProcsPL
  68. # // Extensions:
  69. #%GLExtProcs2
  70. GLInitialized := True;
  71. Result := True;
  72. end;
  73. function InitGLUFromLibrary(libname: PChar): Boolean;
  74. begin
  75. Result := False;
  76. libGLU := LoadLibrary(libname);
  77. if not Assigned(libGLU) then exit;
  78. %GLUProcsPL
  79. GLUInitialized := True;
  80. Result := True;
  81. end;
  82. function InitGLX: Boolean;
  83. begin
  84. Result := False;
  85. if not Assigned(libGL) then exit;
  86. %GLXProcsPL
  87. GLXInitialized := True;
  88. Result := True;
  89. end;
  90. function InitGL: Boolean;
  91. begin
  92. Result := InitGLFromLibrary('libGL.so.1') or InitGLFromLibrary('libMesaGL.so.1');
  93. end;
  94. function InitGLU: Boolean;
  95. begin
  96. Result := InitGLUFromLibrary('libGLU.so.1') or InitGLUFromLibrary('libMesaGLU.so.1');
  97. end;
  98. finalization
  99. if Assigned(libGL) then dlclose(libGL);
  100. if Assigned(libGLU) then dlclose(libGLU);
  101. if Assigned(libGLX) then dlclose(libGLX);
  102. end.