glx_linux.tem 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. {
  2. $Id$
  3. Translation of the Mesa GLX 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 GLX;
  25. interface
  26. {$MACRO ON}
  27. {$IFDEF Linux}
  28. uses
  29. X, XLib, XUtil;
  30. {$DEFINE HasGLX} // Activate GLX stuff
  31. {$ELSE}
  32. {$MESSAGE Unsupported platform.}
  33. {$ENDIF}
  34. {$IFNDEF HasGLX}
  35. {$MESSAGE GLX not present on this platform.}
  36. {$ENDIF}
  37. // =======================================================
  38. // Unit specific extensions
  39. // =======================================================
  40. // Note: Requires that the GL library has already been initialized
  41. function InitGLX: Boolean;
  42. var
  43. GLXDumpUnresolvedFunctions,
  44. GLXInitialized: Boolean;
  45. // =======================================================
  46. // GLX consts, types and functions
  47. // =======================================================
  48. %GLXDeclsIF
  49. var
  50. %GLXProcsPD
  51. // =======================================================
  52. //
  53. // =======================================================
  54. implementation
  55. {$LINKLIB m}
  56. function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
  57. function dlclose(handle: Pointer): LongInt; external 'dl';
  58. function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
  59. function LoadLibrary(name: PChar): Pointer;
  60. begin
  61. Result := dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY});
  62. end;
  63. function GetProc(handle: Pointer; name: PChar): Pointer;
  64. begin
  65. Result := dlsym(handle, name);
  66. if (Result = nil) and GLXDumpUnresolvedFunctions then
  67. WriteLn('Unresolved: ', name);
  68. end;
  69. var
  70. libGLX: Pointer;
  71. function InitGLXFromLibrary(libname:pchar): Boolean;
  72. begin
  73. Result := False;
  74. libGLX := LoadLibrary(libname);
  75. if not Assigned(libGLX) then exit;
  76. %GLXProcsPL
  77. GLXInitialized := True;
  78. Result := True;
  79. end;
  80. function InitGLX: Boolean;
  81. begin
  82. Result := InitGLXFromLibrary('libGL.so') or
  83. InitGLXFromLibrary('libGL.so.1') or
  84. InitGLXFromLibrary('libMesaGL.so') or
  85. InitGLXFromLibrary('libMesaGL.so.3');
  86. end;
  87. initialization
  88. InitGLX;
  89. finalization
  90. if Assigned(libGLX) then dlclose(libGLX);
  91. end.
  92. {
  93. $Log$
  94. Revision 1.1 2000-09-03 21:25:45 peter
  95. * new updated version
  96. * gtkglarea unit and demo
  97. * win32 opengl headers
  98. * morph3d demo
  99. Revision 1.1 2000/07/13 06:34:18 michael
  100. + Initial import
  101. Revision 1.1 2000/05/31 00:36:08 alex
  102. dummy - incomplete code.
  103. }