unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DXHelp, Direct3D9, D3DX9;
type
TForm1 =
class(TForm)
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
procedure OnIdle(Sender: TObject;
var Done: boolean);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Direct3D9: IDirect3D9;
D3DDev9: IDirect3DDevice9;
Vertexbuffer: IDirect3DVertexBuffer9;
type
TD3DLVertex =
record
Position: TD3DXVector3;
Diffuse: TD3DColor;
end;
const
D3DFVF_TD3DLVERTEX = D3DFVF_XYZ
or D3DFVF_DIFFUSE;
implementation
{$R *.dfm}
function GetTD3DLVertex( X, Y, Z: Extended; Farbe: TD3DColor ): TD3DLVertex;
begin
Result.Position := D3DXVector3( X, Y, Z );
Result.Diffuse := Farbe;
end;
function InitGeometry: HRESULT;
var
Vertices:
Array[0..2]
of TD3DLVertex;
pVertices: Pointer;
begin
Vertices[0] := GetTD3DLVertex( 1.0, -1.0, 0.0, $FFFF0000 );
Vertices[1] := GetTD3DLVertex( -1.0, -1.0, 0.0, $FF0000FF );
Vertices[2] := GetTD3DLVertex( 0.0, 1.0, 0.0, $FFFFFFFF );
Result := D3DDev9.CreateVertexBuffer( Sizeof( TD3DLVertex) *3,
D3DUSAGE_WRITEONLY,
D3DFVF_TD3DLVERTEX,
D3DPOOL_DEFAULT,
Vertexbuffer,
nil );
if Result <> D3D_OK
then
Exit;
Result := Vertexbuffer.Lock( 0, SizeOf( TD3DLVertex ) * 3, pVertices, 0 );
if Result <> D3D_OK
then
Exit;
Move( Vertices, pVertices^, SizeOf( Vertices ) );
Result := Vertexbuffer.Unlock;
D3DDev9.SetRenderState( D3DRS_LIGHTING, LongWord( False ) );
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DHInitDGFX( Form1.Handle, False, True, 0, 0, 0, True, Direct3D9, D3DDev9 );
InitGeometry;
Application.OnIdle := OnIdle;
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Vertexbuffer :=
nil;
DHCloseDGFX( Direct3D9, D3DDev9 );
end;
procedure Render;
begin
D3DDev9.BeginScene;
D3DDev9.Clear( 0,
nil, D3DCLEAR_TARGET, D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0, 0);
D3DDev9.SetStreamSource( 0, VertexBuffer, 0, SizeOf( TD3DLVertex ) );
D3DDev9.SetFVF( D3DFVF_TD3DLVertex );
D3DDev9.DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
D3DDev9.EndScene;
D3DDev9.Present(
nil,
nil, 0,
nil );
end;
procedure TForm1.OnIdle(Sender: TObject;
var done: boolean);
begin
done := false;
Render;
end;
end.