zoukankan      html  css  js  c++  java
  • Direct3D 9学习笔记(1)初始化

    参考书籍:DIRECTX9.03D游戏开发编程基础

    一.创建IDirect3D9接口

    //-----------------------------------------------------------------------------
    // Global variables
    //-----------------------------------------------------------------------------
    LPDIRECT3D9         g_pD3D = NULL; // Used to create the D3DDevice
    LPDIRECT3DDEVICE9   g_pd3dDevice = NULL; // Our rendering device
    
    //-----------------------------------------------------------------------------
    // Name: InitD3D()
    // Desc: Initializes Direct3D
    //-----------------------------------------------------------------------------
    HRESULT InitD3D( HWND hWnd )
    {
        // Create the D3D object, which is needed to create the D3DDevice.
        if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
            return E_FAIL;
        
        // Set up the structure used to create the D3DDevice. Most parameters are
        // zeroed out. We set Windowed to TRUE, since we want to do D3D in a
        // window, and then set the SwapEffect to "discard", which is the most
        // efficient method of presenting the back buffer to the display.  And 
        // we request a back buffer format that matches the current desktop display 
        // format.
        D3DPRESENT_PARAMETERS d3dpp;
        ZeroMemory( &d3dpp, sizeof( d3dpp ) );
        d3dpp.Windowed = TRUE;
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
        d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    
        // Create the Direct3D device. Here we are using the default adapter (most
        // systems only have one, unless they have multiple graphics hardware cards
        // installed) and requesting the HAL (which is saying we want the hardware
        // device rather than a software one). Software vertex processing is 
        // specified since we know it will work on all cards. On cards that support 
        // hardware vertex processing, though, we would see a big performance gain 
        // by specifying hardware vertex processing.
        if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                          &d3dpp, &g_pd3dDevice ) ) )
        {
            return E_FAIL;
        }
    
        // Device state would normally be set here
    
        return S_OK;
    }
    

    参考:http://msdn.microsoft.com/en-us/library/bb174300%28VS.85%29.aspx

    二.创建IDirect3DDevice9

    http://msdn.microsoft.com/en-us/library/bb174313(v=vs.85).aspx

    HRESULT CreateDevice(
        [in]           UINT Adapter,
        [in]           D3DDEVTYPE DeviceType,
        [in]           HWND hFocusWindow,
        [in]           DWORD BehaviorFlags,
        [in, out]      D3DPRESENT_PARAMETERS *pPresentationParameters,
        [out, retval]  IDirect3DDevice9 **ppReturnedDeviceInterface
        );
    

    image

    关于D3DPRESENT_PARAMETERS:Describes the presentation parameters.

    http://msdn.microsoft.com/en-us/library/bb172588(v=vs.85).aspx

    /* Resize Optional Parameters */
    typedef struct _D3DPRESENT_PARAMETERS_
    {
        UINT                BackBufferWidth;
        UINT                BackBufferHeight;
        D3DFORMAT           BackBufferFormat;
        UINT                BackBufferCount;
    
        D3DMULTISAMPLE_TYPE MultiSampleType;
        DWORD               MultiSampleQuality;
    
        D3DSWAPEFFECT       SwapEffect;
        HWND                hDeviceWindow;
        BOOL                Windowed;
        BOOL                EnableAutoDepthStencil;
        D3DFORMAT           AutoDepthStencilFormat;
        DWORD               Flags;
    
        /* FullScreen_RefreshRateInHz must be zero for Windowed mode */
        UINT                FullScreen_RefreshRateInHz;
        UINT                PresentationInterval;
    } D3DPRESENT_PARAMETERS;
    

    image

    三.检测显卡功能

    D3DCAPS9 caps={};
    g_pD3D->GetDeviceCaps(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&caps);
    if(caps.Caps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
    {
    }
    
  • 相关阅读:
    [LeetCode] 952. Largest Component Size by Common Factor 按公因数计算最大部分大小
    [LeetCode] 951. Flip Equivalent Binary Trees 翻转等价二叉树
    [LeetCode] 950. Reveal Cards In Increasing Order 按递增顺序显示卡牌
    上周热点回顾(7.6-7.12)团队
    上周热点回顾(6.29-7.5)团队
    上周热点回顾(6.22-6.28)团队
    调用博客园 open api 的客户端示例代码团队
    【故障公告】阿里云 RDS 实例 CPU 100% 故障引发全站无法正常访问团队
    上周热点回顾(6.15-6.21)团队
    《证券投资顾问胜任能力考试》考试大纲
  • 原文地址:https://www.cnblogs.com/Clingingboy/p/2611651.html
Copyright © 2011-2022 走看看