如何在C ++中使用DirectX绘制透明矩形? [英] How do I draw transparent Rectangles using DirectX in C++?
问题描述
我想绘制对象是部分透明的,但我不知道如何。
我使用MSDN和C ++中的编码。
I want to draw objects to be partially transparent, but I don't know how. I'm using MSDN and coding in C++.
下面的代码是我如何绘制一个规则的矩形,但我想画一个透明的矩形。
The following code is how I draw a regular rectangle, but I want to draw a transparent rectangle.
VOID DrawingObject::Draw()
{
ID2D1HwndRenderTarget *m_pRenderTarget;
m_pRenderTarget->FillRectangle(RectF(10, 10, 20, 20),
m_pD2DDriver->GetBrush(static_cast<DrawingColor>(m_uColorIndex))
);
}
非常感谢任何帮助或指导。
Any help or guidance is greatly appreciated.
推荐答案
查看画笔界面。您可以创建画笔,并使用 SetOpacity
创建一个透明画笔发送到矩形。
Have a look at the Brush Interface. You can create a brush and use SetOpacity
to create a transparent brush to send to the rectangle.
只需直接使用 D2D1 :: ColorF(红色,绿色,蓝色,alpha)
函数创建颜色。 alpha
参数是透明度。 0
是完全透明的,而 1
是不透明的。
You can also just create the color directly with the D2D1::ColorF(red,green,blue,alpha)
function. The alpha
argument is transparency. 0
is completely transparent while 1
is opaque.
如果您不知道如何使用它,此链接包含了关于如何使用 ID2D1画笔的代码的精彩示例。下面是该页面的一些示例代码。
If you are unaware on how to use it, this link contains fantastic examples with code on how to use the ID2D1 Brushes. Below is some sample code from that page.
ID2D1SolidColorBrush *pGridBrush = NULL;
hr = pCompatibleRenderTarget->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF(0.93f, 0.94f, 0.96f, 1.0f)),
&pGridBrush
);
这篇关于如何在C ++中使用DirectX绘制透明矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!