所以我现在正在学习如何使用Directx9。我已经做了一个透明的窗口。我设法在屏幕上得到一个三角形,但是,每当我绘制时,透明窗口周围都会出现一条细的灰色线。我已经尝试使用DwmExtendFrameIntoClientArea使窗口透明,但是这样做时我看不到图形。我想知道是否有人知道为什么会这样,因为在我使用Directx9绘制之前,我的窗口是100%透明的,周围没有边框。先谢谢了! (很抱歉,图片太大了,我不知道如何将其缩小)
Directx9代码:
#include <DirectXDraw.h>
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
LPDIRECT3DVERTEXBUFFER9 v_buffer;
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
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.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
if (hWnd == NULL)
{
std::cout << "hWNd is NULL";
}
}
void Init_Graphics()
{
CUSTOMVERTEX OurVertices[] =
{
{350, 50, 1.0f, 1.0f, D3DCOLOR_XRGB(500, 0, 0)},
{550, 420, 1.0f, 1.0f, D3DCOLOR_XRGB(500, 0, 0)},
{250, 420, 1.0f, 1.0f, D3DCOLOR_XRGB(500, 0, 0)},
};
d3ddev->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL);
void* pVoid;
v_buffer->Lock(0, 0, &pVoid, NULL);
memcpy(pVoid, OurVertices, sizeof(OurVertices));
v_buffer->Unlock();
}
void Render_Frame()
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1.0f, 0);
d3ddev->BeginScene();
d3ddev->SetFVF(CUSTOMFVF);
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
}
void CleanD3D()
{
v_buffer->Release();
d3d->Release();
d3ddev->Release();
}