DXUT工程文件

这是我整理的DXUT的工程文件.DXUT框架回调函数,我总是记不住顺序和关系,所以自己写了个模版文件.

真理就贴出来了.

 

// --------------------------------------------------------------------------------------
//  File: 
//
//  
//
//  Copyright (c) . All rights reserved.
// --------------------------------------------------------------------------------------
#include  < dxstdafx.h >
// #include "resource.h"

/***
程序启动:InitApp →MsgProc →IsDeviceAcceptable →ModifyDeviceSettings → OnCreateDevice →OnResetDevice → 渲染主循环 
渲染主循环:OnFrameMove → OnFrameRender 
改变设备:ModifyDeviceSettings → OnLostDevice →根据需要调用OnDestroyDevice → OnResetDevice → 渲染主循环 
程序退出:OnLostDevice →OnDestroyDevice
**
*/


// --------------------------------------------------------------------------------------
//  Rejects any devices that aren't acceptable by returning false
// --------------------------------------------------------------------------------------
bool  CALLBACK IsDeviceAcceptable( D3DCAPS9 *  pCaps, D3DFORMAT AdapterFormat, 
                                  D3DFORMAT BackBufferFormat, 
bool  bWindowed,  void *  pUserContext )
{
    
// Typically want to skip backbuffer formats that don't support alpha blending
    IDirect3D9* pD3D = DXUTGetD3DObject(); 
    
if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType,
                    AdapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, 
                    D3DRTYPE_TEXTURE, BackBufferFormat ) ) )
        
return false;

    
return true;
}


// --------------------------------------------------------------------------------------
//  Create any D3DPOOL_MANAGED resources here 
// --------------------------------------------------------------------------------------
//  当Directx3D设备被创建后,这个回调函数马上被调用,因为D3DPOOL_MANAGED资源在设备被销毁后
//  需要重新装载,这里是最佳创建D3DPOOL_MANAGED资源的地方,创建的资源应在 OnDestroyDevice 
//  函数中销毁 。
// --------------------------------------------------------------------------------------
HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9 *  pd3dDevice,  const  D3DSURFACE_DESC *  pBackBufferSurfaceDesc,  void *  pUserContext )
{
    
return S_OK;
}


// --------------------------------------------------------------------------------------
//  Before a device is created, modify the device settings as needed
// --------------------------------------------------------------------------------------
bool  CALLBACK ModifyDeviceSettings( DXUTDeviceSettings *  pDeviceSettings,  const  D3DCAPS9 *  pCaps,  void *  pUserContext )
{
    
return true;
}


// --------------------------------------------------------------------------------------
//  Create any D3DPOOL_DEFAULT resources here 
// --------------------------------------------------------------------------------------
//  当direct3d设备被复位后,这个函数立即被调用,这里最好放置D3DPOOL_DEFAULT 资源代码,因为这
//  这些资源在设备丢失后需要重新装载。在这里创建的资源应该在OnLostDevice 函数中释放
// --------------------------------------------------------------------------------------
HRESULT CALLBACK OnResetDevice( IDirect3DDevice9 *  pd3dDevice, 
                                
const  D3DSURFACE_DESC *  pBackBufferSurfaceDesc,  void *  pUserContext )
{
    
return S_OK;
}


// --------------------------------------------------------------------------------------
//  Handle messages to the application 
// --------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, 
                         
bool *  pbNoFurtherProcessing,  void *  pUserContext )
{
    
return 0;
}


// --------------------------------------------------------------------------------------
//  Handle updates to the scene
// -------------------------------------------------------------------------------------- 
// 这个回调函数在每帧的开始被调用,这个在你的程序中用来处理场景更新最好的位置,但不能包含实际的
// 场景渲染调用,渲染工作应该放在OnFrameRender 回调函数中。常用于矩阵转换、摄像机等操作。
void  CALLBACK OnFrameMove( IDirect3DDevice9 *  pd3dDevice,  double  fTime,  float  fElapsedTime,  void *  pUserContext )
{
}


// --------------------------------------------------------------------------------------
//  Render the scene 
// --------------------------------------------------------------------------------------
// 此回调函数在每Frame最后被调用,在场景上执行所有的渲染调用,当窗口需要重绘(处理WM_PAINT消
// 息)时此函数也会被调用(此时不调用OnFrameMove),在此函数返回后,DXUT将调用
// IDirect3DDevice9::Present 来显示翻转链中下一个缓冲区内容。
// --------------------------------------------------------------------------------------
void  CALLBACK OnFrameRender( 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(0128128128), 1.0f0) );

    
// Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    
{
        V( pd3dDevice
->EndScene() );
    }

}


// --------------------------------------------------------------------------------------
//  Release resources created in the OnResetDevice callback here 
// --------------------------------------------------------------------------------------
//  在Direct3D设备进入lost状态后在IDirect3DDevice9::Reset 调用之前调用此函数,在OnResetDevice 
//  中创建的资源必须在这里释放,通常包括所有的D3DPOOL_DEFAULT 资源,
// --------------------------------------------------------------------------------------
void  CALLBACK OnLostDevice(  void *  pUserContext )
{
}


// --------------------------------------------------------------------------------------
//  Release resources created in the OnCreateDevice callback here
// -------------------------------------------------------------------------------------- 
// 此回调函数在direct3d设备被销毁时调用,通常发生在程序终止,在OnCreateDevice 中创建的资源,要
// 在这里释放,通常包含所有的D3DPOOL_MANAGED资源
// IDirect3DDevice9::Present 来显示翻转链中下一个缓冲区内容。
// --------------------------------------------------------------------------------------
void  CALLBACK OnDestroyDevice(  void *  pUserContext )
{
}


// --------------------------------------------------------------------------------------
//  Initialize everything and go into a render loop
// --------------------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR,  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
    DXUTSetCallbackDeviceCreated( OnCreateDevice );
    DXUTSetCallbackDeviceReset( OnResetDevice );
    DXUTSetCallbackDeviceLost( OnLostDevice );
    DXUTSetCallbackDeviceDestroyed( OnDestroyDevice );
    DXUTSetCallbackMsgProc( MsgProc );
    DXUTSetCallbackFrameRender( OnFrameRender );
    DXUTSetCallbackFrameMove( OnFrameMove );
   
    
// TODO: Perform any application-level initialization here

    
// Initialize DXUT and create the desired Win32 window and Direct3D device for the application
    
// 初始化DXUT并创建想要的Win32窗口和应用程序的Direct3D设备。调用这些
    
// 可选函数中的每一个,此外它们允许你设置几个选项来控制框架的行为。
    DXUTInit( truetruetrue ); // Parse the command line, handle the default hotkeys, and show msgboxes
    DXUTSetCursorSettings( truetrue ); // Show the cursor and clip it when in full screen
    DXUTCreateWindow( L"DXUT" );
    DXUTCreateDevice( D3DADAPTER_DEFAULT, 
true640480, IsDeviceAcceptable, ModifyDeviceSettings );

    
// Start the render loop
    
// 通过DXUT来处理消息循环并分派渲染调用。当在空闲时间和处理窗口消息的
    
// 时间间隔时,框架将调用OnFrameMove和OnFrameRender回调函数。
    DXUTMainLoop();

    
// TODO: Perform any application-level cleanup here

    
return DXUTGetExitCode();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值