I'm trying to draw textures to the screen in a game I hooked. The problem is that the textures have these weird outlines..
For example, in the following picture:
It is supposed to look like this (drawn using D3D9XSprite):
I'm drawing my textures with:
//Creates a texture from a buffer containing pixels.
void LoadTexture(IDirect3DDevice9* Device, std::uint8_t* buffer, int width, int height, IDirect3DTexture9* &Texture)
{
Device->CreateTexture(width, height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &Texture, 0);
D3DLOCKED_RECT rect;
Texture->LockRect(0, &rect, nullptr, D3DLOCK_DISCARD);
std::uint8_t* TexturePixels = static_cast<std::uint8_t*>(rect.pBits);
Texture->UnlockRect(0);
memcpy(TexturePixels, &buffer[0], width * height * 4);
}
//Draws a texture to the screen..
void DrawTexture(IDirect3DDevice9* Device, IDirect3DTexture9* Texture, float X1, float Y1, float X2, float Y2)
{
D3DVertex vertices[] =
{
{X1, Y1, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 0.0f, 0.0f},
{X2, Y1, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 1.0f, 0.0f},
{X1, Y2, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 0.0f, 1.0f},
{X2, Y2, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 1.0f, 1.0f}
};
Device->SetFVF(VERTEX_FVF_TEX);
Device->SetTexture(0, Texture);
Device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(D3DVertex));
}
//Loads and draws a texture to the screen.
void BltBuffer(IDirect3DDevice9* Device)
{
LoadTexture(Device, buffer, w, h, Texture);
DrawTexture(Device, Texture, 0, 0, w, h);
SafeRelease(Texture);
}
//Hooked EndScene. Draws my texture on the game's window.
HRESULT Direct3DDevice9Proxy::EndScene()
{
IDirect3DStateBlock9* stateblock;
ptr_Direct3DDevice9->CreateStateBlock(D3DSBT_ALL, &stateblock);
stateblock->Capture();
ptr_Direct3DDevice9->SetRenderState(D3DRS_LIGHTING, false);
ptr_Direct3DDevice9->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
ptr_Direct3DDevice9->SetRenderState(D3DRS_ZENABLE, false);
ptr_Direct3DDevice9->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
ptr_Direct3DDevice9->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
ptr_Direct3DDevice9->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
ptr_Direct3DDevice9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
BltBuffer(ptr_Direct3DDevice9);
if (stateblock)
{
stateblock->Apply();
stateblock->Release();
}
return ptr_Direct3DDevice9->EndScene();
}
Any ideas why my colours are being degraded?