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

            C++ Programmer's Cookbook

            {C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

            Managed directx 檢查硬件支持和實現全屏顯示

            c#代碼:
            //-----------------------------------------------------------------------------
            //???????????Name:?dx9cs_fullscreen.cs
            //?????????Author:?Kevin?Harris
            //??Last?Modified:?06/15/05
            //????Description:?This?sample?demonstrates?how?to?probe?the?hardware?for?
            //?????????????????specific?Display?or?Adaptor?Modes?and?hardware?support?
            //?????????????????suitable?for?a?full-screen?application?with?Direct3D.
            //-----------------------------------------------------------------------------

            using?System;
            using?System.Drawing;
            using?System.Windows.Forms;
            using?Microsoft.DirectX;
            using?Microsoft.DirectX.Direct3D;

            namespace?DX9Sample
            {
            ????
            public?class?DX9Form?:?System.Windows.Forms.Form
            ????
            {
            ????????
            private?Device?d3dDevice?=?null;

            ????????
            public?DX9Form()
            ????????
            {
            ????????????
            this.ClientSize?=?new?System.Drawing.Size(?640,?480?);
            ????????????
            this.Text?=?"Direct3D?(DX9/C#)?-?Full?Screen";
            ????????????
            this.SetStyle(?ControlStyles.AllPaintingInWmPaint?|?ControlStyles.Opaque,?true?);
            ????????}


            ????????
            protected?override?void?OnPaint(System.Windows.Forms.PaintEventArgs?e)
            ????????
            {
            ????????????
            this.Render();
            ????????????
            this.Invalidate();
            ????????}


            ????????
            protected?override?void?OnKeyDown(System.Windows.Forms.KeyEventArgs?e)
            ????????
            {
            ????????????
            switch(?e.KeyCode?)
            ????????????
            {
            ????????????????
            case?System.Windows.Forms.Keys.Escape:
            ????????????????????
            this.Dispose();
            ????????????????????
            break;
            ????????????}

            ????????}


            ????????
            protected?override?void?Dispose(bool?disposing)
            ????????
            {
            ????????????
            base.Dispose(?disposing?);
            ????????}


            ????????
            static?void?Main()?
            ????????
            {
            ????????????
            using(?DX9Form?frm?=?new?DX9Form()?)
            ????????????
            {
            ????????????????frm.Show();
            ????????????????frm.Init();
            ????????????????Application.Run(?frm?);
            ????????????}

            ????????}


            ????????
            ///?<summary>
            ????????
            ///?This?method?basically?creates?and?initialize?the?Direct3D?device?and
            ????????
            ///?anything?else?that?doens't?need?to?be?recreated?after?a?device?
            ????????
            ///?reset.
            ????????
            ///?</summary>

            ????????private?void?Init()
            ????????
            {
            ????????????
            //
            ????????????
            //?For?each?adapter,?examine?all?of?its?display?modes?to?see?if?any?
            ????????????
            //?of?them?can?give?us?the?hardware?support?we?desire.
            ????????????
            //

            ????????????
            bool?desiredAdapterModeFound?=?false;

            ????????????
            //?For?each?Adapter
            ????????????foreach(?AdapterInformation?adapter?in?Manager.Adapters?)
            ????????????
            {
            ????????????????
            //?Examine?each?display?mode?available.
            ????????????????foreach(?DisplayMode?display?in?adapter.SupportedDisplayModes?)
            ????????????????
            {
            ????????????????????
            //?Does?this?adapter?mode?support?a?mode?of?640?x?480?
            ????????????????????if(?display.Width?!=?640?||?display.Height?!=?480?)
            ????????????????????????
            continue;

            ????????????????????
            //?Does?this?adapter?mode?support?a?32-bit?RGB?pixel?format?
            ????????????????????if(?display.Format?!=?Format.X8R8G8B8?)
            ????????????????????????
            continue;

            ????????????????????
            //?Does?this?adapter?mode?support?a?refresh?rate?of?75?MHz?
            ????????????????????if(?display.RefreshRate?!=?75?)
            ????????????????????????
            continue;

            ????????????????????
            //?We?found?a?match!
            ????????????????????desiredAdapterModeFound?=?true;
            ????????????????????
            break;
            ????????????????}

            ????????????}


            ????????????
            if(?desiredAdapterModeFound?==?false?)
            ????????????
            {
            ????????????????
            //?TO?DO:?Handle?lack?of?support?for?desired?adapter?mode
            ????????????????return;
            ????????????}


            ????????????
            //
            ????????????
            //?Here's?the?manual?way?of?verifying?hardware?support.
            ????????????
            //

            ????????????
            //?Can?we?get?a?32-bit?back?buffer?
            ????????????if(?!Manager.CheckDeviceType(?Manager.Adapters.Default.Adapter,?
            ??????????????????????????????????????????DeviceType.Hardware,
            ??????????????????????????????????????????Format.X8R8G8B8,
            ??????????????????????????????????????????Format.X8R8G8B8,
            ??????????????????????????????????????????
            false)?)
            ????????????
            {
            ????????????????
            //?TO?DO:?Handle?lack?of?support?for?a?32-bit?back?buffer
            ????????????????return;
            ????????????}


            ????????????
            //?Does?the?hardware?support?a?16-bit?z-buffer?
            ????????????if(?!Manager.CheckDeviceFormat(?Manager.Adapters.Default.Adapter,?
            ????????????????????????????????????????????DeviceType.Hardware,
            ????????????????????????????????????????????Manager.Adapters.Default.CurrentDisplayMode.Format,?
            ????????????????????????????????????????????Usage.DepthStencil,
            ????????????????????????????????????????????ResourceType.Surface,
            ????????????????????????????????????????????DepthFormat.D16?)?)
            ????????????
            {
            ????????????????
            //?POTENTIAL?PROBLEM:?We?need?at?least?a?16-bit?z-buffer!
            ????????????????return;
            ????????????}


            ????????????
            //
            ????????????
            //?Do?we?support?hardware?vertex?processing??if?so,?use?it.?
            ????????????
            //?If?not,?downgrade?to?software.
            ????????????
            //

            ????????????Caps?caps?
            =?Manager.GetDeviceCaps(?Manager.Adapters.Default.Adapter,?
            ???????????????????????????????????????????????DeviceType.Hardware?);
            ????????????CreateFlags?flags;

            ????????????
            if(?caps.DeviceCaps.SupportsHardwareTransformAndLight?)
            ????????????????flags?
            =?CreateFlags.HardwareVertexProcessing;
            ????????????
            else
            ????????????????flags?
            =?CreateFlags.SoftwareVertexProcessing;

            ????????????
            //
            ????????????
            //?Everything?checks?out?-?create?a?simple,?full-screen?device.
            ????????????
            //

            ????????????PresentParameters?d3dpp?
            =?new?PresentParameters();

            ????????????d3dpp.Windowed???????????????
            =?false;
            ????????????d3dpp.EnableAutoDepthStencil?
            =?true;
            ????????????d3dpp.AutoDepthStencilFormat?
            =?DepthFormat.D16;
            ????????????d3dpp.SwapEffect?????????????
            =?SwapEffect.Discard;
            ????????????d3dpp.BackBufferWidth????????
            =?640;
            ????????????d3dpp.BackBufferHeight???????
            =?480;
            ????????????d3dpp.BackBufferFormat???????
            =?Format.X8R8G8B8;
            ????????????d3dpp.PresentationInterval???
            =?PresentInterval.Immediate;?

            ????????????d3dDevice?
            =?new?Device(?0,?DeviceType.Hardware,?this,?flags,?d3dpp?);

            ????????????
            //?Register?an?event-handler?for?DeviceReset?and?call?it?to?continue
            ????????????
            //?our?setup.
            ????????????d3dDevice.DeviceReset?+=?new?System.EventHandler(?this.OnResetDevice?);
            ????????????OnResetDevice(?d3dDevice,?
            null?);
            ????????}


            ????????
            ///?<summary>
            ????????
            ///?This?event-handler?is?a?good?place?to?create?and?initialize?any?
            ????????
            ///?Direct3D?related?objects,?which?may?become?invalid?during?a?
            ????????
            ///?device?reset.
            ????????
            ///?</summary>

            ????????public?void?OnResetDevice(object?sender,?EventArgs?e)
            ????????
            {
            ????????????
            //?This?sample?doens't?create?anything?that?requires?recreation?
            ????????????
            //?after?the?DeviceReset?event.
            ????????}


            ????????
            private?void?Render()
            ????????
            {
            ????????????d3dDevice.Clear(?ClearFlags.Target?
            |?ClearFlags.ZBuffer,?
            ?????????????????????????????Color.FromArgb(
            255,?0,?255,?0),?1.0f,?0?);

            ????????????d3dDevice.BeginScene();
            ????????????
            ????????????
            //?Render?geometry?here
            ????
            ????????????d3dDevice.EndScene();

            ????????????d3dDevice.Present();
            ????????}

            ????}

            }

            posted on 2006-06-22 16:08 夢在天涯 閱讀(941) 評論(1)  編輯 收藏 引用 所屬分類: DirectX

            評論

            # re: Managed directx 檢查硬件支持和實現全屏顯示 2010-06-08 17:43 ascu

            您好,我拜讀完您的文章,有些問題想請教,因為最近正初學DirectX,而且需要用它來做個東西。首先我的問題是您的那個檢查硬件支持是檢查哪個方面的支持,為什么我運行此程序,他最后返回的是無硬件支持,即desiredAdapterModeFound == false,所以,我只能將其強制設置true,最后可以也可以正常運行,所以我想問檢查硬件有什么用。還有一個問題,具體的內容我在百度問了個問題http://zhidao.baidu.com/question/158001103.html麻煩您看一下,我很急需去解決這個問題,先謝謝您了。  回復  更多評論   

            公告

            EMail:itech001#126.com

            導航

            統計

            • 隨筆 - 461
            • 文章 - 4
            • 評論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1804363
            • 排名 - 5

            最新評論

            閱讀排行榜

            精品一区二区久久久久久久网站| 精品999久久久久久中文字幕| 欧美精品福利视频一区二区三区久久久精品| 久久精品国产亚洲网站| 国产成人精品久久一区二区三区av | 中文字幕无码久久精品青草| 亚洲欧美国产精品专区久久| 亚洲AV无码久久精品成人| 久久久久亚洲av无码专区导航| 中文字幕成人精品久久不卡| 性高朝久久久久久久久久| 久久人妻少妇嫩草AV无码专区| 中文精品久久久久国产网址 | 91精品国产综合久久精品| 久久精品国产黑森林| 色8久久人人97超碰香蕉987| 久久久黄片| 久久线看观看精品香蕉国产| 久久久久se色偷偷亚洲精品av| 国产999精品久久久久久| 少妇人妻88久久中文字幕| 久久久久久久久久久免费精品| 久久影院综合精品| 久久精品综合一区二区三区| 久久国产精品久久国产精品| 无码人妻精品一区二区三区久久久| 久久久久久亚洲精品不卡| 99久久久精品| 久久人人爽人人爽人人AV东京热| 四虎国产精品成人免费久久| 91精品国产综合久久四虎久久无码一级| 久久精品国产2020| 亚洲AV伊人久久青青草原| 国产—久久香蕉国产线看观看| 国产产无码乱码精品久久鸭| 色8久久人人97超碰香蕉987| 亚洲伊人久久精品影院| 久久久久久伊人高潮影院| 久久婷婷五月综合97色直播| 久久久久这里只有精品 | 国产美女久久精品香蕉69|