Platform SDK: DirectX

Using Direct3DX to Access Direct3D and DirectDraw

After you have obtained a context object, you can access the encapsulated objects.

To obtain a pointer to an IDirect3DDevice7 interface, use the ID3DXContext::GetD3DDevice method:

    m_pd3dDevice = g_pd3dx->GetD3DDevice();
    if (m_pd3dDevice == NULL)
        return E_FAIL;

To obtain a pointer to an IDirect3D7 interface, use the ID3DXContext::GetD3D method:

    m_pd3d = g_pd3dx->GetD3D();
    if (m_pd3d == NULL)
        return E_FAIL;

To obtain a pointer to an IDirectDraw7 interface, use the ID3DXContext::GetDD method:

    m_pdd = g_pd3dx->GetDD();
    if (m_pdd == NULL)
        return E_FAIL;

These retrieved interfaces can then be used by your application. For example, the following code uses the retrieved pointer to an IDirect3DDevice7 interface, m_pd3dDevice, to enable dithering, specular effects, lighting, and z-buffer usage.

    hr = m_pd3dDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE);
 
    hr = m_pd3dDevice->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, TRUE);
 
    hr = m_pd3dDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);
 
    hr = m_pd3dDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, TRUE);