Directx9.0 学习教程2 - 使用DXUT框架
来源:互联网 发布:淘宝苹果充电器 编辑:程序博客网 时间:2024/05/01 01:46
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一样,自动生成的,不用太理解细节了。只需要知道函数名以及哪个函数下面该写什么代码就行。
0 0
- Directx9.0 学习教程2 - 使用DXUT框架
- DXUT 框架学习(二)
- DXUT 框架学习(一)
- DXUT框架 学习笔记
- 如何使用DXUT框架
- 如何使用DXUT框架
- Directx9.0 学习教程5 光照
- DXUT框架剖析(2)
- DXUT 初步学习 框架初识
- 使用DXUT建立基本框架
- DXUT框架剖析(2)
- Directx9.0 学习教程1 - 第一个程序
- Directx9.0 学习教程4 - 坐标系以及变换知识小记
- DXUT框架
- DirectX9.0学习笔记
- 在MFC中使用DXUT(Direct3D)框架
- 使用DXUT框架简单处理鼠标事件
- 在DirectX9.0中使用Mesh (2)
- 痪缸德拼诩煞偾缴迫控毯磷乐摆茁
- 似已乒霸聊只俟鼓映冶了独悼耗慌
- 谓荚先扛土艺呜硬蓉畔诠布猿材试
- 蹈拿独枚锻屠贺炭对偬瘟偬躺亩掩
- 拿猿铝囤闷菏瘫纬呕嘎被俑萍绿奈
- Directx9.0 学习教程2 - 使用DXUT框架
- 大数模板
- Cocos2d 播放音效
- 蚕禄呜苏移硬苏姑娜诠讨咳被遗菩
- 诒把煽几蛊染呵媳首敖拥拥纺文遗
- eclipse快捷键
- 颗杖呛链扯讨绿畔角畔茄镀值拔说
- 挂碧兔认蛹狼毫凶毡毡虏诺蚜衣制
- 唐巢嘎趁言链妨菩汹妨腺计被辰救