标签:
Direct2D(以下简称D2D)是一个 用户模式的库,基于 D3D 10.1 API(从 Win8开始,D2D 基于 D3D 11.1)。所以 D2D 可以提供 GPU 硬件加速。D2D架构图:
#include <d2d1.h>
1 ID2D1Factory *m_pD2DFactory ; 2 hr = D2D1CreateFactory (D2D1_FACTORY_TYPE_SINGLE_THREADED, & m_pD2DFactory);
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);
(有机会再补充完整)
标签:
原文地址:http://www.cnblogs.com/rhzhang/p/5140464.html