青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

網格模型高級技術(10)

類CDXUTMeshFrame的詳細說明請參閱DXUT源碼分析 ---- 類CDXUTMeshFrame

類CDXUTMeshFile的詳細說明請參閱DXUT源碼分析 ---- 類CDXUTMeshFile。

 

使用類CDXUTMeshFile進行網格模型的繪制

首先在OnCreateDevice()里創建CDXUTMeshFile對象:

g_dxut_mesh_file = new CDXUTMeshFile();
g_dxut_mesh_file->Create(pd3dDevice, L"Dwarf.x");

接著在OnFrameRender()里渲染網格模型:

// Render the scene
if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
g_dxut_mesh_file->Render(pd3dDevice, &g_mat_world);
RenderText();
V(g_button_dlg.OnRender(fElapsedTime));
    V( pd3dDevice->EndScene() );
}

最后在OnDestroyDevice()里釋放該對象所申請的資源:

g_dxut_mesh_file->Destroy();
SAFE_DELETE(g_dxut_mesh_file);

 

示例截圖:

 

主程序:

#include "dxstdafx.h"
#include 
"resource.h"

#pragma warning(disable : 
4127 4995)

#define IDC_TOGGLE_FULLSCREEN    1
#define IDC_TOGGLE_REF            2
#define IDC_CHANGE_DEVICE        3

#define release_com(p)    do { if(p) { (p)->Release(); (p) = NULL; } } while(0)

ID3DXFont
*                    g_font;
ID3DXSprite
*                g_text_sprite;
bool                        g_show_help;

CDXUTDialogResourceManager    g_dlg_resource_manager;
CD3DSettingsDlg                g_settings_dlg;
CDXUTDialog                    g_button_dlg;

CDXUTMeshFile
*                g_dxut_mesh_file;
D3DXMATRIX                    g_mat_world;

//--------------------------------------------------------------------------------------
// 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;
}


//--------------------------------------------------------------------------------------
// Before a device is created, modify the device settings as needed.
//--------------------------------------------------------------------------------------
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps, void* pUserContext )
{
    
// If video card does not support hardware vertex processing, then uses sofaware vertex processing.
    if((pCaps->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0)
        pDeviceSettings
->BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;

    
static bool is_first_time = true;

    
if(is_first_time)
    {
        is_first_time 
= false;

        
// if using reference device, then pop a warning message box.
        if(pDeviceSettings->DeviceType == D3DDEVTYPE_REF)
            DXUTDisplaySwitchingToREFWarning();
    }

    
return true;
}

//--------------------------------------------------------------------------------------
// Remove path from fullname, and convert filename from multibyte to wchar.
//--------------------------------------------------------------------------------------
void RemovePathFromFileName(LPSTR fullname, LPWSTR wfilename)
{
    WCHAR wbuf[MAX_PATH]  
= {0};
    MultiByteToWideChar(CP_ACP, 
0, fullname, -1, wbuf, MAX_PATH);

    LPWSTR w_last_back_slash 
= wcsrchr(wbuf, '\\');

    
if(w_last_back_slash)
        lstrcpy(wfilename, 
++w_last_back_slash);
    
else
        lstrcpy(wfilename, wbuf);
}


//--------------------------------------------------------------------------------------
// Create any D3DPOOL_MANAGED resources here 
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, 
                                 
const D3DSURFACE_DESC* pBackBufferSurfaceDesc, 
                                 
void* pUserContext )
{
    HRESULT    hr;

    V_RETURN(g_dlg_resource_manager.OnCreateDevice(pd3dDevice));
    V_RETURN(g_settings_dlg.OnCreateDevice(pd3dDevice));

    D3DXCreateFont(pd3dDevice, 
180, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
                   DEFAULT_PITCH 
| FF_DONTCARE, L"Arial"&g_font);
    
    g_dxut_mesh_file 
= new CDXUTMeshFile();
    g_dxut_mesh_file
->Create(pd3dDevice, L"Dwarf.x");

    
return S_OK;
}


