unit dxHelpUnit;
interface
function DHInitDGfx(_handle: hwnd; _fullscreen: boolean; _width,_height, _bits: longint;
_Hal: Boolean;
out _IDirect3D9: IDirect3D9;
out _IDirect3DDevice9 : IDirect3DDevice9) :boolean;
uses d3d9;
implementation
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;
if failed(_IDirect3d9.CreateDevice(D3DAdapter_Default, dType,_handle,vertexProcessing,
d3dpp,_IDirect3dDevice9))
then begin
exit;
end;
Result:=true;
end;
procedure DHCloseDGFX(_IDirect3D9: IDirect3D9; _IDirect3DDevice9:IDirect3DDevice9);
begin
_IDirect3DDevice9 :=
nil;
_IDirect3D9 :=
nil;
end;
end.