界面关系描述:
object Form1: TForm1 Left = 290 Top = 175 Caption = 'Blur' ClientHeight = 462 ClientWidth = 518 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 object GLSceneViewer: TGLSceneViewer Left = 0 Top = 45 Width = 518 Height = 417 Camera = GLCamera1//相机 Buffer.FogEnvironment.FogColor.Color = {1283003F1283003F0000803F0000803F} Buffer.FogEnvironment.FogStart = 1.000000000000000000 Buffer.FogEnvironment.FogEnd = 3.000000000000000000 Buffer.BackgroundColor = clBackground Buffer.AmbientColor.Color = {0000000000000000000000000000803F} FieldOfView = 153.029327392578100000 Align = alClient OnMouseMove = GLSceneViewerMouseMove//鼠标事件 TabOrder = 0 end object Panel1: TPanel Left = 0 Top = 0 Width = 518 Height = 45 Align = alTop Caption = ' ' TabOrder = 1 object Label1: TLabel Left = 8 Top = 4 Width = 54 Height = 13 Caption = 'Blur Preset:' FocusControl = ComboBox1 end object Label2: TLabel Left = 216 Top = 4 Width = 61 Height = 13 Caption = 'Render Size:' FocusControl = ComboBox2 end object LabelFPS: TLabel Left = 376 Top = 26 Width = 20 Height = 13 Caption = 'FPS' end object ComboBox1: TComboBox Left = 8 Top = 20 Width = 161 Height = 21 Style = csDropDownList ItemIndex = 0 TabOrder = 0 Text = 'pNone (no change)' OnClick = ComboBox1Click Items.Strings = ( 'pNone (no change)' 'pGlossy' 'pBeastView' 'pOceanDepth' 'pDream' 'pOverBlur' 'pAdvancedBlur') end object ComboBox2: TComboBox Left = 216 Top = 20 Width = 145 Height = 21 Style = csDropDownList ItemIndex = 5 TabOrder = 1 Text = '256' OnChange = ComboBox2Change Items.Strings = ( '8' '16' '32' '64' '128' '256' '512') end end object GLScene1: TGLScene ObjectsSorting = osRenderFarthestFirst Left = 44 Top = 64 object GLLightSource1: TGLLightSource//光源 Ambient.Color = {BEC0403FBEC0403FBEC0403F0000803F} ConstAttenuation = 1.000000000000000000 Diffuse.Color = {BEC0403FBEC0403FBEC0403F0000803F} Position.Coordinates = {56551B40F9FF2D40F6FF3B400000803F} LightStyle = lsOmni SpotCutOff = 180.000000000000000000 end object GLCube1: TGLCube//立方体 Material.MaterialLibrary = GLMaterialLibrary1//材质 Material.LibMaterialName = 'LibMaterial' Direction.Coordinates = {82B16B3E068E77BF3986DFBD00000000} PitchAngle = -95.500000000000000000 Position.Coordinates = {DB9FEC3E806395BE509F213F0000803F} TurnAngle = 6.500000000000000000 Up.Coordinates = {DD7324BEE3EB17BE6BCE793F00000000} end object GLSphere1: TGLSphere//球 Material.MaterialLibrary = GLMaterialLibrary2//材质 Material.LibMaterialName = 'LibMaterial' Position.Coordinates = {6E3D38BF0A5515BE733C1CBF0000803F} Radius = 0.500000000000000000 end object GLDummyCube1: TGLDummyCube// CubeSize = 1.000000000000000000 end object GLCamera1: TGLCamera//相机 DepthOfView = 100.000000000000000000 FocalLength = 50.000000000000000000 NearPlaneBias = 0.100000001490116100 TargetObject = GLDummyCube1 Position.Coordinates = {41A38A3F6847033F2894FA3F0000803F} Direction.Coordinates = {A5C4F6BE96EA77BE3E9257BF00000000} Up.Coordinates = {B74DF6BD4B62783F582A57BE00000000} end end object GLMaterialLibrary1: TGLMaterialLibrary Materials = < item Name = 'LibMaterial' Tag = 0 Material.Texture.ImageClassName = 'TGLPicFileImage'//Texture是一个关注点 Material.Texture.Image.PictureFileName = 'marbletiles.jpg'//程序运行时要加载相片 Material.Texture.MagFilter = maNearest Material.Texture.MinFilter = miNearest Material.Texture.TextureMode = tmModulate Material.Texture.Compression = tcNone Material.Texture.Disabled = False end> TexturePaths = '..\..\..\..\media\'//相片的路径 Left = 140 Top = 64 end object GLCadencer1: TGLCadencer//动画节拍器 Scene = GLScene1 SleepLength = 0 OnProgress = GLCadencer1Progress//节拍事件 Left = 44 Top = 144 end object Timer1: TTimer OnTimer = Timer1Timer Left = 260 Top = 64 end object GLMaterialLibrary2: TGLMaterialLibrary//第二个材质库 Materials = < item Name = 'LibMaterial' Tag = 0 Material.Texture.ImageClassName = 'TGLPicFileImage' Material.Texture.Image.PictureFileName = 'marbletiles.jpg' Material.Texture.MagFilter = maNearest Material.Texture.MinFilter = miNearest Material.Texture.TextureMode = tmModulate Material.Texture.Compression = tcNone Material.Texture.Disabled = False end> TexturePaths = '..\..\..\..\media\' Left = 400 Top = 88 end end
代码控制:
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, GLWin32Viewer, GLScene, GLObjects, GLTexture, GLHudObjects, GLCompositeImage, GLFileJPEG, GLCadencer, StdCtrls, ExtCtrls, GLBlur, GLCrossPlatform, GLMaterial, GLCoordinates, BaseClasses, Jpeg, GLUtils; type TForm1 = class(TForm) GLScene1: TGLScene; GLCamera1: TGLCamera; GLMaterialLibrary1: TGLMaterialLibrary; GLCube1: TGLCube; GLLightSource1: TGLLightSource; GLSceneViewer: TGLSceneViewer; GLCadencer1: TGLCadencer; GLSphere1: TGLSphere; Panel1: TPanel; ComboBox1: TComboBox; Label1: TLabel; Label2: TLabel; ComboBox2: TComboBox; Timer1: TTimer; GLDummyCube1: TGLDummyCube; LabelFPS: TLabel; GLMaterialLibrary2: TGLMaterialLibrary; procedure FormCreate(Sender: TObject); procedure GLCadencer1Progress(Sender: TObject; const deltaTime, newTime: Double); procedure ComboBox1Click(Sender: TObject); procedure ComboBox2Change(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure GLSceneViewerMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); private { Private declarations } oldx, oldy: integer; public { Public declarations } B: TGLBlur; end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin SetGLSceneMediaDir(); // Add GLBlur to scene B := TGLBlur.Create(self); GLSphere1.AddChild(B); B.TargetObject := GLCube1; B.RenderWidth := 256; B.RenderHeight := 256; // Load texture for objects GLMaterialLibrary1.Materials[0].Material.Texture.Image.LoadFromFile('HPIM5446.JPG');//加载相片 GLMaterialLibrary2.Materials[0].Material.Texture.Image.LoadFromFile('HPIM5446.JPG'); ComboBox1.ItemIndex := 1; ComboBox2.ItemIndex := 2; ComboBox1Click(self); end; procedure TForm1.GLCadencer1Progress(Sender: TObject; const deltaTime, newTime: Double); begin GLCube1.Turn(deltatime * 10); GLSphere1.Turn(deltatime * 50); end; procedure TForm1.ComboBox1Click(Sender: TObject); begin B.Preset := TGLBlurPreset(ComboBox1.itemIndex); end; procedure TForm1.ComboBox2Change(Sender: TObject); begin B.RenderWidth := StrToInt(ComboBox2.Items[ComboBox2.ItemIndex]); B.RenderHeight := B.RenderWidth; end; procedure TForm1.Timer1Timer(Sender: TObject); begin LabelFPS.Caption := FloatToStr(Trunc(GLSceneViewer.FramesPerSecond))+ ' FPS'; // GLSceneViewer.ResetPerformanceMonitor; end; procedure TForm1.GLSceneViewerMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if ssLeft in Shift then begin GLCamera1.MoveAroundTarget(1 * (oldy - y), 1 * (oldx - x)); end; oldx := x; oldy := y; end; end.