DXUT框架是 samples例子的一个公共框架。非常方便的把很多本来需要复杂、而且重复的操作,都封装了起来。
使用步骤非常简单
C:\Program Files\Microsoft DirectX SDK (June 2010)\Samples\SampleBrowser
在SDK安装目录下面 有一个SampleBrowser文件。打开
然后根据自己的版本,选择如上, EmptyProject工程
然后 InstallProject
自动安装完成后。打开工程。Clean一下工程 ,防止缓存出错
然后最好重新打开一下工程。 F5运行。
就是一个基本的窗口啦。
//--------------------------------------------------------------------------------------
// File: EmptyProject.cpp
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "DXUT.h"
#include "resource.h"
//--------------------------------------------------------------------------------------
// Rejects any D3D9 devices that aren't acceptable to the app by returning false
//--------------------------------------------------------------------------------------
bool CALLBACK IsD3D9DeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat,
bool bWindowed, void* pUserContext )
{
// Typically want to skip back buffer formats that don't support alpha blending
IDirect3D9* pD3D = DXUTGetD3D9Object();
if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType,
AdapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,
D3DRTYPE_TEXTURE, BackBufferFormat ) ) )
return false;
return true;
}
//--------------------------------------------------------------------------------------
// Before a device is created, modify the device settings as needed
//--------------------------------------------------------------------------------------
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext )
{
return true;
}
//--------------------------------------------------------------------------------------
// Create any D3D9 resources that will live through a device reset (D3DPOOL_MANAGED)
// and aren't tied to the back buffer size
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
void* pUserContext )
{
return S_OK;
}
//--------------------------------------------------------------------------------------
// Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT)
// or that are tied to the back buffer size
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
void* pUserContext )
{
return S_OK;
}
//--------------------------------------------------------------------------------------
// Handle updates to the scene. This is called regardless of which D3D API is used
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext )
{
}
//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
HRESULT hr;
// Clear the render target and the zbuffer
V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) );
// Render the scene
if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
V( pd3dDevice->EndScene() );
}
}
//--------------------------------------------------------------------------------------
// Handle messages to the application
//--------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
bool* pbNoFurtherProcessing, void* pUserContext )
{
return 0;
}
//--------------------------------------------------------------------------------------
// Release D3D9 resources created in the OnD3D9ResetDevice callback
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D9LostDevice( void* pUserContext )
{
}
//--------------------------------------------------------------------------------------
// Release D3D9 resources created in the OnD3D9CreateDevice callback
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D9DestroyDevice( void* pUserContext )
{
}
//--------------------------------------------------------------------------------------
// Initialize everything and go into a render loop
//--------------------------------------------------------------------------------------
INT WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
{
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
// Set the callback functions
DXUTSetCallbackD3D9DeviceAcceptable( IsD3D9DeviceAcceptable );
DXUTSetCallbackD3D9DeviceCreated( OnD3D9CreateDevice );
DXUTSetCallbackD3D9DeviceReset( OnD3D9ResetDevice );
DXUTSetCallbackD3D9FrameRender( OnD3D9FrameRender );
DXUTSetCallbackD3D9DeviceLost( OnD3D9LostDevice );
DXUTSetCallbackD3D9DeviceDestroyed( OnD3D9DestroyDevice );
DXUTSetCallbackDeviceChanging( ModifyDeviceSettings );
DXUTSetCallbackMsgProc( MsgProc );
DXUTSetCallbackFrameMove( OnFrameMove );
// TODO: Perform any application-level initialization here
// Initialize DXUT and create the desired Win32 window and Direct3D device for the application
DXUTInit( true, true ); // Parse the command line and show msgboxes
DXUTSetHotkeyHandling( true, true, true ); // handle the default hotkeys
DXUTSetCursorSettings( true, true ); // Show the cursor and clip it when in full screen
DXUTCreateWindow( L"EmptyProject" );
DXUTCreateDevice( true, 640, 480 );
// Start the render loop
DXUTMainLoop();
// TODO: Perform any application-level cleanup here
return DXUTGetExitCode();
}
上面就是框架代码。就像MFC一样,自动生成的,不用太理解细节了。只需要知道函数名以及哪个函数下面该写什么代码就行。
分享到:
相关推荐
摘要: DXUT(也称sample framework)是建立在Direct3D API之上的Direct3D应用程序框架,有了DXUT这样一个Direct3D程序框架,只需在这个框架的基础上编写相应的代码,从而简化了 windows和Direct3D API的使用,...
DXUT框架进阶教程.pdf
DXUT框架概述 这个指南涵盖了更多DXUT的高级应用. 这个指南里的大部分功能是可选的, 为了以最小的代价来增强你的应用程序. DXUT提供了一个简单的基于GUI系统的精灵和一个设备设置对话框. 另外, 它还提供了一些摄像机...
DXUT(也称sample framework)是建立在Direct3D API之上的Direct3D应用程序框架,有了DXUT这样一个Direct3D程序框架,只需在这个框架的基础上编写相应的代码,从而简化了 windows和Direct3D API的使用,可以高效地...
把DirectX下的示例代码移至DXUT框架下,学习DXUT的同学可以看一下
我想使用DXUY框架,就将DXSDK tutorial的例子 移植过来。却发现使用dxut中的光照之后 使用材质也没有颜色。 我起初怀疑是光照没有起作用,就把材质反射设为100. 居然就出现颜色了。但是方向光是没有衰减的怎么需要...
d3d10渲染到纹理 基于dxut框架 使用directx提供的d3d10的例子EmptyProject10,把相应的主文件换成下载的文件即可运行。
本PDF详细解析微软DirectX游戏框架程序DXUT。想了解DXUT的朋友不能错过哦。
介绍如何使用DXUT框架的控件程序,VC++2005 主要类文件DXUTControl.cpp
基于DXUT框架的三角形面片操作,使用DXUT框架完成各项基本操作
DirectX 3D HLSL高级实例精讲_DXUT库和渲染对象类
DXUT框架剖析,介绍了DXUT的程序框架的创建以及应用
基于微软件DXUT框架设计的程序,使用框架,程序员可以把更多的精力投入到核心算法上
DXUT是一个建立在Direct3D API之上的,被大部分Direct3D指南和例子所使用的层。 它的目标是创建Direct3D例子、原型、工具,更容易的建立坚固、专业的游戏。 • DXUT概观 • 初始化DXUT • 使用基于DXUT的程序窗口 •...
• DXUT概观 • 初始化DXUT • 使用基于DXUT的程序窗口 • 使用DXUT设备 • 使用DXUT主循环 • 处理DXUT的错误 • DXUT高级设备选择 • DXUT高级功能
Microsoft DirectX SDK (August 2009) ,VS2008SP1和XPSP3环境 帖子地址:http://blog.csdn.net/zyq5945/archive/2010/07/29/5775200.aspx
DXUT是directx的一个快速开发游戏的框架, 使用它的话可以隐去很多directx的使用细节, 这个指南介绍这个框架是如何运作的, 和如何使用。
第五部分是附录,包括学习direct3d之前所必须掌握的基础知识和directx sdk提供的各种工具的简要说明。 本书配套光盘提供了书中所有示例程序的可执行文件、工程文件和完整源代码,以方便读者编译、调试示例程序。 ...