universal cross platform unit file generator

This commit is contained in:
alex 2000-05-26 09:22:39 +00:00
parent 9c20c3c839
commit 13d8d513b0
10 changed files with 4287 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
#
# Makefile.fpc for auto generation of OpenGL units
#
[targets]
units=buildgl
programs=c_gen
[require]
packages=fcl
[dirs]
fpcdir=../../..
[defaults]
defaultrule=all_units
[rules]
.PHONY: all_units linuxd w32d w32s
all_units: linuxd w32d w32s
linuxd: c_gen$(EXEEXT) ogl_lind.gen
c_gen ogl_lind.gen
w32d: c_gen$(EXEEXT) ogl_w32d.gen
c_gen ogl_w32d.gen
w32s: c_gen$(EXEEXT) ogl_w32s.gen
c_gen ogl_w32s.gen

View File

@ -0,0 +1,77 @@
{
$Id$
GL unit creation tool helpers
(c) 1999 Sebastian Guenther, sg@freepascal.org
}
{$MODE objfpc}
{$H+}
unit buildgl;
interface
uses SysUtils, Classes;
type
TDefReader = class
protected
FInterfaceBlock, FProcs: TStringList;
public
constructor Create(const Filename: String);
property InterfaceBlock: TStringList read FInterfaceBlock;
property Procs: TStringList read FProcs;
end;
implementation
constructor TDefReader.Create(const Filename: String);
type
TCurState = (stateNothing, stateCopyInterface, stateProcs);
var
f: Text;
s: String;
state: TCurState;
begin
state := stateNothing;
FInterfaceBlock := TStringList.Create;
FProcs := TStringList.Create;
Assign(f, Filename);
Reset(f);
while not EOF(f) do begin
ReadLn(f, s);
if Copy(s, 1, 1) = '#' then continue; // Skip comments
if s = '%COPY_INTERFACE' then
state := stateCopyInterface
else if s = '%PROCS' then
state := stateProcs
else if s = '%END' then
state := stateNothing
else
case state of
stateCopyInterface: InterfaceBlock.Add(s);
stateProcs: Procs.Add(s);
end;
end;
Close(f);
end;
end.
{
$Log$
Revision 1.1 2000-05-26 09:22:39 alex
universal cross platform unit file generator
Revision 1.1 1999/12/23 13:51:50 peter
* reorganized, it now doesn't depend on fcl anymore by default
Revision 1.1 1999/11/28 17:55:22 sg
* Added new unit generation tools and auto-generated GL units for Linux
}

View File

