请问为什么只有个黑屏啊,我只想绘制一个简单的三角形啊.

#include<d3d9.h>

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9d.lib")

#define WINDOW_CLASS "UGPDX"
#define WINDOW_NAME  "Blank D3D Window"


// Function Prototypes...
bool InitializeD3D(HWND hWnd, bool fullscreen);                       //链接函数
bool set();
void RenderScene();
void Shutdown();


// Direct3D object and device.
LPDIRECT3D9 g_D3D = NULL;
LPDIRECT3DDEVICE9 g_D3DDevice = NULL;
LPDIRECT3DVERTEXBUFFER9 dd = 0;

struct vertex {
    float x, y, z;
    unsigned long color;
};
#define D3DFVF_VERTEX (D3DFVF_XYZ)

 

LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)                   //窗口开始
{
    switch (msg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
        break;

    case WM_KEYUP:
        if (wParam == VK_ESCAPE) PostQuitMessage(0);
        break;
    }

    return DefWindowProc(hWnd, msg, wParam, lParam);
}


int WINAPI WinMain(HINSTANCE hInst, HINSTANCE prevhInst, LPSTR cmdLine, int show)
{
    // Register the window class
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      WINDOW_CLASS, NULL };
    RegisterClassEx(&wc);

    // Create the application's window
    HWND hWnd = CreateWindow(WINDOW_CLASS, WINDOW_NAME, WS_OVERLAPPEDWINDOW,
        100, 100, 640, 480, GetDesktopWindow(), NULL,
        wc.hInstance, NULL);

    // Initialize Direct3D
    if (InitializeD3D(hWnd, false))
    {
        // Show the window
        ShowWindow(hWnd, SW_SHOWDEFAULT);
        UpdateWindow(hWnd);

        // Enter the message loop
        MSG msg;
        ZeroMemory(&msg, sizeof(msg));

        while (msg.message != WM_QUIT)
        {
            if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
            else
                RenderScene();
        }
    }

    // Release any and all resources.
    Shutdown();

    // Unregister our window.
    UnregisterClass(WINDOW_CLASS, wc.hInstance);
    return 0;
}                                 //窗口结束


bool InitializeD3D(HWND hWnd, bool fullscreen)                //开始链接
{
    D3DDISPLAYMODE displayMode;

    // Create the D3D object.
    g_D3D = Direct3DCreate9(D3D_SDK_VERSION);
    if (g_D3D == NULL) return false;

    // Get the desktop display mode.
    if (FAILED(g_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode)))
        return false;

    // Set up the structure used to create the D3DDevice
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    if (fullscreen)
    {
        d3dpp.Windowed = FALSE;
        d3dpp.BackBufferWidth = 640;
        d3dpp.BackBufferHeight = 480;
    }
    else
        d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = displayMode.Format;

    // Create the D3DDevice
    if (FAILED(g_D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_D3DDevice)))
    {
        return false;
    }

    return true;

 

}

//开始创建顶点缓存
bool set() {
    unsigned long col = D3DCOLOR_XRGB(25, 215, 155);
    g_D3DDevice->CreateVertexBuffer(              //创立静态顶点缓存
        3 * sizeof(vertex),
        0,
        D3DFVF_XYZ,
        D3DPOOL_MANAGED,
        &dd,
        0
    );

    vertex* str;
    dd->Lock(0, 0, (void**)&str, 0);
    str[0] = vertex{ -1.0f, 0.0f, 2.0f ,col };
    str[1] = vertex{ 0.0f, 1.0f, 2.0f ,col };
    str[3] = vertex{ 1.0f, 0.0f, 2.0f,col };

    dd->Unlock();
    return true;
}

 

void RenderScene()
{
    // Clear the backbuffer.
    g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    g_D3DDevice->BeginScene();             //渲染开始
    g_D3DDevice->SetStreamSource(0, dd, 0, sizeof(vertex));
    g_D3DDevice->SetFVF(D3DFVF_VERTEX);
    g_D3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0,1);
    g_D3DDevice->EndScene();
    g_D3DDevice->Present(0, 0, 0, 0);

}


void Shutdown() {               //清除
    if (g_D3DDevice != NULL)   g_D3DDevice->Release();
    if (g_D3D != NULL)      g_D3D->Release();
    if (dd != NULL)          dd->Release();

    g_D3DDevice = NULL;
    g_D3D = NULL;
    dd = NULL;
}