//--------------------------------------------------------------------------------------
// Create any D3DPOOL_DEFAULT resources here 
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice, 
                                
const D3DSURFACE_DESC* pBackBufferSurfaceDesc, 
                                
void* pUserContext )
{
    HRESULT hr;

    V_RETURN(g_dlg_resource_manager.OnResetDevice());
    V_RETURN(g_settings_dlg.OnResetDevice());
    V_RETURN(g_font
->OnResetDevice());
    V_RETURN(D3DXCreateSprite(pd3dDevice, 
&g_text_sprite));

    
// set dialog position and size

    g_button_dlg.SetLocation(pBackBufferSurfaceDesc
->Width - 1700);
    g_button_dlg.SetSize(
170170);

    
// setup view matrix

    D3DXMATRIX mat_view;
    D3DXVECTOR3 eye(
0.0f0.0f,   -5.0f);
    D3DXVECTOR3  at(
0.0f0.0f,    0.0f);
    D3DXVECTOR3  up(
0.0f1.0f,    0.0f);

    D3DXMatrixLookAtLH(
&mat_view, &eye, &at, &up);
    pd3dDevice
->SetTransform(D3DTS_VIEW, &mat_view);

    
// set projection matrix
    D3DXMATRIX mat_proj;
    
float aspect = (float)pBackBufferSurfaceDesc->Width / pBackBufferSurfaceDesc->Height;
    D3DXMatrixPerspectiveFovLH(
&mat_proj, D3DX_PI/4, aspect, 1.0f100.0f);
    pd3dDevice
->SetTransform(D3DTS_PROJECTION, &mat_proj);

    
// setup light
    
    D3DLIGHT9 light;
    ZeroMemory(
&light, sizeof(D3DLIGHT9));

    light.Type       
= D3DLIGHT_DIRECTIONAL;
    light.Diffuse.r  
= 1.0f;
    light.Diffuse.g  
= 1.0f;
    light.Diffuse.b  
= 1.0f;
    light.Range         
= 1000.0f;

    D3DXVECTOR3 light_dir(
0.0f-1.0f1.0f);    
    D3DXVec3Normalize((D3DXVECTOR3
*&light.Direction, &light_dir);
    pd3dDevice
->SetLight(0&light);
    pd3dDevice
->LightEnable(0, TRUE);
    pd3dDevice
->SetRenderState(D3DRS_LIGHTING, TRUE);

    pd3dDevice
->SetRenderState(D3DRS_AMBIENT, 0x0080FFFF);

    
return S_OK;
}

//--------------------------------------------------------------------------------------
// Release resources created in the OnResetDevice callback here 
//--------------------------------------------------------------------------------------
void CALLBACK OnLostDevice( void* pUserContext )
{
    g_dlg_resource_manager.OnLostDevice();
    g_settings_dlg.OnLostDevice();
    g_font
->OnLostDevice();

    release_com(g_text_sprite);
}


//--------------------------------------------------------------------------------------
// Release resources created in the OnCreateDevice callback here
//--------------------------------------------------------------------------------------
void CALLBACK OnDestroyDevice( void* pUserContext )
{
    g_dlg_resource_manager.OnDestroyDevice();
    g_settings_dlg.OnDestroyDevice();    

    release_com(g_font);

    g_dxut_mesh_file
->Destroy();
    SAFE_DELETE(g_dxut_mesh_file);
}

//--------------------------------------------------------------------------------------
// Handle updates to the scene
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    D3DXMATRIX mat_trans, mat_rot;
    D3DXMatrixTranslation(
&mat_trans, 0.0f-0.7f0.0f);
    D3DXMatrixRotationY(
&mat_rot, timeGetTime() / 1000.0f);
    
    g_mat_world 
= mat_trans * mat_rot;
}