@ -0,0 +1,572 @@
{
unit generation tool
(C) 2000 Alexander Stohr, alexs@freepage.de
based upon the linux dynamic tool from Sebastian Guenther
with latest version "1.1 1999/12/23 13:51:50 peter"
}
{$MODE objfpc}
{$H-} { use normal strings }
(* do not enable! fpc bug with H+ *)
program c_gen;
uses
SysUtils,
Classes,
buildgl;
// =====================================================================
type
ptDefFile = ^tDefFile;
tDefFile = record
Name : String;
DefFile : TDefReader;
pNext : ptDefFile;
end;
ptSectionKey = ^tSectionKey;
tSectionKey = record
Keyword : String;
Rule : DWord;
pDefFile : ptDefFile;
Option2 : String;
pNext : ptSectionKey;
end;
// =====================================================================
const
verbose = 0; // change this for debugging
const
ST_NONE = 0;
ST_COMMON = 1;
ST_FILE = 2;
RULE_IG = 0;
RULE_TX = 1;
RULE_IF = 2;
RULE_PD = 3;
RULE_PL = 4;
RULE_PS = 5;
// =====================================================================
// global vars
var
ReturnVal : Word;
pSectionKey : ptSectionKey;
pAllDefFile : ptDefFile;
ToolName : String;
TargetText : String;
TargetDir : String;
SectionType : DWord;
SectionName : String;
TemplateName : String;
// =====================================================================
procedure StripSpaces(var s : String);
var
L : Byte;
begin
// strip leading spaces
while (Pos(' ',s)=1) or (Pos(#8,s)=1) do
Delete(s,1,1);
// strip trailing spaces
L := Length(s);
while L<>0 do
begin
if (s[L]=' ') or (s[L]=#8) then
begin
Delete(s,L,1);
Dec(L);
end
else
L := 0;
end;
end;
function GetName(var s : String) : String;
var
Name : String;
P : Byte;
begin
Name := s;
P := Pos(',',s);
if p>0 then
begin
Delete(s,1,P);
Delete(Name,P,255);
end
else
s := '';
StripSpaces(Name);
{ WriteLn('GetName, reminder = ',Name,',',s); }
GetName := Name;
end;
function Name2Rule(Name : String) : DWord;
begin
if Name='IG'
then Name2Rule := RULE_IG
else
if Name='TX'
then Name2Rule := RULE_TX
else
if Name='IF'
then Name2Rule := RULE_IF
else
if Name='PD'
then Name2Rule := RULE_PD
else
if Name='PL'
then Name2Rule := RULE_PL
else
if Name='PS'
then Name2Rule := RULE_PS
else
begin
Name2Rule := RULE_IG;
WriteLn('error - unknown rule: ',Name);
ReturnVal := 1;
end;
end;
function AddDefFile(Name : String) : ptDefFile;
var
pDefFile : ptDefFile;
pSearch : ptDefFile;
begin
pDefFile := NIL;
// search if file is already loaded
if pAllDefFile<>NIL then
begin
pSearch := pAllDefFile;
while pSearch<>NIL do
begin
if pSearch^.Name = Name then
begin
pDefFile := pSearch;
pSearch := NIL;
end
else
pSearch := pSearch^.pNext;
end;
end;
// create new file if its not loaded
if pDefFile = NIL then
begin
New(pDefFile);
pDefFile^.Name := Name;
pDefFile^.DefFile := TDefReader.Create(Name);
pDefFile^.pNext := pAllDefFile; // chain in as first member
pAllDefFile := pDefFile;
end;
AddDefFile := pDefFile;
end;
procedure AddSectionKey(s : string);
var
pKey : ptSectionKey;
t : string;
begin
New(pKey);
pKey^.Keyword := GetName(s);
pKey^.Rule := Name2Rule(GetName(s));
pKey^.pDefFile := AddDefFile(GetName(s));
t := GetName(s);
pKey^.Option2 := t;
pKey^.pNext := pSectionKey; // chain in as first member
pSectionKey := pKey;
end;
function GetSectionKey(s : string) : ptSectionKey;
var
pSearch : ptSectionKey;
begin
GetSectionKey := NIL;
pSearch := pSectionKey;
while pSearch<>NIL do
begin
if pSearch^.Keyword = s then
begin
GetSectionKey := pSearch;
pSearch := NIL;
end
else pSearch := pSearch^.pNext;
end;
end;
procedure FreeSectionKeys;
var
pSearch, pNext : ptSectionKey;
begin
pSearch := pSectionKey;
while pSearch<>NIL do
begin
pNext := pSearch^.pNext;
Dispose(pSearch);
pSearch := pNext;
end;
pSectionKey := pSearch;
end;
// =====================================================================
procedure ResetCommonSecData;
begin
ToolName := 'BuildTool';
TargetText := 'unknown';
TargetDir := '.\';
end;
procedure ResetFileSecData;
begin
FreeSectionKeys;
TemplateName := '';
end;
procedure InitGlobals;
begin
ReturnVal := 0;
SectionType := ST_NONE;
pSectionKey := NIL;
pAllDefFile := NIL;
ResetCommonSecData;
ResetFileSecData;
end;
// =====================================================================
procedure PrintInterface(var dest: Text; lines: TStringList);
var
i: Integer;
begin
for i := 0 to lines.Count - 1 do
WriteLn(dest, lines.Strings[i]);
end;
procedure PrintProcDecls(var dest: Text; procs: TStringList; const Modifier : String);
var
i, j: Integer;
s: String;
begin
for i := 0 to procs.Count - 1 do
begin
s := procs.Strings[i];
j := Pos('//', s);
if (Length(s) = 0) or ((j > 0) and (Trim(s)[1] = '/')) then
WriteLn(dest, s)
else if j = 0 then
WriteLn(dest, s, ' ',Modifier)
else
WriteLn(dest, TrimRight(Copy(s, 1, j-1)),
' ',Modifier,' ', Copy(s, j, Length(s)) );
end;
end;
procedure PrintProcLoaders(var dest: Text; procs: TStringList; const libname: String);
var
i, j: Integer;
s: String;
begin
for i := 0 to procs.Count - 1 do
begin
s := Trim(procs.Strings[i]);
j := Pos(':', s);
s := Trim(Copy(s, 1, j - 1));
if (Length(s) = 0) or (Pos('//', s) > 0) then continue;
WriteLn(dest, ' ', s, ' := GetProc(', libname, ', ''', s, ''');');
end;
end;
procedure PrintProcStatic(var dest: Text; procs: TStringList; const Modifier: String);
var
i, j: Integer;
s: String;
t: String;
begin
for i := 0 to procs.Count - 1 do
begin
s := procs.Strings[i];
j := Pos('//', s);
if (Length(s) = 0) or ((j > 0) and (Trim(s)[1] = '/')) then
WriteLn(dest, s)
else
begin
// swap order of leading symbols and remove ':'
t := Trim(procs.Strings[i]);
j := Pos(':', s);
t := Trim(Copy(t, 1, j - 1));
Delete(s,1,j);
s := Trim(s);
j := Pos('(', s);
Insert(t,s,j);
Insert(' ',s,j);
j := Pos('//', s);
if j = 0 then
WriteLn(dest, s, ' ',Modifier)
else
WriteLn(dest, TrimRight(Copy(s, 1, j-1)),
' ',Modifier,' ', Copy(s, j, Length(s)) );
end;
end;
end;
procedure PrintCVSLogSection(var dest: Text);
begin
WriteLn(dest);
WriteLn(dest);
WriteLn(dest, '{');
WriteLn(dest, ' $', 'Log:$'); // needed because _this_ file might be in CVS, too
WriteLn(dest, '}');
end;
// =====================================================================
procedure ProcessFileSection;
var
f : Text;
tpl : Text;
s : String;
{ j : Integer; }
tmp : String;
pKey : ptSectionKey;
begin
WriteLn('Generating "',TargetDir+SectionName,'" ...');
Assign(f, TargetDir+SectionName);
Rewrite(f);
Assign(tpl, TemplateName);
Reset(tpl);
while not EOF(tpl) do
begin
ReadLn(tpl, s);
if Copy(s, 1, 1) = '%' then
begin
tmp := Copy(s,2,255);
StripSpaces(tmp);
pKey := GetSectionKey(tmp);
if pKey=NIL then
begin
WriteLn(f, '// ### ',ToolName,': Don''t know what to insert here!: ', s);
WriteLn('error - unknown keyword: ',tmp);
ReturnVal := 1;
end
else
begin
case pKey^.Rule of
RULE_IG : { ignore };
RULE_TX : { todo };
RULE_IF : PrintInterface(f, pKey^.pDefFile^.DefFile.InterfaceBlock);
RULE_PD : PrintProcDecls(f, pKey^.pDefFile^.DefFile.Procs,
pKey^.Option2);
RULE_PL : PrintProcLoaders(f, pKey^.pDefFile^.DefFile.Procs,
pKey^.Option2);
RULE_PS : PrintProcStatic(f, pKey^.pDefFile^.DefFile.Procs,
pKey^.Option2);
end;
end;
end
else
begin
if Copy(s, 1, 1) <> '#'
then WriteLn(f, s);
end;
end;
PrintCVSLogSection(f);
Close(f);
(*
if Copy(s, 1, 1) <> '#' then
begin
j := Pos('#extdecl', s);
if j = 0 then
WriteLn(f, s)
else
WriteLn(f, Copy(s, 1, j - 1), 'cdecl', Copy(s, j + 8, Length(s)));
end;
*)
end;
procedure ProcessCommonSection;
begin
if verbose>0 then
begin
WriteLn('common section:');
WriteLn(' ToolName = ',ToolName);
WriteLn(' TargetText = ',TargetText);
WriteLn(' TargetDir = ',TargetDir);
end;
end;
// =====================================================================
procedure SectionComplete;
begin
if ReturnVal=0 then { if we are error free }
case SectionType of
ST_NONE :
begin
// ignore
end;
ST_COMMON :
begin
ProcessCommonSection;
end;
ST_FILE :
begin
ProcessFileSection();
end;
end;
end;
var
hFGen : Text;
Line : String;
KeyName : String;
KeyValue : String;
begin
InitGlobals;
WriteLn('File Generator Tool for OpenGL related Units');
if ParamCount<>1 then
begin
WriteLn('specify a generator file as parameter 1');
Halt(1);
end;
// Open Generation File
Assign(hFGen,ParamStr(1));
Reset(hFGen);
while Not(EOF(hFGen)) do
begin
ReadLn(hFGen,Line);
if Length(Line)>0 then
begin
if Line[1]='[' then
begin
// its a new section
SectionComplete; // close previous section
Delete(Line,Pos(']',Line),255);
SectionName := Copy(Line,2,255);
if verbose>0 then
WriteLn('SectionName = ',SectionName);
if SectionName='common' then
begin
SectionType := ST_COMMON;
ResetCommonSecData;
end
else
begin
SectionType := ST_FILE;
ResetFileSecData;
end;
end
else
if Pos(Line[1],'#*;''')<>0 then
begin
// just a comment - ignore
end
else
begin
// its a key in the section
KeyName := Line;
KeyValue := Line;
Delete(KeyName,Pos('=',KeyName),255);
Delete(KeyValue,1,Pos('=',KeyValue));
StripSpaces(KeyName);
StripSpaces(KeyValue);
// WriteLn('KeyName = ',KeyName);
// WriteLn('KeyValue = ',KeyValue);
case SectionType of
ST_COMMON :
begin
if KeyName='TOOL_NAME'
then ToolName := KeyValue
else
if KeyName='TARGET_TEXT'
then TargetText := KeyValue
else
if KeyName='TARGET_DIR'
then TargetDir := KeyValue
else
begin
WriteLn('error in script file - inside common section');
WriteLn('key line: ',Line);
ReturnVal := 1;
end;
end;
ST_FILE :
begin
if KeyName='TEMPLATE'
then TemplateName := KeyValue
else
if KeyName='KEY'
then AddSectionKey(KeyValue)
else
begin
WriteLn('error in script file - inside file section');
WriteLn('key line: ',Line);
ReturnVal := 1;
end;
end;
ELSE
begin
WriteLn('error in script file - not in a section');
WriteLn('key line: ',Line);
ReturnVal := 1;
end;
end;
end
end;
end;
SectionComplete; // close last section
Close(hFGen);
WriteLn('Done...');
Halt(ReturnVal);
end.

View File

@ -0,0 +1,141 @@
{
$Id$
Translation of the Mesa GL, GLU and GLX headers for Free Pascal
Linux Version, Copyright (C) 1999 Sebastian Guenther
Mesa 3-D graphics library
Version: 3.0
Copyright (C) 1995-1998 Brian Paul
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
}
{$MODE delphi} // objfpc would not work because of direct proc var assignments
unit GL;
interface
uses X,XLib,XUtil;
// ===================================================================
// Unit specific extensions
// ===================================================================
function InitGLFromLibrary(libname: PChar): Boolean;
function InitGLUFromLibrary(libname: PChar): Boolean;
// Requires that the GL library has already been initialized:
function InitGLX: Boolean;
// determines automatically which libraries to use:
function InitGL: Boolean;
function InitGLU: Boolean;
var
GLInitialized, GLUInitialized, GLXInitialized: Boolean;
%GLDeclsIF
%GLProcsPD
%GLExtDeclsIF
%GLExtProcsPD
%GLUDeclsIF
%GLUProcsPD
%GLXDeclsIF
%GLXProcsPD
// ===================================================================
// ===================================================================
implementation
{$LINKLIB m}
function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
function dlclose(handle: Pointer): LongInt; external 'dl';
function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
function LoadLibrary(name: PChar): Pointer;
begin
Result := dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY});
end;
function GetProc(handle: Pointer; name: PChar): Pointer;
begin
Result := dlsym(handle, name);
if Result = nil then WriteLn('Unresolved: ', name);
end;
var
libGL, libGLU, libGLX: Pointer;
function InitGLFromLibrary(libname: PChar): Boolean;
begin
Result := False;
libGL := LoadLibrary(libname);
if not Assigned(libGL) then exit;
%GLProcsPL
# // Extensions:
#%GLExtProcs2
GLInitialized := True;
Result := True;
end;
function InitGLUFromLibrary(libname: PChar): Boolean;
begin
Result := False;
libGLU := LoadLibrary(libname);
if not Assigned(libGLU) then exit;
%GLUProcsPL
GLUInitialized := True;
Result := True;
end;
function InitGLX: Boolean;
begin
Result := False;
if not Assigned(libGL) then exit;
%GLXProcsPL
GLXInitialized := True;
Result := True;
end;
function InitGL: Boolean;
begin
Result := InitGLFromLibrary('libGL.so.1') or InitGLFromLibrary('libMesaGL.so.1');
end;
function InitGLU: Boolean;
begin
Result := InitGLUFromLibrary('libGLU.so.1') or InitGLUFromLibrary('libMesaGLU.so.1');
end;
finalization
if Assigned(libGL) then dlclose(libGL);
if Assigned(libGLU) then dlclose(libGLU);
if Assigned(libGLX) then dlclose(libGLX);
end.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,225 @@
{
Translation of the Mesa GL headers for FreePascal
Copyright (C) 1999 Sebastian Guenther
Template for static linking in Win32 environment by Alexander Stohr.
Original copyright notice:
Mesa 3-D graphics library
Version: 3.0
Copyright (C) 1995-1998 Brian Paul
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
}
{
You have to enable Macros (compiler switch "-Sm") for compiling this unit!
This is necessary for supporting different platforms with different calling
conventions via a single unit.
}
unit GL;
interface
{$DEFINE GL1_0}
{x$DEFINE GL1_1}
{x$DEFINE GL1_2}
{x$DEFINE MESA} {enable if you want to use some special mesa extensions}
{x$DEFINE EXTENSIONS} {enable if you need one/all of extensions}
{x$DEFINE SGI_EXTENSIONS} {enable if you need one/all of extensions}
{
*** Note: ***
There is currently one importants side effect when doing static linking.
If you include a function statically than its required to be present
in the supplied DLLs of your OS and Hardware.
This means if the DLL is not present your program will not run.
In Win95 it appears that you will be informined you about
the name of the first missing symbol while loading the executable.
}
{$IFDEF Win32}
{$DEFINE ogl_dll := external 'opengl32.dll'}
uses Windows;
{$ELSE}
{$MESSAGE Unsupported platform.}
{$ENDIF}
// =======================================================
// Unit specific extensions
// =======================================================
// none - no special init required
// =======================================================
// GL consts, types and functions
// =======================================================
// -------------------------------------------------------
// GL types
// -------------------------------------------------------
type
PSingle = ^Single;
PDouble = ^Double;
GLvoid = Pointer;
GLboolean = Byte;
GLbyte = ShortInt; // 1-byte signed
GLshort = Integer; // 2-byte signed
GLint = LongInt; // 4-byte signed
GLubyte = Byte; // 1-byte unsigned
GLushort = Word; // 2-byte unsigned
GLuint = DWord; // 4-byte signed
GLsizei = LongInt; // 4-byte signed
GLfloat = Single; // single precision float
GLclampf = Single; // single precision float in [0,1]
GLdouble = Double; // double precision float
GLclampd = Double; // double precision float in [0,1]
GLenum = DWord;
type
GLbitfield = DWord; { was an enum - no corresponding thing in pascal }
const
GL_CURRENT_BIT = $00000001;
GL_POINT_BIT = $00000002;
GL_LINE_BIT = $00000004;
GL_POLYGON_BIT = $00000008;
GL_POLYGON_STIPPLE_BIT= $00000010;
GL_PIXEL_MODE_BIT = $00000020;
GL_LIGHTING_BIT = $00000040;
GL_FOG_BIT = $00000080;
GL_DEPTH_BUFFER_BIT = $00000100;
GL_ACCUM_BUFFER_BIT = $00000200;
GL_STENCIL_BUFFER_BIT = $00000400;
GL_VIEWPORT_BIT = $00000800;
GL_TRANSFORM_BIT = $00001000;
GL_ENABLE_BIT = $00002000;
GL_COLOR_BUFFER_BIT = $00004000;
GL_HINT_BIT = $00008000;
GL_EVAL_BIT = $00010000;
GL_LIST_BIT = $00020000;
GL_TEXTURE_BIT = $00040000;
GL_SCISSOR_BIT = $00080000;
GL_ALL_ATTRIB_BITS = $000fffff;
// -------------------------------------------------------
// GL constants
// -------------------------------------------------------
{$IFDEF GL1_0}
%GLDeclsIF10
{$ENDIF GL1_0}
{$IFDEF GL1_1}
%GLDeclsIF11
{$ENDIF GL1_1}
{$IFDEF GL1_2}
%GLDeclsIF12
{$ENDIF GL1_2}
const
// Utility
GL_VENDOR = $1F00;
GL_RENDERER = $1F01;
GL_VERSION = $1F02;
GL_EXTENSIONS = $1F03;
// Errors
GL_INVALID_VALUE = $0501;
GL_INVALID_ENUM = $0500;
GL_INVALID_OPERATION = $0502;
GL_STACK_OVERFLOW = $0503;
GL_STACK_UNDERFLOW = $0504;
GL_OUT_OF_MEMORY = $0505;
// -------------------------------------------------------
// GL extensions constants
// -------------------------------------------------------
{$IFDEF EXTENSIONS}
%GLDeclsIF10Ext
{$ENDIF EXTENSIONS}
{$IFDEF SGI_EXTENSIONS}
%GLDeclsIF10SGI
{$ENDIF SGI_EXTENSIONS}
{$IFDEF MESA}
%GLDeclsIF10Mesa
{$ENDIF MESA}
// -------------------------------------------------------
// GL procedures and functions
// -------------------------------------------------------
{$IFDEF GL1_0}
%GLProcsPS10
{$ENDIF GL1_0}
{$IFDEF GL1_1}
%GLProcsPS11
{$ENDIF GL1_1}
// -------------------------------------------------------
// GL Extensions
// -------------------------------------------------------
{$IFDEF EXTENSIONS}
%GLProcsPS10Ext
{$ENDIF EXTENSIONS}
// library dependent extensions
{$IFDEF SGI_EXTENSIONS}
%GLProcsPS10SGI
{$ENDIF SGI_EXTENSIONS}
{$ifdef MESA}
%GLProcsPS10Mesa
{$endif MESA}
// -------------------------------------------------------
// GL 1.2 Functions
// -------------------------------------------------------
{$IFDEF GL1_2}
%GLProcsPS12
{$ENDIF GL1_2}
// =======================================================
// =======================================================
implementation
{BEGIN}{OF INIT}
END.

View File

@ -0,0 +1,99 @@
{
$Id$
Translation of the Mesa GLUT headers for FreePascal
Linux Version, Copyright (C) 1999 Sebastian Guenther
Mesa 3-D graphics library
Version: 3.0
Copyright (C) 1995-1998 Brian Paul
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
}
{$MODE delphi}
unit GLUT;
interface
uses GL;
function InitGLUTFromLibrary(libname: PChar): Boolean;
// determines automatically which library to use:
function InitGLUT: Boolean;
var
GLUTInitialized: Boolean;
%GLUTDeclsIF
%GLUTProcsPD
implementation
{$LINKLIB Xmu}
function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
function dlclose(handle: Pointer): LongInt; external 'dl';
function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
function LoadLibrary(name: PChar): Pointer;
begin
Result := dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY});
end;
procedure FreeLibrary(handle: Pointer);
begin
dlclose(handle);
end;
function GetProc(handle: Pointer; name: PChar): Pointer;
begin
Result := dlsym(handle, name);
// if Result = nil then WriteLn('Unresolved: ', name);
end;
var
libGLUT: Pointer;
function InitGLUTFromLibrary(libname: PChar): Boolean;
begin
Result := False;
libGLUT := LoadLibrary(libname);
if not Assigned(libGLUT) then exit;
%GLUTProcsPL
GLUTInitialized := True;
Result := True;
end;
function InitGLUT: Boolean;
begin
Result := InitGLUTFromLibrary('libglut.so.1');
end;
finalization
if Assigned(libGLUT) then FreeLibrary(libGLUT);
end.

