- program example;
- {$APPTYPE CONSOLE}
- uses
- SysUtils, Classes,
- ulibShaderFile;
- type
- TFileReader = class(TInterfacedObject, IlsfFileReader)
- public
- function LoadStream(const aFilename: String; const aStream: TStream): Boolean;
- end;
- var
- i : Integer;
- ShaderFile: TlsfShaderFile;
- Generator : TlsfGenerator;
- Pfad : string;
- SHDKlasse : string;
- procedure GetShaderCode(s: TStream);
- var
- SL: TStringList;
- begin
- SL := TStringList.Create;
- try
- SL.Add('{$CLASS Color}');
- SL.Add(' {$PROPERTY UseColorMap ''false''}');
- SL.Add('{$END}');
- SL.Add('{$CLASS ColorFrag $EXTENDS Color}');
- SL.Add(' /* you can also define code here. It will be added when the code for the class is generated */');
- SL.Add(' {$FUNC ''vec4'' GetColor $INLINE}');
- SL.Add(' {$IF UseColorMap}');
- SL.Add(' {$VAR ''vec2'' ''_texCoord'' ''gl_TexCoord[0].st''}');
- SL.Add(' {$UNIFORM ''sampler2D'' ''uColorMap''}');
- SL.Add(' return texture2D(uColorMap, _texCoord);');
- SL.Add(' {$ELSE}');
- SL.Add(' return gl_Color;');
- SL.Add(' {$END}');
- SL.Add(' {$END}');
- SL.Add(' {$MAIN}');
- SL.Add(' gl_FragColor = {$CALL GetColor};');
- SL.Add(' {$END}');
- SL.Add('{$END}');
- SL.Add('{$CLASS ColorVert $EXTENDS Color}');
- SL.Add(' {$MAIN}');
- SL.Add(' gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;');
- SL.Add(' {$IF UseColorMap}');
- SL.Add(' gl_TexCoord[0] = gl_MultiTexCoord0;');
- SL.Add(' {$ELSE}');
- SL.Add(' gl_FrontColor = gl_Color;');
- SL.Add(' gl_BackColor = gl_Color;');
- SL.Add(' {$END}');
- SL.Add(' {$END}');
- SL.Add('{$END}');
- SL.SaveToStream(s);
- finally
- SL.Free;
- end;
- end;
- function TFileReader.LoadStream(const aFilename: String; const aStream: TStream): Boolean;
- var
- Stream: TMemoryStream;
- begin
- Stream := TMemoryStream.Create;
- try
- GetShaderCode(Stream);
- aStream.CopyFrom(Stream, 0);
- result := true;
- finally
- Stream.Free;
- end;
- end;
- begin
- Pfad := ExtractFilePath(ParamStr(0));
- SHDKlasse := 'ColorVert';
- lsf_init(Pfad + '..\..\..\libShaderFile-i386-win32.dll');
- try
- ShaderFile := TlsfShaderFile.Create;
- try
- ShaderFile.LoadFromFunc('', TFileReader.Create);
- Generator := TlsfGenerator.Create(ShaderFile, SHDKlasse);
- try
- WriteLn(Generator.GenerateCode);
- Readln;
- finally
- FreeAndNil(Generator);
- end;
- finally
- FreeAndNil(ShaderFile);
- end;
- except
- on e: Exception do
- begin
- WriteLn('error: ' + e.Message);
- ExitCode := 2;
- end;
- end;
- lsf_finish;
- end.