DirectX - 在IDirect3DTexture9上使用GDI绘图

时间:2016-01-21 02:01:40

标签: c++ directx directx-9

我正在尝试使用IDDI3DTexture9上的GDI TextOutA绘制文本,但是我在屏幕上看不到任何内容。

这是我的代码:

HFONT pFont = CreateFontA(-10 * nLogPixelsY / 72, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");

IDirect3DTexture9* pFontTex = NULL;
pDXDevice->CreateTexture(100, 100, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &pFontTex, NULL);

////////////////////////////

IDirect3DSurface9* ppSurface = NULL;
HDC mDC = NULL;
if (pFontTex->GetSurfaceLevel(0, &ppSurface) == D3D_OK)
{
    if (ppSurface->GetDC(&mDC) == D3D_OK)
    {
        SelectObject(mDC, pFont);
        SetTextColor(mDC, 0x00FF00FF);
        SetBkMode(mDC, TRANSPARENT);
        TextOutA(mDC, 0, 0, "Test", 4);

        //MessageBoxA(0, "work", 0, 0);

        ppSurface->ReleaseDC(mDC);
    }

    ppSurface->Release();
}

pDXDevice->SetTexture(0, pFontTex);
pDXDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
pDXDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
pDXDevice->SetRenderState(D3DRS_ALPHAREF, 0x01);
pDXDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);

0 个答案:

没有答案