type
PD3DVertex = ^TD3DVertex;
TD3DVertex =
record
p : TD3DXVector3;
n : TD3DXVector3;
tu, tv : Single;
end;
var
Form1: TForm1;
DXReady: boolean = false;
//DirectX Devices...
D3D8 : IDirect3D8;
D3DDev8 : IDirect3DDevice8;
d3ddm : TD3DDISPLAYMODE;
d3dpp : TD3DPRESENT_PARAMETERS;
viereckvb : IDirect3DVertexBuffer8;
viereck:
array [0..3]
of TD3DVertex;
implementation
{$R *.DFM}
const
D3DFVF_D3DVERTEX = D3DFVF_XYZ
or D3DFVF_NORMAL
or D3DFVF_TEX1;
procedure TForm1.AppOnIdle(Sender: TObject;
var Done: Boolean);
begin
D3DDEV8.Clear(0,
nil, D3DCLEAR_ZBUFFER
or D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1, 0);
D3DDev8.BeginScene;
D3DDEV8.SetVertexShader(D3DFVF_D3DVERTEX);
D3DDEV8.SetStreamSource(0, viereckvb, sizeof(TD3DVertex));
D3DDEV8.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1);
D3DDev8.EndScene;
D3DDev8.Present(
nil,
nil, 0,
nil);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
ptr : PByte;
begin
D3D8 := Direct3DCreate8(D3D_SDK_VERSION);
if D3D8 =
NIL then exit;
if failed(D3D8.GetAdapterDisplayMode(D3DADAPTER_DEFAULT, d3ddm))
then exit;
Fillchar(d3dpp, sizeof(d3dpp), 0);
d3dpp.Windowed := TRUE;
d3dpp.SwapEffect := D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat := d3ddm.Format;
d3dpp.EnableAutoDepthStencil := true;
d3dpp.AutoDepthStencilFormat := D3DFMT_D16;
if failed(D3D8.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, form1.handle,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp, D3DDEV8))
then exit;
Application.OnIdle := AppOnIdle;
viereck[0].p := d3dxvector3(-100, 0, -100);
viereck[0].n := d3dxvector3(0, 1, 0);
viereck[0].tu := 0;
viereck[0].tv := 0;
viereck[1].p := d3dxvector3(-100, 0, 100);
viereck[1].n := d3dxvector3(0, 1, 0);
viereck[1].tu := 0;
viereck[1].tv := 1;
viereck[2].p := d3dxvector3(100, 0, -100);
viereck[2].n := d3dxvector3(0, 1, 0);
viereck[2].tu := 1;
viereck[2].tv := 0;
viereck[3].p := d3dxvector3(100, 0, 100);
viereck[3].n := d3dxvector3(0, 1, 0);
viereck[3].tu := 1;
viereck[3].tv := 1;
D3DDEV8.CreateVertexBuffer(SizeOf(viereck), D3DUSAGE_WRITEONLY,
D3DFVF_D3DVERTEX, D3DPOOL_DEFAULT,
viereckvb);
viereckvb.Lock(0, SizeOf(viereck), ptr, 0);
Move(viereck, ptr^, SizeOf(viereck));
viereckvb.Unlock;
end;