gpt4 book ai didi

c++ - 绘图时忽略颜色

转载 作者:太空宇宙 更新时间:2023-11-04 11:41:19 24 4
gpt4 key购买 nike

如何让 Direct-X 绘制除黑色以外的所有颜色?目前我使用以下代码加载和绘制纹理:

void LoadTexture(IDirect3DDevice9* Device, unsigned char* buffer, int width, int height, IDirect3DTexture9* &Texture, ID3DXSprite* &Sprite)
{
Device->CreateTexture(width, height, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &Texture, 0);
D3DXCreateSprite(Device, &Sprite);

D3DLOCKED_RECT rect;
Texture->LockRect(0, &rect, nullptr, D3DLOCK_DISCARD);
TexturePixels = static_cast<unsigned char*>(rect.pBits);
Texture->UnlockRect(0);

memcpy(TexturePixels, &buffer[0], width * height * 4);
}

void DrawTextureSprite(IDirect3DDevice9* Device, IDirect3DTexture9* Texture, ID3DXSprite* Sprite)
{
if (Sprite && Texture)
{
D3DXVECTOR3 Position = D3DXVECTOR3(0, 0, 0);
Sprite->Begin(D3DXSPRITE_ALPHABLEND);
Sprite->Draw(Texture, nullptr, nullptr, &Position, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF)); //0xFFFFFFFF - white..
Sprite->End();
}
}

void BltBuffer(IDirect3DDevice9* Device)
{
if (Bitmap != nullptr)
{
std::uint8_t* Ptr = Bitmap->pixels;
for (int I = 0; I < Bitmap->height; ++I)
{
for (int J = 0; J < Bitmap->width; ++J)
{
std::uint8_t B = *(Ptr++);
std::uint8_t G = *(Ptr++);
std::uint8_t R = *(Ptr++);
*(Ptr++) = (B == 0 && G == 0 && R == 0) ? 0 : 0xFF; //if the colour is black, set the alpha channel to 0x0.
}
}

//if (!Texture && !TexturePixels)
{
LoadTexture(Device, Bitmap->pixels, Bitmap->width, Bitmap->height, Texture, Sprite);
}

DrawTextureSprite(Device, Texture, Sprite);
SafeRelease(Texture);
SafeRelease(Sprite);
}
}

我调用 BlitBuffer 的每一帧并将其传递给我的设备。但是,当它绘制时,即使我将它们的 alpha channel 设置为 0,它也会绘制我的黑色像素。所有其他像素的 alpha channel 都设置为 255。

有什么办法让它不绘制黑色像素吗?

最佳答案

你还必须启用和设置混合模式

     d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
d3ddev->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);

关于c++ - 绘图时忽略颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21327447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com