|
3
D3D-.
DirectInput8 |
|
,
- delphi directx 8.1 |
|
Delphi. |
|
[]
[ 1] []
[ ] |
|
|
|
OpenGL DirectX.
,
.
, ,
. ,
-
.
. , ..
, ,
. |
|
, , "",
.
,
. |
|
|
|
, 2 ,
D3D- .
D3D
, (Handle)
IDirect3DDevice8
TD3DGameApp.Create_ TD3DGameApp.CreateDisplayObjects |
|
,
D3D-
/ . |
|
, ,
, (MainForm)
. |
|
,
D3D- / .
TMainMenu.
-
,
- ( ),
DirectInput,
, Direct3D TMainMenu.
, -
|
|
DirectInput,
.. -
/ . |
|
DirectX, , ,
, DirectInput8 -
- ,
( ,
).
DirectInput8 , ,
-
uses interface DX8_DIUtil8.pas
Delphi DirectX 8.1
,
,
const
ChangeWindowModeKey
= isButton1; //
isButton1 DX8_DIUtil8.pas
D3D- ( TD3DGameApp )
m_DXInput:
TDXInput; // DirectInput
-
//
Input functions
procedure SetDefaultDefKeys;
procedure CreateInputObjects;
procedure DestroyInputObjects;
procedure UpdateInput; |
|
implementation -
procedure
TD3DGameApp.SetDefaultDefKeys;
begin
FCustomKeyAssign := DefineDefaultKeys; //
DefineDefaultKeys //
end;
function
DefineDefaultKeys: TKeyAssignList;
function
DefineDefaultKeys: TKeyAssignList;
begin
FillChar(Result, SizeOf(Result), 0);
AssignKey(Result, ChangeWindowModeKey, [Ord('W'), VK_F6]); //
W F6
end;
procedure
TD3DGameApp.CreateInputObjects;
begin
SetDefaultDefKeys;
m_DXInput := TDXInput.Create(Self);
end;
procedure
TD3DGameApp.DestroyInputObjects;
begin
FreeAndNil(m_DXInput);
end;
procedure
TD3DGameApp.UpdateInput;
var
CurrentState: TUserInput;
begin
if not Assigned(m_DXInput) then Exit;
m_DXInput.Update;
if
ChangeWindowModeKey in m_DXInput.States then {
};
end;
CreateInputObjects TD3DGameApp.OneTimeSceneInit
DestroyInputObjects TD3DGameApp.FinalCleanup
, FormDestroy
UpdateInput,
DirectInput
TD3DGameApp.FrameMove |
|
,
/ D3D-
ChangeWindowModeKey.
[W] [F6]. , . |
|
if
ChangeWindowModeKey in m_DXInput.States then {
};
{
}
,
.
-
procedure
TOptionsMenu.AcceptOptions;
var
ScreenSizeMetric: TScreenSizeMetric;
begin
if g_d3dApp = nil then Exit;
ScreenSizeMetric := GetScreenSize;
if (not g_d3dApp.m_bFullScreen = Windowed) and
(g_d3dApp.m_dwScreenWidth = ScreenSizeMetric.Width) then Exit;
g_d3dApp.SwitchDisplayModes(not Windowed, ScreenSizeMetric.Width,
ScreenSizeMetric.Height);
end;
TOptionsMenu
.
.
/
SwitchDisplayModes
g_d3dApp, TD3DGameApp.
800x600
(100 Hz ).
TD3DGameApp
function
SwitchDisplayModes(bFullScreen: Boolean;
dwWidth, dwHeight: Cardinal): HRESULT;
-
function
TD3DGameApp.SwitchDisplayModes(bFullScreen: Boolean;
dwWidth, dwHeight: Cardinal): HRESULT;
var
hr: HResult;
begin
if not m_bIsActive or not m_bDisplayReady then begin
result := S_OK;
Exit;
end;
// Check to see if a change was actually requested
if bFullScreen then
begin
if ((m_dwScreenWidth = dwWidth) and (m_dwScreenHeight = dwHeight)) and
(m_bFullScreen = bFullScreen ) then
begin
result := S_OK;
Exit;
end;
end
else
begin
if not m_bFullScreen then begin
result := S_OK;
Exit;
end;
end;
// Invalidate the old display objects
m_bDisplayReady := FALSE;
InvalidateDisplayObjects;
// Set up the new presentation paramters
if bFullScreen then
begin
m_d3dpp.Windowed := FALSE;
m_d3dpp.hDeviceWindow := m_hWndMain;
m_dwScreenWidth := dwWidth;
m_d3dpp.BackBufferWidth := dwWidth;
m_dwScreenHeight := dwHeight;
m_d3dpp.BackBufferHeight := dwHeight;
m_d3dpp.BackBufferFormat := m_d3dfmtFullscreen;
end
else
begin
m_d3dpp.Windowed := TRUE;
m_d3dpp.hDeviceWindow := 0;
m_d3dpp.BackBufferWidth := 0;
m_d3dpp.BackBufferHeight := 0;
m_dwScreenWidth := dwWidth;
m_dwScreenHeight := dwHeight;
m_d3dpp.BackBufferFormat := m_DesktopMode.Format;
end;
// Reset the device
hr := m_pd3dDevice.Reset( m_d3dpp );
if SUCCEEDED(hr) then
begin
m_bFullScreen := bFullScreen;
hr := RestoreDisplayObjects;
if SUCCEEDED(hr) then
begin
m_bDisplayReady := TRUE;
result := S_OK;
Exit;
end;
end;
// If we get here, a fatal error occurred
PostMessage( m_hWndMain, WM_CLOSE, 0, 0 );
result := E_FAIL;
end;
,
TD3DGameApp TD3DGameApp.Create
, .
,
/
InvalidateDisplayObjects
Direct3DDevice ,
Direct3DDevice, RestoreDisplayObjects
,
.
, ,
!!!
", !" , ..
, ,
,
. |
|
,
[ Donuts3D],
: |
|
D3D-
. |
|
[]
[ 1] []
[ ] |
|
|
|
|
|