• <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>

            李錦俊(mybios)的blog

            游戲開發 C++ Cocos2d-x OpenGL DirectX 數學 計算機圖形學 SQL Server

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              86 Posts :: 0 Stories :: 370 Comments :: 0 Trackbacks

            公告

            QQ:30743734
            EMain:mybios@qq.com

            常用鏈接

            留言簿(16)

            我參與的團隊

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 370257
            • 排名 - 67

            最新評論

            閱讀排行榜

            評論排行榜

            ? 這章主要介紹一下DXUT 里面的GUI元素。要在圖形界面中添加GUI元素,首先要定義一個DialogResourceManager對象用來管理對話框資源。DialogResourceManager 管理渲染時狀態、Sprite控制批量顯示更新、對話框字體、紋理等等。CDXUTDialog?相當于MFC里面的對話框,作為各種控件資源的容器。CD3DSettingsDlg?是一個ms已經寫好的對話框類,可以用來設置各種Direct3DDevice9?創建時的參數。點擊該對話框的ok 按鈕,D3D設備將會重建。
            ? 這里先建立了DialogResourceManager全局變量g_DialogResourceManager和CD3DSettingsDlg?全局變量g_SettingsDlg。并且要在 OnCreateDevice OnResetDevice MsgProc OnLostDevice OnDestroyDevice 回調函數中調用自己相應的函數如g_DialogResourceManager.OnCreateDevice(...) 等等。
            ? 對于對話框對象使用前必須初始化 init() 參數為DialogResourceManager類對象,即g_DialogResourceManager.之后對于CDXUTDialog類對象g_HUD需要設置自己的消息回調函數 OnGUIEvent()。并且在 dxut 的消息處理函數MsgProc中調用自己的消息處理函數 g_HUD->MsgProc(), 如果是該對話框的消息,Dxut回調函數將不再處理這個消息。而交由對話框處理。
            //使用DXUT?框架GUI程序
            #include?<dxstdafx.h>

            //自定義頂點結構
            struct?CUSTOMVERTEX
            {
            ?
            float?x,y,z,rhw;
            ?DWORD?diffuse;
            }
            ;

            ID3DXFont
            *?????g_pFont?=?NULL;?????//?Font?for?drawing?text
            ID3DXSprite*????g_pTextSprite?=?NULL;???//?Sprite?for?batching?draw?text?calls
            bool??????g_bShowHelp?=?true;????//?If?true,?it?renders?the?UI?control?text
            CDXUTDialogResourceManager?g_DialogResourceManager;??//?manager?for?shared?resources?of?dialogs
            CD3DSettingsDlg????g_SettingsDlg;?????//?Device?settings?dialog
            CDXUTDialog?????g_HUD;???????//?dialog?for?standard?controls
            static?const?int???D3DFVF_CUSTOMVERTEX?=?D3DFVF_XYZRHW?|?D3DFVF_DIFFUSE;
            LPDIRECT3DVERTEXBUFFER9??g_pVB;
            bool??????g_vsb?=?true;

            //定義g_HUD對話框上按鈕ID
            static?const?int?IDC_TOGGLEFULLSCREEN=1;??
            static?const?int?IDC_TOGGLEREF=2;
            static?const?int?IDC_CHANGEDEVICE=3;

            HRESULT?CALLBACK?OnCreateDevice(?IDirect3DDevice9
            *?pd3dDevice,?const?D3DSURFACE_DESC*?pBackBufferSurfaceDesc,?void*?pUserContext?);
            HRESULT?CALLBACK?OnResetDevice(?IDirect3DDevice9
            *?pd3dDevice,?const?D3DSURFACE_DESC*?pBackBufferSurfaceDesc,?void*?pUserContext?);
            void????CALLBACK?OnFrameMove(?IDirect3DDevice9*?pd3dDevice,?double?fTime,?float?fElapsedTime,?void*?pUserContext?);
            void????CALLBACK?OnFrameRender(?IDirect3DDevice9*?pd3dDevice,?double?fTime,?float?fElapsedTime,?void*?pUserContext?);
            LRESULT?CALLBACK?MsgProc(?HWND?hWnd,?UINT?uMsg,?WPARAM?wParam,?LPARAM?lParam,?
            bool*?pbNoFurtherProcessing,?void*?pUserContext?);
            void????CALLBACK?KeyboardProc(?UINT?nChar,?bool?bKeyDown,?bool?bAltDown,?void*?pUserContext?);
            void????CALLBACK?OnGUIEvent(?UINT?nEvent,?int?nControlID,?CDXUTControl*?pControl,?void*?pUserContext?);
            void????CALLBACK?OnLostDevice(?void*?pUserContext?);
            void????CALLBACK?OnDestroyDevice(?void*?pUserContext?);
            void????InitApp();
            void????RenderText();

            INT?WINAPI?WinMain(?HINSTANCE,?HINSTANCE,?LPSTR,?
            int?)
            {
            ?
            //為DEBUG模式激活運行時內存檢查
            #if?defined(DEBUG)?|?defined(_DEBUG)
            ?_CrtSetDbgFlag(?_CRTDBG_ALLOC_MEM_DF?
            |?_CRTDBG_LEAK_CHECK_DF?);
            #endif
            ?
            //?設置回調函數,這些函數允許DXUT通知應用程序更換設備,用戶輸入和窗口消息。
            ?
            //?回調函數是可選的,因此你要做的僅是設置你感興趣的事件的回調函數。
            ?DXUTSetCallbackDeviceCreated(?OnCreateDevice?);
            ?DXUTSetCallbackDeviceReset(?OnResetDevice?);
            ?DXUTSetCallbackDeviceLost(?OnLostDevice?);
            ?DXUTSetCallbackDeviceDestroyed(?OnDestroyDevice?);
            ?DXUTSetCallbackFrameRender(?OnFrameRender?);
            ?DXUTSetCallbackFrameMove(?OnFrameMove?);
            ?DXUTSetCallbackMsgProc(?MsgProc?);
            ?DXUTSetCallbackKeyboard(?KeyboardProc?);
            ?
            //?全屏時顯示鼠標
            ?DXUTSetCursorSettings(?true,?true?);
            ?
            //InitApp();
            ?
            //?初始化DXUT并創建想要的Win32窗口和應用程序的Direct3D設備。調用這些
            ?
            //?可選函數中的每一個,此外它們允許你設置幾個選項來控制框架的行為。
            ?DXUTInit(?TRUE,?TRUE,?TRUE?);
            ?DXUTCreateWindow(?L
            "ameng"?);
            ?DXUTCreateDevice(?D3DADAPTER_DEFAULT,?TRUE,?
            640,?480?);
            ?
            //?通過DXUT來處理消息循環并分派渲染調用。當在空閑時間和處理窗口消息的
            ?
            //?時間間隔時,框架將調用OnFrameMove和OnFrameRender回調函數。
            ?DXUTMainLoop();
            ?
            return?DXUTGetExitCode();
            }

            void?InitApp()
            {
            ?
            //?初始化對話框
            ?g_SettingsDlg.Init(&g_DialogResourceManager?);
            ?g_HUD.Init(
            &g_DialogResourceManager?);
            ?
            //設置對話框消息處理函數。
            ?g_HUD.SetCallback(?OnGUIEvent?);?
            ?
            int?iY?=?10;?
            ?g_HUD.AddButton(?IDC_TOGGLEFULLSCREEN,?L
            "Toggle?full?screen",?35,?iY,?125,?22?);
            ?g_HUD.AddButton(?IDC_TOGGLEREF,?L
            "Toggle?REF?(F3)",?35,?iY?+=?24,?125,?22,VK_F3?);
            ?g_HUD.AddButton(?IDC_CHANGEDEVICE,?L
            "Change?device?(F2)",?35,?iY?+=?24,?125,?22,?VK_F2?);
            }



            HRESULT?CALLBACK?OnCreateDevice(?IDirect3DDevice9
            *?pd3dDevice,?const?D3DSURFACE_DESC*?pBackBufferSurfaceDesc,?void*?pUserContext?)
            {
            ?HRESULT?hr;
            ?V_RETURN(?g_DialogResourceManager.OnCreateDevice(?pd3dDevice?)?);
            ??InitApp();
            ?V_RETURN(?g_SettingsDlg.OnCreateDevice(?pd3dDevice?)?);
            ?
            //?Initialize?the?font
            ?V_RETURN(?D3DXCreateFont(?pd3dDevice,?15,?0,?FW_BOLD,?1,?FALSE,?DEFAULT_CHARSET,?
            ??OUT_DEFAULT_PRECIS,?DEFAULT_QUALITY,?DEFAULT_PITCH?
            |?FF_DONTCARE,?
            ??L
            "Arial",?&g_pFont?)?);
            ?
            return?S_OK;
            }

            HRESULT?CALLBACK?OnResetDevice(?IDirect3DDevice9
            *?pd3dDevice,?const?D3DSURFACE_DESC*?pBackBufferSurfaceDesc,?void*?pUserContext?)
            {
            ?HRESULT?hr;
            ?
            static?CUSTOMVERTEX?vertices[]?=
            ?
            {
            ??
            {?300.0f,??50.0f,?0.1f,?1.0f,?D3DCOLOR_ARGB(255,255,0,0)?},?//?x,?y,?z,?rhw,?color
            ??{?500.0f,?350.0f,?0.1f,?1.0f,?D3DCOLOR_ARGB(255,0,255,0)?},
            ??
            {?100.0f,?350.0f,?0.1f,?1.0f,?D3DCOLOR_ARGB(255,0,0,255)?},
            ?}
            ;
            ?pd3dDevice
            ->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&g_pVB,NULL);
            ?BYTE
            *?pVertices;
            ?
            if(?FAILED(?g_pVB->Lock(?0,?sizeof(vertices),?(void**)&pVertices,?0?)))
            ??
            return?E_FAIL;
            ?memcpy(pVertices,vertices,
            sizeof(vertices));
            ?g_pVB
            ->Unlock();
            ?V_RETURN(?g_DialogResourceManager.OnResetDevice()?);
            ?V_RETURN(?g_SettingsDlg.OnResetDevice()?);
            ?
            if(?g_pFont?)
            ??V_RETURN(?g_pFont
            ->OnResetDevice()?);
            ?
            //?Create?a?sprite?to?help?batch?calls?when?drawing?many?lines?of?text
            ?V_RETURN(?D3DXCreateSprite(?pd3dDevice,?&g_pTextSprite?)?);
            ?g_HUD.SetLocation(?pBackBufferSurfaceDesc
            ->Width-170,?0?);
            ?g_HUD.SetSize(?
            170,?170?);
            ?
            return?S_OK;
            }

            void?CALLBACK?OnFrameMove(?IDirect3DDevice9*?pd3dDevice,?double?fTime,?float?fElapsedTime,?void*?pUserContext?)
            {

            }

            void?CALLBACK?OnFrameRender(?IDirect3DDevice9*?pd3dDevice,?double?fTime,?float?fElapsedTime,?void*?pUserContext?)
            {
            ?HRESULT?hr;
            ?V(?pd3dDevice
            ->Clear(0,?NULL,?D3DCLEAR_TARGET?|?D3DCLEAR_ZBUFFER,?D3DCOLOR_ARGB(0,?0,?0,?0),?1.0f,?0)?);
            ?V(pd3dDevice
            ->SetStreamSource(0,g_pVB,0,sizeof(CUSTOMVERTEX)));
            ?V(pd3dDevice
            ->SetFVF(D3DFVF_CUSTOMVERTEX));
            ?
            if(?g_SettingsDlg.IsActive()?)
            ?
            {
            ??g_SettingsDlg.OnRender(?fElapsedTime?);
            ??
            return;
            ?}

            ?
            if(SUCCEEDED(pd3dDevice->BeginScene()))
            ?
            {
            ??
            //更新圖像
            ??V(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,1));
            ??
            if(g_vsb)
            ??
            {
            ???RenderText();
            ??}

            ??V(?g_HUD.OnRender(?fElapsedTime?)?);
            //??V(?g_SampleUI.OnRender(?fElapsedTime?)?);
            ??pd3dDevice->EndScene();
            ?}

            }

            void?RenderText()
            {
            ?
            //?The?helper?object?simply?helps?keep?track?of?text?position,?and?color
            ?
            //?and?then?it?calls?pFont->DrawText(?m_pSprite,?strMsg,?-1,?&rc,?DT_NOCLIP,?m_clr?);
            ?
            //?If?NULL?is?passed?in?as?the?sprite?object,?then?it?will?work?however?the?
            ?
            //?pFont->DrawText()?will?not?be?batched?together.??Batching?calls?will?improves?performance.
            ?CDXUTTextHelper?txtHelper(?g_pFont,?g_pTextSprite,?15?);
            ?
            //?Output?statistics
            ?txtHelper.Begin();
            ?txtHelper.SetInsertionPos(?
            5,?5?);
            ?txtHelper.SetForegroundColor(?D3DXCOLOR(?
            1.0f,?1.0f,?0.0f,?1.0f?)?);
            ?txtHelper.DrawTextLine(?DXUTGetFrameStats(
            true)?);?//為true?顯現FPS,默認為false不顯使FPS
            ?txtHelper.DrawTextLine(?DXUTGetDeviceStats()?);

            ?
            ?
            //TODO:?add?UI?text?as?needed
            ?txtHelper.SetForegroundColor(?D3DXCOLOR(?1.0f,?1.0f,?1.0f,?1.0f?)?);
            ?txtHelper.DrawTextLine(?L
            "Put?whatever?misc?status?here"?);

            ?
            //?獲取圖象后備緩沖區
            ?const?D3DSURFACE_DESC*?pd3dsdBackBuffer?=?DXUTGetBackBufferSurfaceDesc();
            ?
            if(?g_bShowHelp?)
            ?
            {
            ??txtHelper.SetInsertionPos(?
            10,?pd3dsdBackBuffer->Height-15*6?);
            ??txtHelper.SetForegroundColor(?D3DXCOLOR(?
            1.0f,?0.75f,?0.0f,?1.0f?)?);
            ??txtHelper.DrawTextLine(?L
            "Controls?(F1?to?hide):"?);
            ??txtHelper.SetInsertionPos(?
            40,?pd3dsdBackBuffer->Height-15*5?);
            ??txtHelper.DrawTextLine(?L
            "Quit:?ESC"?);
            ?}

            ?
            else
            ?
            {
            ??
            //txtHelper.SetInsertionPos(?10,?pd3dsdBackBuffer->Height-15*2?);
            ??txtHelper.SetForegroundColor(?D3DXCOLOR(?1.0f,?1.0f,?1.0f,?1.0f?)?);
            ??txtHelper.DrawTextLine(?L
            "Press?F1?for?help"?);
            ?}

            ?
            ?txtHelper.End();
            }


            //--------------------------------------------------------------------------------------
            //?Before?handling?window?messages,?DXUT?passes?incoming?windows?
            //?messages?to?the?application?through?this?callback?function.?If?the?application?sets?
            //?*pbNoFurtherProcessing?to?TRUE,?then?DXUT?will?not?process?this?message.
            //--------------------------------------------------------------------------------------
            LRESULT?CALLBACK?MsgProc(?HWND?hWnd,?UINT?uMsg,?WPARAM?wParam,?LPARAM?lParam,?bool*?pbNoFurtherProcessing,?void*?pUserContext?)
            {
            ?
            //?Always?allow?dialog?resource?manager?calls?to?handle?global?messages
            ?
            //?so?GUI?state?is?updated?correctly
            ?*pbNoFurtherProcessing?=?g_DialogResourceManager.MsgProc(?hWnd,?uMsg,?wParam,?lParam?);
            ?
            if(?*pbNoFurtherProcessing?)
            ??
            return?0;
            ?
            if(?g_SettingsDlg.IsActive()?)
            ?
            {
            ??g_SettingsDlg.MsgProc(?hWnd,?uMsg,?wParam,?lParam?);
            ??
            return?0;
            ?}

            ?
            //?Give?the?dialogs?a?chance?to?handle?the?message?first
            ?*pbNoFurtherProcessing?=?g_HUD.MsgProc(?hWnd,?uMsg,?wParam,?lParam?);
            ?
            if(?*pbNoFurtherProcessing?)
            ??
            return?0;
            ?
            return?0;
            }


            //--------------------------------------------------------------------------------------
            //?As?a?convenience,?DXUT?inspects?the?incoming?windows?messages?for
            //?keystroke?messages?and?decodes?the?message?parameters?to?pass?relevant?keyboard
            //?messages?to?the?application.??The?framework?does?not?remove?the?underlying?keystroke?
            //?messages,?which?are?still?passed?to?the?application's?MsgProc?callback.
            //--------------------------------------------------------------------------------------
            void?CALLBACK?KeyboardProc(?UINT?nChar,?bool?bKeyDown,?bool?bAltDown,?void*?pUserContext?)
            {
            ?
            if(?bKeyDown?)
            ?
            {
            ??
            switch(?nChar?)
            ??
            {
            ???
            case?VK_F1:?
            ????g_bShowHelp?
            =?!g_bShowHelp;?
            ????
            break;
            ???
            case?VK_F4:
            ????g_HUD.SetVisible(
            !g_HUD.GetVisible());
            ????g_vsb?
            =?!g_vsb;
            ????
            break;
            ???
            default:
            ????
            break;
            ??}

            ?}

            }


            //--------------------------------------------------------------------------------------
            //?Handles?the?GUI?events
            //--------------------------------------------------------------------------------------
            void?CALLBACK?OnGUIEvent(?UINT?nEvent,?int?nControlID,?CDXUTControl*?pControl,?void*?pUserContext?)
            {
            ?
            switch(?nControlID?)
            ?
            {
            ??
            case?IDC_TOGGLEFULLSCREEN:?
            ???DXUTToggleFullScreen();?
            ???
            break;
            ??
            case?IDC_TOGGLEREF:????????
            ???DXUTToggleREF();?
            ???
            break;
            ??
            case?IDC_CHANGEDEVICE:?????
            ???g_SettingsDlg.SetActive(?
            !g_SettingsDlg.IsActive()?);?
            ???
            break;
            ?}

            }

            void?CALLBACK?OnLostDevice(?void*?pUserContext?)
            {
            ?
            if(g_pVB?!=?NULL)
            ?
            {
            ??g_pVB
            ->Release();
            ??g_pVB?
            =?NULL;
            ?}

            ?g_DialogResourceManager.OnLostDevice();
            ?g_SettingsDlg.OnLostDevice();
            ?
            if(?g_pFont?)
            ??g_pFont
            ->OnLostDevice();
            ?
            ?SAFE_RELEASE(?g_pTextSprite?);
            }

            void?CALLBACK?OnDestroyDevice(?void*?pUserContext?)
            {
            ?g_DialogResourceManager.OnDestroyDevice();
            ?g_SettingsDlg.OnDestroyDevice();
            ?SAFE_RELEASE(?g_pFont?);
            }
            posted on 2006-11-18 09:02 李錦俊(mybios) 閱讀(1990) 評論(0)  編輯 收藏 引用 所屬分類: Direct3D
            精品熟女少妇a∨免费久久| 伊人久久久AV老熟妇色| 久久久久久夜精品精品免费啦| 亚洲国产一成久久精品国产成人综合 | 久久亚洲精品国产精品| 久久中文字幕人妻丝袜| 久久影院午夜理论片无码| 国内精品久久久久久麻豆| 91精品国产91久久久久久| 久久久久久综合一区中文字幕| 久久w5ww成w人免费| 精品亚洲综合久久中文字幕| 精品久久久久久无码专区| 久久久久亚洲av无码专区喷水| 人妻精品久久久久中文字幕69| 性色欲网站人妻丰满中文久久不卡| 伊人久久大香线蕉av一区| 亚洲av伊人久久综合密臀性色| 99精品国产综合久久久久五月天 | 思思久久好好热精品国产| 亚洲精品无码久久不卡| 最新久久免费视频| 亚洲精品无码久久久久| 99久久人妻无码精品系列 | 国产亚洲婷婷香蕉久久精品 | 日本一区精品久久久久影院| 成人亚洲欧美久久久久| 久久久久久国产a免费观看不卡| 久久人妻少妇嫩草AV蜜桃| 免费无码国产欧美久久18| 日产精品99久久久久久| 久久国产精品国产自线拍免费| 久久综合丁香激情久久| 色8激情欧美成人久久综合电| 日韩人妻无码精品久久免费一| 99精品国产在热久久无毒不卡 | 7777精品伊人久久久大香线蕉| 久久WWW免费人成一看片| 久久精品一区二区国产| 久久无码一区二区三区少妇| 99久久精品免费看国产一区二区三区 |