123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- unit fSkyBox;
- interface
- uses
- Winapi.Windows,
- Winapi.OpenGL,
- System.SysUtils,
- System.Classes,
- Vcl.Graphics,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- Vcl.ExtCtrls,
- Vcl.Imaging.Jpeg,
- GLS.Scene,
- GLS.VectorTypes,
- GLS.Texture,
- GLS.SkyDome,
- GLS.Cadencer,
- GLS.Navigator,
- GLS.SceneViewer,
- GLS.Keyboard,
- GLS.LensFlare,
- GLS.Objects,
- GLS.Material,
- GLS.Coordinates,
- GLS.BaseClasses,
- GLS.SimpleNavigation,
- GLS.Utils;
- type
- TFormSkyBox = class(TForm)
- GLScene1: TGLScene;
- GLCamera1: TGLCamera;
- GLMaterialLibraryCM: TGLMaterialLibrary;
- GLLightSource1: TGLLightSource;
- Castle: TGLDummyCube;
- GLCube1: TGLCube;
- GLCube11: TGLCube;
- GLCube111: TGLCube;
- GLCube112: TGLCube;
- GLCube2: TGLCube;
- GLCube21: TGLCube;
- GLCube211: TGLCube;
- GLCube212: TGLCube;
- GLNavigator1: TGLNavigator;
- GLCadencer1: TGLCadencer;
- GLUserInterface1: TGLUserInterface;
- GLLensFlare1: TGLLensFlare;
- GLSceneViewer1: TGLSceneViewer;
- GLSkyBox1: TGLSkyBox;
- GLSkyBox2: TGLSkyBox;
- GLSphere1: TGLSphere;
- GLSphere2: TGLSphere;
- GLSimpleNavigation1: TGLSimpleNavigation;
- procedure FormCreate(Sender: TObject);
- procedure GLCadencer1Progress(Sender: TObject;
- const deltaTime, newTime: Double);
- private
- procedure HandleKeys(d: Double);
- function LoadTexture(Matname, Filename: string): TGLLibMaterial;
- public
- end;
- var
- FormSkyBox: TFormSkyBox;
- implementation
- {$R *.dfm}
- function TFormSkyBox.LoadTexture(Matname, Filename: string): TGLLibMaterial;
- begin
- Result := GLMaterialLibraryCM.AddTextureMaterial(Matname, Filename);
- Result.Material.Texture.Disabled := False;
- Result.Material.Texture.TextureMode := tmDecal;
- end;
- procedure TFormSkyBox.FormCreate(Sender: TObject);
- var
- PathCM: TFileName;
- begin
- SetGLSceneMediaDir();
- PathCM := GetCurrentDir() + '\Cubemaps';
- SetCurrentDir(PathCM);
- // Skybox cubemaps
- LoadTexture('Left', 'icecraterlf.jpg');
- LoadTexture('Right', 'icecraterrt.jpg');
- LoadTexture('Top', 'icecraterup.jpg');
- LoadTexture('Bottom', 'icecraterdn.jpg');
- LoadTexture('Front', 'icecraterft.jpg');
- LoadTexture('Back', 'icecraterbk.jpg');
- SetGLSceneMediaDir(); // back to media folder with textures
- with LoadTexture('Clouds', 'Clouds.jpg') do
- begin
- // Add transparency to clouds
- Material.BlendingMode := bmTransparency;
- Material.FrontProperties.Diffuse.Alpha := 0.2;
- // scale the clouds texture
- TextureScale.X := 8;
- TextureScale.y := 8;
- end;
- // bricks
- with LoadTexture('Bricks', 'rawwall.jpg') do
- begin
- TextureScale.X := 1;
- TextureScale.y := 32;
- Material.Texture.TextureMode := tmModulate;
- end;
- with LoadTexture('Bricks2', 'marbletiles.jpg') do
- begin
- TextureScale.X := 6;
- TextureScale.y := 1;
- Material.Texture.TextureMode := tmModulate;
- end;
- // Moon
- LoadTexture('Moon', 'unwrapped moon.jpg').Material.Texture.TextureMode :=
- tmModulate;
- // -----------------------------------------
- // Assign materials to objects
- // -----------------------------------------
- GLCube1.Material.LibMaterialName := 'Bricks';
- GLCube11.Material.LibMaterialName := 'Bricks';
- GLCube111.Material.LibMaterialName := 'Bricks';
- GLCube112.Material.LibMaterialName := 'Bricks';
- GLCube2.Material.LibMaterialName := 'Bricks2';
- GLCube21.Material.LibMaterialName := 'Bricks2';
- GLCube21.Material.LibMaterialName := 'Bricks2';
- GLCube211.Material.LibMaterialName := 'Bricks2';
- GLCube212.Material.LibMaterialName := 'Bricks2';
- GLSphere1.Material.LibMaterialName := 'Moon';
- GLSphere2.Material.LibMaterialName := 'Moon';
- //GLUserInterface1.MouseLookActive := true;
- end;
- procedure TFormSkyBox.GLCadencer1Progress(Sender: TObject;
- const deltaTime, newTime: Double);
- begin
- // Make clouds Texture slide
- with GLMaterialLibraryCM.Materials.GetLibMaterialByName('Clouds') do
- begin
- TextureOffset.X := TextureOffset.X + deltaTime * 0.02;
- TextureOffset.y := TextureOffset.y + deltaTime * 0.03;
- end;
- // Rotate moons
- GLSphere1.Turn(deltaTime * 7);
- GLSphere2.Turn(deltaTime * 10);
- HandleKeys(deltaTime);
- GLUserInterface1.Mouselook;
- GLUserInterface1.MouseUpdate;
- GLSceneViewer1.Invalidate;
- end;
- procedure TFormSkyBox.HandleKeys(d: Double);
- begin
- if IsKeyDown('W') or IsKeyDown('Z') then
- GLCamera1.Move(d);
- if IsKeyDown('S') then
- GLCamera1.Move(-d);
- if IsKeyDown('A') or IsKeyDown('A') then
- GLCamera1.Slide(-d);
- if IsKeyDown('D') then
- GLCamera1.Slide(d);
- if IsKeyDown(VK_ESCAPE) then
- Close;
- end;
- end.
|