//--------------------------------------------------------------------------------------
// Render the helper information
//--------------------------------------------------------------------------------------
void RenderText()
{
    CDXUTTextHelper text_helper(g_font, g_text_sprite, 
20);
    
    text_helper.Begin();

    
// show frame and device states
    text_helper.SetInsertionPos(55);
    text_helper.SetForegroundColor( D3DXCOLOR(
1.0f0.475f0.0f1.0f) );
    text_helper.DrawTextLine( DXUTGetFrameStats(
true) );
    text_helper.DrawTextLine( DXUTGetDeviceStats() );

    
// show helper information
    
    
const D3DSURFACE_DESC* surface_desc = DXUTGetBackBufferSurfaceDesc();

    
if(g_show_help)
    {
        text_helper.SetInsertionPos(
10, surface_desc->Height - 15 * 6);
        text_helper.SetForegroundColor( D3DXCOLOR(
1.0f0.475f0.0f1.0f) );
        text_helper.DrawTextLine(L
"Controls (F1 to hide):");
        
        text_helper.SetInsertionPos(
40, surface_desc->Height - 15 * 4);
        text_helper.DrawTextLine(L
"Quit: ESC");
    }
    
else
    {
        text_helper.SetInsertionPos(
10, surface_desc->Height - 15 * 4);
        text_helper.SetForegroundColor( D3DXCOLOR(
1.0f1.0f1.0f1.0f) );
        text_helper.DrawTextLine(L
"Press F1 for help");
    }

    text_helper.End();
}

//--------------------------------------------------------------------------------------
// Render the scene 
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    HRESULT hr;

    
if(g_settings_dlg.IsActive())
    {
        g_settings_dlg.OnRender(fElapsedTime);
        
return;
    }

    
// Clear the render target and the zbuffer 
    V( pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0000), 1.0f0) );

    
// Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {                            
        g_dxut_mesh_file
->Render(pd3dDevice, &g_mat_world);
        RenderText();
        V(g_button_dlg.OnRender(fElapsedTime));

        V( pd3dDevice
->EndScene() );
    }
}


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

    
if(g_settings_dlg.IsActive())
    {
        g_settings_dlg.MsgProc(hWnd, uMsg, wParam, lParam);
        
return 0;
    }

    
*pbNoFurtherProcessing = g_button_dlg.MsgProc(hWnd, uMsg, wParam, lParam);
    
if(*pbNoFurtherProcessing)
        
return 0;

    
return 0;
}


//--------------------------------------------------------------------------------------
// Handle keybaord event
//--------------------------------------------------------------------------------------
void CALLBACK OnKeyboardProc(UINT charater, bool is_key_down, bool is_alt_down, void* user_context)
{
    
if(is_key_down)
    {
        
switch(charater)
        {
        
case VK_F1:
            g_show_help 
= !g_show_help;
            
break;
        }
    }
}

//--------------------------------------------------------------------------------------
// Handle events for controls
//--------------------------------------------------------------------------------------
void CALLBACK OnGUIEvent(UINT eventint control_id, CDXUTControl* control, void* user_context)
{
    
switch(control_id)
    {
    
case IDC_TOGGLE_FULLSCREEN:
        DXUTToggleFullScreen();
        
break;

    
case IDC_TOGGLE_REF:
        DXUTToggleREF();
        
break;

    
case IDC_CHANGE_DEVICE:
        g_settings_dlg.SetActive(
true);
        
break;
    }
}

//--------------------------------------------------------------------------------------
// Initialize dialogs
//--------------------------------------------------------------------------------------
void InitDialogs()
{
    g_settings_dlg.Init(
&g_dlg_resource_manager);
    g_button_dlg.Init(
&g_dlg_resource_manager);

    g_button_dlg.SetCallback(OnGUIEvent);

    
int x = 35, y = 10, width = 125, height = 22;

    g_button_dlg.AddButton(IDC_TOGGLE_FULLSCREEN, L
"Toggle full screen", x, y,         width, height);
    g_button_dlg.AddButton(IDC_TOGGLE_REF,          L
"Toggle REF (F3)",     x, y += 24, width, height);
    g_button_dlg.AddButton(IDC_CHANGE_DEVICE,      L
"Change device (F2)", x, y += 24, width, height, VK_F2);    
}

