绘制时忽略颜色
Ignore Colour when drawing
除了黑色以外,如何获得直接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频道设置为0,也会绘制我的黑色像素。
有什么想法我如何使它不绘制黑色像素?
您必须启用并设置混合模式
d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
d3ddev->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
相关文章:
- 如何在 openGL-2D 中绘制不同颜色的线条?
- 如何使用DP绘制具有n种不同颜色的r x r字段,而无需在同一行使用相同的颜色
- 无法在QImage上绘制或更改像素的颜色
- Opengl 3+ 绘制不同颜色的线条
- 用一个glDrawArrays命令绘制几个不同颜色的三角形
- QT-从Combobox选择颜色并绘制矩形
- 在OpenCV中绘制带有梯度颜色的线
- 绘制时忽略颜色
- 直接在.png加载的cimage上绘制时,将文本颜色设置为
- 未绘制每个顶点处的C++OpenGL颜色
- 调用Qpainter的方法绘制以刷新图像和更改颜色
- 绘制时无法设置线条颜色
- 如何在OpenFrameworks/OpenCV中使用HSV颜色绘制正方形
- QwtPlot:使最后绘制的点看起来具有不同的颜色或大小
- 如何在 cocos2d-x 中用颜色绘制圆形填充
- 在QQuickItem中绘制多个不同颜色的点
- OpenGL在更改RGBA颜色后绘制16种颜色
- 绘制具有不同颜色顶点的OpenGL颜色矩形
- 如何在顶点缓冲区中以另一种颜色绘制顶点
- 在Opengl中从不同颜色的正方形中绘制矩形