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

            天行健 君子當(dāng)自強(qiáng)而不息

            D3D Animation Basis(3)

            Initializing Direct3D

            Next in line for the helper functions is init_d3d, which you use to initialize Direct3D and create a 3D device and display window. I tried to keep the code as simple as possible, performing the typical initialization code you would use in any Direct3D application.

            HRESULT init_d3d(IDirect3D9** ret_d3d,
                             IDirect3DDevice9
            ** ret_device,
                             HWND hwnd,
                             BOOL force_windowed,
                             
            bool multi_threaded)
            {
                
            // error checking
                if(ret_d3d == NULL || ret_device == NULL || hwnd == NULL)
                    
            return E_FAIL;

                IDirect3D9
            * d3d = Direct3DCreate9(D3D_SDK_VERSION);

                
            if(d3d == NULL)
                    
            return E_FAIL;

                
            *ret_d3d = d3d;

                
            // Ask if user wants to run windowed or fullscreen, or force windowed if flagged to do such.

                
            int mode;

                
            if(force_windowed)
                    mode 
            = IDNO;
                
            else
                    mode 
            = MessageBox(hwnd, "Use fullscreen mode? (640x480x16)""Initialize D3D", MB_YESNO | MB_ICONQUESTION);

                
            // set the video (depending on windowed mode or fullscreen)

                D3DPRESENT_PARAMETERS d3dpp;
                ZeroMemory(
            &d3dpp, sizeof(d3dpp));

                
            // setup video setttings based on choice of fullscreen or not

                
            if(mode == IDYES)    // setup fullscreen format (set to your own if you perfer)
                {
                    
            // set the presentation parameters (use fullscreen)
                    d3dpp.BackBufferWidth             = 640;
                    d3dpp.BackBufferHeight             
            = 480;
                    d3dpp.BackBufferFormat             
            = D3DFMT_R5G6B5;
                    d3dpp.SwapEffect                 
            = D3DSWAPEFFECT_FLIP;
                    d3dpp.Windowed                     
            = FALSE;
                    d3dpp.EnableAutoDepthStencil     
            = TRUE;
                    d3dpp.AutoDepthStencilFormat     
            = D3DFMT_D16;
                    d3dpp.FullScreen_RefreshRateInHz 
            = D3DPRESENT_RATE_DEFAULT;
                    d3dpp.PresentationInterval         
            = D3DPRESENT_INTERVAL_DEFAULT;
                }
                
            else    // setup windowed format (set to your own demensions below)
                {
                    
            // get the client and window dimensions
                    RECT client_rect, window_rect;
                    GetClientRect(hwnd, 
            &client_rect);
                    GetWindowRect(hwnd, 
            &window_rect);

                    
            // set the width and height (set your dimensions here)
                    DWORD desired_width = 640, desired_height = 480;
                    DWORD width  
            = (window_rect.right - window_rect.left) - client_rect.right  + desired_width;
                    DWORD height 
            = (window_rect.bottom - window_rect.top) - client_rect.bottom + desired_height;

                    
            // set the window's dimensions
                    MoveWindow(hwnd, window_rect.left, window_rect.top, width, height, TRUE);

                    
            // get the desktop format
                    D3DDISPLAYMODE display_mode;
                    d3d
            ->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &display_mode);

                    
            // set the presentation parameters (use windowed)
                    d3dpp.BackBufferWidth              = desired_width;
                    d3dpp.BackBufferHeight              
            = desired_height;
                    d3dpp.BackBufferFormat              
            = display_mode.Format;
                    d3dpp.SwapEffect                  
            = D3DSWAPEFFECT_DISCARD;
                    d3dpp.Windowed                      
            = TRUE;
                    d3dpp.EnableAutoDepthStencil      
            = TRUE;
                    d3dpp.AutoDepthStencilFormat     
            = D3DFMT_D16;
                    d3dpp.FullScreen_RefreshRateInHz 
            = D3DPRESENT_RATE_DEFAULT;
                    d3dpp.PresentationInterval         
            = D3DPRESENT_INTERVAL_DEFAULT;
                }

                
            // create the 3D device

                DWORD flags 
            = D3DCREATE_MIXED_VERTEXPROCESSING;

                
            if(multi_threaded)
                    flags 
            |= D3DCREATE_MULTITHREADED;

                IDirect3DDevice9
            * device;
                HRESULT hr 
            = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, flags, &d3dpp, &device);

                
            if(FAILED(hr))
                    
            return hr;

                
            // store the 3D device object pointer
                *ret_device = device;

                
            // set the perspective projection

                
            float aspect = (float)d3dpp.BackBufferWidth / d3dpp.BackBufferHeight;

                D3DXMATRIX mat_proj;
                D3DXMatrixPerspectiveFovLH(
            &mat_proj, D3DX_PI/4.0f, aspect, 1.0f10000.0f);
                device
            ->SetTransform(D3DTS_PROJECTION, &mat_proj);

                
            // set the default render states
                device->SetRenderState(D3DRS_LIGHTING,            FALSE);
                device
            ->SetRenderState(D3DRS_ZENABLE,            D3DZB_TRUE);
                device
            ->SetRenderState(D3DRS_ALPHABLENDENABLE,    FALSE);
                device
            ->SetRenderState(D3DRS_ALPHATESTENABLE,    FALSE);

                
            // set the default texture stage states
                device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
                device
            ->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
                device
            ->SetTextureStageState(0, D3DTSS_COLOROP,      D3DTOP_MODULATE);

                
            // set the default texture filters
                device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
                device
            ->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);

                
            return S_OK;
            }

             

            posted on 2008-04-14 12:33 lovedday 閱讀(348) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評論

            亚洲天堂久久久| 久久99精品综合国产首页| 亚洲精品成人网久久久久久| 伊人久久亚洲综合影院| 97超级碰碰碰久久久久| 久久天天躁狠狠躁夜夜av浪潮| 亚洲AV无码一区东京热久久| 99久久精品免费国产大片| 亚洲精品无码久久久久sm| 99久久国产综合精品成人影院| 亚洲AⅤ优女AV综合久久久| 国产精品久久久久影院色 | 亚洲va久久久噜噜噜久久| 欧美伊香蕉久久综合类网站| A级毛片无码久久精品免费| 久久久久久青草大香综合精品 | 国产L精品国产亚洲区久久| 国产精品久久婷婷六月丁香| 91精品国产91久久久久久蜜臀| 色欲久久久天天天综合网| 久久久国产精品| 成人午夜精品久久久久久久小说 | 亚洲熟妇无码另类久久久| 久久久久久国产精品无码下载| 久久精品a亚洲国产v高清不卡 | 久久精品国产一区| 久久精品天天中文字幕人妻| 一个色综合久久| 国产精品一区二区久久精品涩爱 | 久久强奷乱码老熟女网站| 99久久精品免费国产大片| 91久久精品国产91性色也| 久久综合九色综合精品| 99久久精品国产一区二区三区| 青青草国产精品久久| 国产精品va久久久久久久| 99久久婷婷国产一区二区| 精品国产综合区久久久久久| 久久久久亚洲精品无码网址| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 久久精品人人做人人爽97|