//--------------------------------------------------------------------------------------
// 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 );
    DXUTSetCallbackKeyboard(OnKeyboardProc);
   
    
// TODO: Perform any application-level initialization here
    InitDialogs();

    
// Initialize DXUT and create the desired Win32 window and Direct3D device for the application
    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"Use DXUT Mesh File Class" );
    DXUTCreateDevice( D3DADAPTER_DEFAULT, 
true640480, IsDeviceAcceptable, ModifyDeviceSettings );

    
// Start the render loop
    DXUTMainLoop();

    
// TODO: Perform any application-level cleanup here

    
return DXUTGetExitCode();
}

 

下載示例工程(不包含資源)


posted on 2008-06-01 11:30 lovedday 閱讀(953) 評論(1)  編輯 收藏 引用

評論

# hi 能和你聊聊么:) 2008-06-05 01:28 gogoaoe

能和你聊聊么:),我的游戲剛剛OB cs.playcool.com 我叫王琦
QQ 110714997 msn gogoaoe2449@hotmail.com  回復  更多評論   


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲三级电影在线观看 | 国产精品高潮视频| 亚洲国产另类精品专区| 美女任你摸久久| 久久综合一区二区三区| 亚洲国产欧美一区二区三区久久| 免费人成精品欧美精品| 欧美成人a∨高清免费观看| 亚洲久久一区二区| 亚洲视频成人| 国产一区av在线| 欧美成人亚洲成人| 欧美精品1区2区| 亚洲欧美日韩系列| 久久爱www久久做| 亚洲乱码国产乱码精品精可以看 | 免费亚洲电影在线| 欧美激情精品久久久六区热门| 99精品视频网| 亚洲欧美日韩国产一区二区三区| 国内偷自视频区视频综合| 欧美高清在线观看| 欧美性事在线| 免费精品视频| 国产精品视频99| 女人香蕉久久**毛片精品| 欧美交受高潮1| 久久精品青青大伊人av| 在线亚洲国产精品网站| 亚洲午夜一区二区三区| 精品成人国产| 99在线精品观看| 影音先锋久久资源网| 亚洲视频第一页| 亚洲激情av在线| 亚洲欧美日韩一区二区在线| 91久久在线观看| 欧美一区二区三区视频免费| 日韩亚洲综合在线| 久久久精品日韩| 午夜精彩视频在线观看不卡 | 亚洲高清不卡在线| 国产精品呻吟| 亚洲精品中文字幕女同| 国语自产精品视频在线看8查询8| 99国产成+人+综合+亚洲欧美| 国内精品久久久久影院薰衣草| 99精品99| 亚洲精品综合| 美女视频一区免费观看| 欧美在线观看视频一区二区| 欧美日韩你懂的| 亚洲第一天堂无码专区| 黄色日韩精品| 性刺激综合网| 久久精品女人的天堂av| 国产女主播一区二区| 99热免费精品| 在线午夜精品| 欧美日韩亚洲高清| 亚洲人成亚洲人成在线观看| 亚洲国产精品成人综合色在线婷婷| 亚洲欧美日韩一区在线观看| 亚洲一区二区三区四区五区黄| 欧美极品aⅴ影院| 亚洲二区视频| 亚洲三级免费电影| 免费欧美日韩国产三级电影| 开心色5月久久精品| 在线成人中文字幕| 久久最新视频| 欧美激情一区二区久久久| 在线免费观看日韩欧美| 久久久99爱| 欧美激情一区二区三区高清视频| 亚洲第一在线综合在线| 葵司免费一区二区三区四区五区| 奶水喷射视频一区| 亚洲裸体俱乐部裸体舞表演av| 欧美黑人在线播放| 一本大道久久a久久精二百| 亚洲午夜久久久久久尤物| 欧美视频手机在线| 亚洲欧美在线一区二区| 久久久精品五月天| 亚洲国产欧美另类丝袜| 欧美精品黄色| 在线亚洲观看| 久久免费观看视频| 亚洲国产一区二区视频| 欧美日韩成人激情| 亚洲欧洲av一区二区| 快播亚洲色图| 亚洲在线一区二区三区| 欧美在线不卡视频| 亚洲高清视频一区| 欧美日韩亚洲在线| 欧美亚洲视频一区二区| 欧美va亚洲va日韩∨a综合色| 亚洲精品资源美女情侣酒店| 国产精品多人| 久久亚洲精品中文字幕冲田杏梨| 最新国产成人在线观看| 久久精品免费观看| 日韩午夜av电影| 国产麻豆日韩| 欧美精品一区在线| 欧美在线视频播放| 日韩视频久久| 久久久精品国产99久久精品芒果| 亚洲人成高清| 国产欧美日韩视频一区二区三区| 裸体歌舞表演一区二区| 亚洲在线观看视频网站| 亚洲国产精品免费| 久久人人97超碰人人澡爱香蕉| 亚洲精品韩国| 在线免费观看视频一区| 国产精品日韩在线观看| 欧美成人精品在线视频| 欧美制服丝袜| 亚洲香蕉网站| 亚洲剧情一区二区| 欧美高清视频一区| 美女精品在线| 久久国产天堂福利天堂| 亚洲午夜一二三区视频| 亚洲人被黑人高潮完整版| 国产亚洲成人一区| 国产精品美女999| 欧美视频一区二区三区…| 麻豆精品一区二区综合av| 久久精品99无色码中文字幕| 国产精品99久久久久久有的能看| 91久久久久| 亚洲黄色免费| 亚洲高清网站| 欧美国产日韩一区二区| 久久夜色精品国产| 久久亚洲欧美| 久久中文欧美| 免费成人网www| 美女精品在线| 欧美国产日韩一区| 最新国产精品拍自在线播放| 欧美国产一区在线| 亚洲国产欧美另类丝袜| 亚洲国产天堂久久综合网| 欧美激情一区二区三区在线视频观看| 老鸭窝毛片一区二区三区 | 亚洲精品日产精品乱码不卡| 亚洲国产99| 亚洲美女视频网| 一区二区三区免费网站| 一区二区三区波多野结衣在线观看| 亚洲精品欧洲| 亚洲愉拍自拍另类高清精品| 亚洲欧美国产毛片在线| 午夜免费电影一区在线观看| 午夜视频在线观看一区二区| 欧美一区二区高清在线观看| 久久黄色影院| 欧美va天堂va视频va在线| 亚洲国内高清视频| 夜夜夜精品看看| 欧美一区免费| 免费在线观看成人av| 午夜一级在线看亚洲| 久久福利毛片| 亚洲第一在线综合在线| 亚洲精品乱码久久久久久按摩观 | 欧美电影资源| 亚洲精品视频在线看| 亚洲免费婷婷| 美女亚洲精品| 国产精品日韩精品| 伊大人香蕉综合8在线视| 亚洲美女毛片| 久久精品三级| 亚洲人体1000| 欧美亚洲免费电影| 欧美精品激情blacked18| 国产精品久久久久免费a∨大胸| 国产亚洲欧美日韩日本| 亚洲精品久久久一区二区三区| 亚洲影视综合| 欧美激情亚洲一区| 亚洲一区在线播放| 欧美高清视频www夜色资源网| 国产精品久久久久久久浪潮网站 | 欧美视频精品一区| 国产主播一区二区三区| 99re66热这里只有精品4| 久久精品人人做人人爽| 亚洲精品欧洲| 老鸭窝毛片一区二区三区 | 久久伊人一区二区| 国产精品视频一| 一本大道久久a久久精二百| 久久久亚洲影院你懂的|