glut_linux.tem 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. {
  2. $Id$
  3. Translation of the Mesa GLUT headers for FreePascal
  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}
  21. unit GLUT;
  22. interface
  23. {$MACRO ON}
  24. {$IFDEF Linux}
  25. {$DEFINE gldecl := cdecl;}
  26. {$DEFINE extdecl := cdecl;}
  27. uses GL;
  28. {$ELSE}
  29. {$MESSAGE Unsupported platform.}
  30. {$ENDIF}
  31. function InitGLUTFromLibrary(libname: PChar): Boolean;
  32. // determines automatically which library to use:
  33. function InitGLUT: Boolean;
  34. var
  35. GLUTDumpUnresolvedFunctions,
  36. GLUTInitialized: Boolean;
  37. %GLUTDeclsIF
  38. var
  39. %GLUTProcsPD
  40. implementation
  41. {$LINKLIB Xmu}
  42. function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
  43. function dlclose(handle: Pointer): LongInt; external 'dl';
  44. function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
  45. function LoadLibrary(name: PChar): Pointer;
  46. begin
  47. Result := dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY});
  48. end;
  49. function GetProc(handle: Pointer; name: PChar): Pointer;
  50. begin
  51. Result := dlsym(handle, name);
  52. if (Result = nil) and GLUTDumpUnresolvedFunctions then
  53. WriteLn('Unresolved: ', name);
  54. end;
  55. var
  56. libGLUT: Pointer;
  57. function InitGLUTFromLibrary(libname: PChar): Boolean;
  58. begin
  59. Result := False;
  60. libGLUT := LoadLibrary(libname);
  61. if not Assigned(libGLUT) then exit;
  62. %GLUTProcsPL
  63. GLUTInitialized := True;
  64. Result := True;
  65. end;
  66. function InitGLUT: Boolean;
  67. begin
  68. Result := InitGLUTFromLibrary('libglut.so') or
  69. InitGLUTFromLibrary('libglut.so.3');
  70. end;
  71. initialization
  72. InitGLUT;
  73. finalization
  74. if Assigned(libGLUT) then dlClose(libGLUT);
  75. end.