//-----------------------------------------------------------------------------
// File: D3DApp.cpp
//
// Desc: Application class for the Direct3D samples framework library.
//
// Copyright (c) 1998-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <basetsd.h>
#include <mmsystem.h>
#include <stdio.h>
#include <tchar.h>
#include <D3D8.h>
#include "D3DApp.h"
#include "D3DUtil.h"
#include "DXUtil.h"
#include "D3DRes.h"
//-----------------------------------------------------------------------------
// Global access to the app (needed for the global WndProc())
//-----------------------------------------------------------------------------
static CD3DApplication* g_pD3DApp = NULL;
//-----------------------------------------------------------------------------
// Name: CD3DApplication()
// Desc: Constructor
//-----------------------------------------------------------------------------
CD3DApplication::CD3DApplication()
{
g_pD3DApp = this;
m_dwNumAdapters = 0;
m_dwAdapter = 0L;
m_pD3D = NULL;
m_pd3dDevice = NULL;
m_hWnd = NULL;
m_hWndFocus = NULL;
m_hMenu = NULL;
m_bActive = FALSE;
m_bReady = FALSE;
m_bHasFocus = FALSE;
m_dwCreateFlags = 0L;
m_bFrameMoving = TRUE;
m_bSingleStep = FALSE;
m_fFPS = 0.0f;
m_strDeviceStats[0] = _T('\0');
m_strFrameStats[0] = _T('\0');
m_strWindowTitle = _T("D3D8 Application");
m_dwCreationWidth = 400;
m_dwCreationHeight = 300;
m_bUseDepthBuffer = FALSE;
m_dwMinDepthBits = 16;
m_dwMinStencilBits = 0;
m_bShowCursorWhenFullscreen = FALSE;
// When m_bClipCursorWhenFullscreen is TRUE, the cursor is limited to
// the device window when the app goes fullscreen. This prevents users
// from accidentally clicking outside the app window on a multimon system.
// This flag is turned off by default for debug builds, since it makes
// multimon debugging difficult.
#if defined(_DEBUG) || defined(DEBUG)
m_bClipCursorWhenFullscreen = FALSE;
#else
m_bClipCursorWhenFullscreen = TRUE;
#endif
}
//-----------------------------------------------------------------------------
// Name: WndProc()
// Desc: Static msg handler which passes messages to the application class.
//-----------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
return g_pD3DApp->MsgProc( hWnd, uMsg, wParam, lParam );
}
//-----------------------------------------------------------------------------
// Name: Create()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CD3DApplication::Create( HINSTANCE hInstance )
{
HRESULT hr;
// Create the Direct3D object
m_pD3D = Direct3DCreate8( D3D_SDK_VERSION );
if( m_pD3D == NULL )
return DisplayErrorMsg( D3DAPPERR_NODIRECT3D, MSGERR_APPMUSTEXIT );
// Build a list of Direct3D adapters, modes and devices. The
// ConfirmDevice() callback is used to confirm that only devices that
// meet the app's requirements are considered.
if( FAILED( hr = BuildDeviceList() ) )
{
SAFE_RELEASE( m_pD3D );
return DisplayErrorMsg( hr, MSGERR_APPMUSTEXIT );
}
// Unless a substitute hWnd has been specified, create a window to
// render into
if( m_hWnd == NULL)
{
// Register the windows class
WNDCLASS wndClass = { 0, WndProc, 0, 0, hInstance,
LoadIcon( hInstance, MAKEINTRESOURCE(IDI_MAIN_ICON) ),
LoadCursor( NULL, IDC_ARROW ),
(HBRUSH)GetStockObject(WHITE_BRUSH),
NULL, _T("D3D Window") };
RegisterClass( &wndClass );
// Set the window's initial style
m_dwWindowStyle = WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|
WS_MINIMIZEBOX|WS_VISIBLE;
// Set the window's initial width
RECT rc;
SetRect( &rc, 0, 0, m_dwCreationWidth, m_dwCreationHeight );
AdjustWindowRect( &rc, m_dwWindowStyle, TRUE );
// Create the render window
m_hWnd = CreateWindow( _T("D3D Window"), m_strWindowTitle, m_dwWindowStyle,
CW_USEDEFAULT, CW_USEDEFAULT,
(rc.right-rc.left), (rc.bottom-rc.top), 0L,
LoadMenu( hInstance, MAKEINTRESOURCE(IDR_MENU) ),
hInstance, 0L );
}
// The focus window can be a specified to be a different window than the
// device window. If not, use the device window as the focus window.
if( m_hWndFocus == NULL )
m_hWndFocus = m_hWnd;
// Save window properties
m_dwWindowStyle = GetWindowLong( m_hWnd, GWL_STYLE );
GetWindowRect( m_hWnd, &m_rcWindowBounds );
GetClientRect( m_hWnd, &m_rcWindowClient );
// Initialize the application timer
DXUtil_Timer( TIMER_START );
// Initialize the app's custom scene stuff
if( FAILED( hr = OneTimeSceneInit() ) )
{
SAFE_RELEASE( m_pD3D );
return DisplayErrorMsg( hr, MSGERR_APPMUSTEXIT );
}
// Initialize the 3D environment for the app
if( FAILED( hr = Initialize3DEnvironment() ) )
{
SAFE_RELEASE( m_pD3D );
return DisplayErrorMsg( hr, MSGERR_APPMUSTEXIT );
}
// The app is ready to go
m_bReady = TRUE;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: SortModesCallback()
// Desc: Callback function for sorting display modes (used by BuildDeviceList).
//-----------------------------------------------------------------------------
static int SortModesCallback( const VOID* arg1, const VOID* arg2 )
{
D3DDISPLAYMODE* p1 = (D3DDISPLAYMODE*)arg1;
D3DDISPLAYMODE* p2 = (D3DDISPLAYMODE*)arg2;
if( p1->Format > p2->Format ) return -1;
if( p1->Format < p2->Format ) return +1;
if( p1->Width < p2->Width ) return -1;
if( p1->Width > p2->Width ) return +1;
if( p1->Height < p2->Height ) return -1;
if( p1->Height > p2->Height ) return +1;
return 0;
}
//-----------------------------------------------------------------------------
// Name: BuildDeviceList()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CD3DApplication::BuildDeviceList()
{
const DWORD dwNumDeviceTypes = 2;
const TCHAR* strDeviceDescs[] = { _T("HAL"), _T("REF") };
const D3DDEVTYPE DeviceTypes[] = { D3DDEVTYPE_HAL, D3DDEVTYPE_REF };
BOOL bHALExists = FALSE;
BOOL bHALIsWindowedCompatible = FALSE;
BOOL bHALIsDesktopCompatible = FALSE;
BOOL bHALIsSampleCompatible = FALSE;
// Loop through all the adapters on the system (usually, there's just one
// unless more than one graphics card is present).
for( UINT iAdapter = 0; iAdapter < m_pD3D->GetAdapterCount(); iAdapter++ )
{
// Fill in adapter info
D3DAdapterInfo* pAdapter = &m_Adapters[m_dwNumAdapters];
m_pD3D->GetAdapterIdentifier( iAdapter, D3DENUM_NO_WHQL_LEVEL, &pAdapter->d3dAdapterIdentifier );
m_pD3D->GetAdapterDisplayMode( iAdapter, &pAdapter->d3ddmDesktop );
pAdapter->dwNumDevices = 0;
pAdapter->dwCurrentDevice = 0;
// Enumerate all display modes on this adapter
D3DDISPLAYMODE modes[100];
D3DFORMAT formats[20];
没有合适的资源?快使用搜索试试~ 我知道了~
Introductions_and_Tutorials_with_DirectX_9_code
共929个文件
h:182个
cpp:161个
dds:126个
5星 · 超过95%的资源 需积分: 5 122 下载量 91 浏览量
2012-05-09
11:17:14
上传
评论 1
收藏 38.83MB ZIP 举报
温馨提示
Introductions_and_Tutorials_with_DirectX_9_code 源代码
资源推荐
资源详情
资源评论
收起资源包目录
Introductions_and_Tutorials_with_DirectX_9_code (929个子文件)
winmain.aps 52KB
winmain.aps 52KB
winmain.aps 52KB
winmain.aps 52KB
winmain.aps 52KB
winmain.aps 49KB
EngineResources.aps 25KB
test_all.bat 451B
shader.bat 422B
fx2vsh.bat 32B
fx2psh.bat 32B
S5_Wall_Bump.bmp 768KB
D3F_DefaultSpotlight2.bmp 192KB
D3F_DefaultSpotlight3.bmp 192KB
D3F_DefaultSpotlight.bmp 48KB
icon32x32.BMP 3KB
Background.bmp 1KB
D3F_DefaultTexture.bmp 1KB
D3F_DefaultWhite.bmp 1KB
D3F_DefaultBlack.bmp 1KB
icon16x16.BMP 822B
D3F_Green.bmp 58B
D3F_Blue.bmp 58B
D3F_Red.bmp 58B
D3F_Yellow.bmp 58B
D3F_Cyan.bmp 58B
D3F_Magenda.bmp 58B
d3dapp.cpp 74KB
d3dapp.cpp 74KB
d3dapp.cpp 74KB
d3dapp.cpp 74KB
d3dapp.cpp 61KB
d3dapp.cpp 61KB
d3dapp.cpp 60KB
ENG-SimpleScene.cpp 42KB
dxutil.cpp 37KB
dxutil.cpp 37KB
dxutil.cpp 37KB
d3dsettings.cpp 36KB
d3dsettings.cpp 36KB
d3dsettings.cpp 36KB
InfiniteHLSL.cpp 30KB
d3dfont.cpp 30KB
d3dfont.cpp 30KB
DepthFailCPU.cpp 29KB
FiniteHLSL.cpp 29KB
DepthPassCPU.cpp 28KB
MAT-DX9DiffuseSpecularSpot.cpp 28KB
InfiniteGPU.cpp 28KB
FiniteGPU.cpp 28KB
VoidExporter.cpp 27KB
d3dfile.cpp 27KB
d3denumeration.cpp 26KB
d3denumeration.cpp 26KB
d3denumeration.cpp 26KB
d3dfile.cpp 26KB
d3dfile.cpp 26KB
d3dfile.cpp 26KB
d3dfont.cpp 26KB
ExampleBase.cpp 25KB
d3dfile.cpp 25KB
d3dfile.cpp 25KB
d3dutil.cpp 25KB
d3dutil.cpp 25KB
d3dutil.cpp 25KB
ENG-MeshD3F.cpp 25KB
MAT-DiffuseSpecularSpot_Optimized.cpp 24KB
d3dfile.cpp 24KB
MAT-DX9CookTorrance.cpp 24KB
d3dfont.cpp 23KB
d3dfont.cpp 23KB
d3dfont.cpp 23KB
d3dfont.cpp 23KB
dxutil.cpp 23KB
dxutil.cpp 23KB
dxutil.cpp 23KB
dxutil.cpp 23KB
d3dutil.cpp 23KB
d3dutil.cpp 23KB
d3dutil.cpp 23KB
d3dutil.cpp 23KB
MAT-DiffuseSpecularSpot.cpp 22KB
MAT-DX9ShadowPhong.cpp 21KB
Shadow.cpp 20KB
MAT-DX9Reflective.cpp 20KB
MAT-DiffuseSpecularPhong.cpp 20KB
Shadow.cpp 20KB
Tester02.cpp 20KB
MAT-Specular.cpp 19KB
MAT-DX9OrenNayar.cpp 19KB
MAT-Reflective.cpp 19KB
MGR-ErrorManager.cpp 17KB
ENG-MeshMS3D.cpp 16KB
MAT-DiffuseOptimized.cpp 16KB
ExportedController.cpp 16KB
D3F_Scene.cpp 15KB
Shadow.cpp 15KB
Shadow.cpp 15KB
MGR-MemoryManager.cpp 15KB
MAT-DX8Material.cpp 15KB
共 929 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
拖后腿选手
- 粉丝: 99
- 资源: 40
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页