directxdirect3ddirectx-9direct3d9

Direct3D9 not drawing?


I needed to draw some simple shapes and I decided to go with D3D9. After going through a few of the tutorials on directxtutorial.com, I finally have all the code and knowledge I need to make my first shape appear on the screen. The problem is, though, that no image is appearing. I've looked over the code many times and have compared it with the code on the website, and it all checks out. Why is nothing rendering on the screen?

    #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

    LPDIRECT3D9 d3d;
    LPDIRECT3DDEVICE9 d3ddev;

    LPDIRECT3DVERTEXBUFFER9 vbuffer;

    struct CUSTOMVERTEX
    {
        float x, y, z, rhw;
        DWORD color;
    };

    void InitD3D(HWND hWnd)
    {
        d3d = Direct3DCreate9(D3D_SDK_VERSION);

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

        d3dpp.Windowed = true;
        d3dpp.hDeviceWindow = hWnd;
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

        d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
    }

void InitGraphics()
{
    CUSTOMVERTEX verticies[]
    {
        {50, 70, 1.0f, 1.0f, D3DCOLOR_XRGB(250, 0, 0),},
        {70, 50, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 250, 0),},
        {40, 80, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 250),},
    };

    d3ddev->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX), NULL, CUSTOMFVF, D3DPOOL_MANAGED, &vbuffer, NULL);

    void* vp;

    vbuffer->Lock(0, 0, (void**)&vp, NULL);

    memcpy(vp, verticies, sizeof(verticies));

    vbuffer->Unlock();
}

void Draw()
{
    d3ddev->Clear(NULL, NULL, D3DCLEAR_TARGET, NULL, 1.0f, NULL);

    d3ddev->BeginScene();

    d3ddev->SetFVF(CUSTOMFVF);
    d3ddev->SetStreamSource(0, vbuffer, 0, sizeof(CUSTOMVERTEX));
    d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

    d3ddev->EndScene();
    d3ddev->Present(NULL, NULL, NULL, NULL);
}

void ReleaseD3D()
{
    d3d->Release();
    d3ddev->Release();
    vbuffer->Release();
}

Solution

  • Turns out my vertex positions weren't triangle enough to make a triangle. Thanks for the help, though, it reminded me to set up error-checking.