unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, direct3d9, d3dx9;
type
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure OnIdle(Sender: Tobject;
var done: boolean);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
direct3d9: IDirect3d9;
d3ddev9: idirect3ddevice9;
implementation
{$R *.dfm}
function dhinitdgfx(_handle: hwnd; _fullscreen: boolean;
_width, _height, _bits: longint;
_hal: boolean;
out _idirect3d9: idirect3d9;
out _idirect3ddevice9: idirect3ddevice9): boolean;
var
d3dpp : td3dpresent_parameters;
d3ddm : td3ddisplaymode;
dtype : td3ddevtype;
d3dcaps9 : td3dcaps9;
hardwarevertexprocessing : boolean;
vertexprocessing : integer;
begin
result:= false;
_idirect3d9:= direct3dcreate9(d3d_sdk_version);
if (_idirect3d9 =
nil)
then exit;
fillchar(d3dpp, sizeof(d3dpp), 0);
with d3dpp
do begin
windowed:=
not _fullscreen;
swapeffect:= d3dswapeffect_discard;
if (_fullscreen)
then
begin
backbufferwidth:= _width;
backbufferheight:= _height;
case _bits
of
16: backbufferformat:= d3dfmt_r5g6b5;
32: backbufferformat:= d3dfmt_a8r8g8b8;
else exit;
end;
end else begin
if failed(_idirect3d9.GetAdapterDisplayMode(d3dadapter_default, d3ddm))
then
exit;
backbufferformat:= d3ddm.Format;
end;
end;
_idirect3d9.GetDeviceCaps(d3dadapter_default, d3ddevtype_hal, d3dcaps9);
hardwarevertexprocessing:= d3dcaps9.DevCaps
and d3ddevcaps_hwtransformandlight <> 0;
if hardwarevertexprocessing
then
vertexprocessing:= d3dcreate_hardware_vertexprocessing
else
vertexprocessing:= d3dcreate_software_vertexprocessing;
if _hal
then
dtype:= d3ddevtype_hal
else
dtype:= d3ddevtype_ref;
result:= true;
end;
procedure dxgfx_init;
var
d3dpp: td3dpresent_parameters;
d3ddm: td3ddisplaymode;
begin
direct3d9:= direct3dcreate9(d3d_sdk_version);
if direct3d9 =
nil then
begin
exit;
end;
if (
not direct3d9.GetAdapterDisplayMode(d3dadapter_default, d3ddm)= d3d_ok)
then
begin
application.terminate;
exit;
end;
fillchar(d3dpp, sizeof(d3dpp), 0);
d3dpp.windowed:= false;
d3dpp.BackBufferWidth:= d3ddm.Width;
d3dpp.BackBufferHeight:= d3ddm.Height;
d3dpp.BackBufferFormat:= d3ddm.Format;
d3dpp.SwapEffect:= d3dswapeffect_discard;
[b]direct3d9.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, form1.Handle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp, d3ddev9);[/b]
// Diese Zeile wird bei mir als Fehler markiert//
end;
procedure dhclosedgfx(_idirect3d9: idirect3d9; _idirect3ddevice9: idirect3ddevice9);
begin
_idirect3ddevice9:=
nil;
_idirect3d9:=
nil;
end;
procedure render;
begin
d3ddev9.BeginScene;
d3ddev9.Clear(0,
nil, d3dclear_target, d3dcolor_argb(0,0,0,0),1.0, 0);
d3ddev9.EndScene;
d3ddev9.Present(
nil,
nil, 0,
nil);
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
dhclosedgfx(direct3d9, d3ddev9);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
dhinitdgfx(
handle, false, 0,0,0, true, direct3d9, d3ddev9);
application.OnIdle:= onidle;
end;
procedure tform1.OnIdle(Sender: TObject;
var done: Boolean);
begin
done:= false;
render;
end;
end.