View File

@ -0,0 +1,114 @@
{$MODE delphi}
unit GLUT;
interface
uses GL;
{$IFDEF Linux}
{$DEFINE gldecl := cdecl}
{$ELSE}
{$IFDEF Win32}
{$DEFINE gldecl := stdcall}
{$ENDIF}
{$ENDIF}
function InitGLUTFromLibrary(libname: PChar): Boolean;
// determines automatically which library to use:
function InitGLUT: Boolean;
var
GLUTInitialized: Boolean;
%GLUTDeclsIF
%GLUTProcsPD
implementation
{$IFDEF Linux}
{$LINKLIB Xmu}
type
HInstance = LongWord;
function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
function dlclose(handle: Pointer): LongInt; external 'dl';
function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
function LoadLibrary(name: PChar): HInstance;
begin
Result := LongWord(dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY}));
end;
procedure FreeLibrary(handle: HInstance);
begin
dlclose(Pointer(handle));
end;
function GetProcAddress(handle: HInstance; name: PChar): Pointer;
begin
Result := dlsym(Pointer(handle), name);
if Result = nil then WriteLn('Unresolved: ', name);
end;
{$ENDIF}
{$IFDEF Win32}
type
HInstance = LongWord;
function LoadLibrary(name: PChar): HInstance;
begin
Result := 0;
end;
procedure FreeLibrary(handle: HInstance);
begin
end;
function GetProcAddress(handle: HInstance; name: PChar): Pointer;
begin
Result := NIL;
if Result = nil then WriteLn('Unresolved: ', name);
end;
{$ENDIF}
var
libGLUT: HInstance;
function InitGLUTFromLibrary(libname: PChar): Boolean;
begin
Result := False;
libGLUT := LoadLibrary(libname);
if libGLUT = 0 then exit;
%GLUTProcsPL
GLUTInitialized := True;
Result := True;
end;
function InitGLUT: Boolean;
begin
{$IFDEF Win32}
Result := InitGLUTFromLibrary('glut32.dll');
{$ELSE}
{$IFDEF Linux}
Result := InitGLUTFromLibrary('libglut.so');
{$ELSE}
{$ERROR Unsupported platform}
{$ENDIF}
{$ENDIF}
end;
finalization
if libGLUT <> 0 then FreeLibrary(libGLUT);
end.

View File

@ -0,0 +1,50 @@
{
$Id$
Translation of the GLUT headers for FreePascal
Copyright (C) 1999 Sebastian Guenther
Version for static linking in Win32 environment by Alexander Stohr.
Latest change: 1999-11-13
Further information:
GLUT is a powerful toolkit for programming multiplatform OpenGL
applications. It was designed by Mark J. Kilgard while working for SGI,
he is now working for nVidia.
}
{ this translation of the c header files is done by Sebastian Guenther 1999 }
{ version for static linking for Win32 platforms done by Alexander Stohr 1999 }
{$MODE delphi}
{You have to enable Macros (compiler switch "-Sm") for compiling this unit!
This is necessary for supporting different platforms with different calling
conventions via a single unit.}
unit GLUT_SL; { version which does statically linking }
interface
uses GL_SL;
{x$DEFINE GLUT_GAME} {enable if you need game mode sub api}
{$IFDEF Win32}
{$DEFINE glut_dll := external 'glut32.dll'}
{$DEFINE glut_callback := cdecl}
{$ELSE}
{$MESSAGE Unsupported platform.}
{$ENDIF}
%GLUTDeclsIF
%GLUTProcsPS
implementation
{begin{of init}
end.