unit1.pas
来自「delphi 最好的3D控件GLScene_Demos」· PAS 代码 · 共 86 行
PAS
86 行
{: Sample showing use of TGLSprite for "caterpillar" effect.<p>
A bunch of TGLSprite is created in FormCreate, all copied from Sprite2 (used
as "template"), then we move and resize them as they orbit a pulsating "star".<br>
Textures are loaded from a "flare1.bmp" file that is expected to be in the
same directory as the compiled EXE.<p>
There is nothing really fancy in this code, but in the objects props :<ul>
<li>blending is set to bmAdditive (for the color saturation effect)
<li>DepthTest is disabled
<li>ball color is determined with the Emission color
</ul><br>
The number of sprites is low to avoid stalling a software renderer
(texture alpha-blending is a costly effect), if you're using a 3D hardware,
you'll get FPS in the hundredths and may want to make the sprite count higher.<p>
A material library component is used to store the material (and texture) for
all the sprites, if we don't use it, sprites will all maintain their own copy
of the texture, which would just be a waste of resources. With the library,
only one texture exists (well, two, the sun has its own).
}
unit Unit1;
interface
uses
Forms, GLScene, GLObjects, GLMisc, StdCtrls, GLTexture, Classes, Controls,
ExtCtrls, GLCadencer, GLWin32Viewer;
type
TForm1 = class(TForm)
GLScene1: TGLScene;
GLSceneViewer1: TGLSceneViewer;
DummyCube1: TGLDummyCube;
GLCamera1: TGLCamera;
Sprite1: TGLSprite;
Sprite2: TGLSprite;
GLMaterialLibrary1: TGLMaterialLibrary;
Timer1: TTimer;
GLCadencer1: TGLCadencer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure GLCadencer1Progress(Sender: TObject; const deltaTime,
newTime: Double);
private
{ D閏larations priv閑s }
public
{ D閏larations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses SysUtils, VectorGeometry;
procedure TForm1.FormCreate(Sender: TObject);
var
picName : String;
i : Integer;
spr : TGLSprite;
begin
// Load texture for sprite2, this is the hand-coded way using a PersistentImage
// Sprite1 uses a PicFileImage, and so the image is automagically loaded by
// GLScene when necessary (no code is required).
// (Had I used two PicFileImage, I would have avoided this code)
picName:='..\..\media\flare1.bmp';
GLMaterialLibrary1.Materials[0].Material.Texture.Image.LoadFromFile(picName);
// New sprites are created by duplicating the template "sprite2"
for i:=1 to 9 do begin
spr:=TGLSprite(DummyCube1.AddNewChild(TGLSprite));
spr.Assign(sprite2);
end;
end;
procedure TForm1.GLCadencer1Progress(Sender: TObject; const deltaTime,
newTime: Double);
var
i : Integer;
a, aBase : Double;
begin
// angular reference : 90
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?