Direct2D 概览
Direct2D(以下简称D2D)是一个 用户模式的库,基于 D3D 10.1 API(从 Win8开始,D2D 基于 D3D 11.1)。所以 D2D 可以提供 GPU 硬件加速。D2D架构图:
先绘制个矩阵
第一步:头文件
#include <d2d1.h>
第二步:创建一个 ID2D1 工厂
1 ID2D1Factory *m_pD2DFactory ; 2 hr = D2D1CreateFactory (D2D1_FACTORY_TYPE_SINGLE_THREADED, & m_pD2DFactory);
第三步:创建 Render Target
1 // Obtain the size of the drawing area. 2 RECT rc ; 3 GetClientRect(hwnd , &rc ); 4 5 // Create a Direct2D render target 6 ID2D1HwndRenderTarget * pRT = NULL ; 7 HRESULT hr = pD2DFactory->CreateHwndRenderTarget( 8 D2D1::RenderTargetProperties (), 9 D2D1::HwndRenderTargetProperties ( 10 hwnd, 11 D2D1::SizeU ( 12 rc. right - rc. left, 13 rc. bottom - rc. top) 14 ), 15 & pRT 16 );
第四步:创建笔刷
1 ID2D1SolidColorBrush * pBlackBrush = NULL ; 2 if (SUCCEEDED (hr )) { 3 pRT-> CreateSolidColorBrush( 4 D2D1::ColorF (D2D1::ColorF:: Black), 5 & pBlackBrush 6 ); 7 }
第五步:画矩形
1 pRT->BeginDraw(); 2 3 pRT->DrawRectangle( 4 D2D1::RectF( 5 rc.left + 100.0f, 6 rc.top + 100.0f, 7 rc.right - 100.0f, 8 rc.bottom - 100.0f), 9 pBlackBrush); 10 11 HRESULT hr = pRT->EndDraw();
第六步(最后):释放资源
1 SafeRelease(pRT); 2 SafeRelease(pBlackBrush); 3 SafeRelease(pD2DFactory);
参考资料
https://msdn.microsoft.com/en-us/library/dd370990.aspx
https://msdn.microsoft.com/en-us/library/dd535473(v=vs.85).aspx
(有机会再补充完整)
时间: 2024-12-17 21:38:28