Showing posts with label Direct2D. Show all posts
Showing posts with label Direct2D. Show all posts

2011/10/02

[Direct2D] MFC에서 간단한 사용 예

Direct2D 에 대해서는 오래전에 들어 보았지만 오늘에서야 관련 정보를 찾아 보았다.

그리고 간단한게 사용해 봤다.



MSDN 에서 찾은 것으로 간단하게 사각형을 그리는 코드 이다. 이 코드는 Windows 7 x64 에서 Visual Studio 2010 SP1 버전에서 작성되고 테스트 하였다.


Direct2D 기능을 사용하려면 Windows 7 또는 Vista SP2 이상이어야 해서 범용 프로그램 제작에 이용하는 것은 이른것 같지만 알아두면 앞으로 사용할 일이 있을 것 같다. 상세한 것들은 차차 익혀가야 겠다.



////////////////////////////////////////////////////////////////////////////////
// stdafx.h
// Direct2D
#include <d2d1.h>
#pragma comment(lib, "D2D1.lib")

template<class Interface>
inline void SafeRelease(
Interface **ppInterfaceToRelease
)
{
if (*ppInterfaceToRelease != NULL)
{
(*ppInterfaceToRelease)->Release();

(*ppInterfaceToRelease) = NULL;
}
}

#ifndef Assert
#if defined( DEBUG ) || defined( _DEBUG )
#define Assert(b) do {if (!(b)) {OutputDebugStringA("Assert: " #b "\n");}} while(0)
#else
#define Assert(b)
#endif //DEBUG || _DEBUG
#endif

#ifndef HINST_THISCOMPONENT
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
#endif

////////////////////////////////////////////////////////////////////////////////
// ChildView.h
ID2D1Factory* m_pD2DFactory;

////////////////////////////////////////////////////////////////////////////////
// ChildView.cpp
CChildView::CChildView()
{
// Initialize Direct2D
m_pD2DFactory = NULL;
HRESULT hr = D2D1CreateFactory(
D2D1_FACTORY_TYPE_SINGLE_THREADED,
&m_pD2DFactory
);
}

CChildView::~CChildView()
{
// Release Direct2D
SafeRelease( &m_pD2DFactory );
}

void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting

Render();

// Do not call CWnd::OnPaint() for painting messages
}

int CChildView::Render()
{
if ( m_pD2DFactory == NULL )
{
return -1;
}

// Obtain the size of the drawing area.
CRect rcClient;
GetClientRect(&rcClient);

// Create a Direct2D render target
ID2D1HwndRenderTarget* pRT = NULL;
HRESULT hr = m_pD2DFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(
GetSafeHwnd(),
D2D1::SizeU( rcClient.Width(), rcClient.Height() )),
&pRT
);

ID2D1SolidColorBrush* pBlackBrush = NULL;
pRT->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::Blue),
&pBlackBrush
);

// Begin Drawing
pRT->BeginDraw();

pRT->Clear(D2D1::ColorF(D2D1::ColorF::White));

pRT->DrawRectangle(
D2D1::RectF(
rcClient.left + 100.0f,
rcClient.top + 100.0f,
rcClient.right - 100.0f,
rcClient.bottom - 100.0f),
pBlackBrush
);

// End Drawing
HRESULT hrDraw = pRT->EndDraw();

SafeRelease( &pBlackBrush );
SafeRelease( &pRT );

return NO_ERROR;
}



Direct2D on MSDN

&

Original Post : http://neodreamer-dev.tistory.com/582

2011/03/11

Visual Studio 2010 Service Pack 1 설치~

Visual Studio 2010 Service Pack 1 설치후 About box

Visual Studio 2010 Service Pack 1 설치후 About box



점심시간 짬을 이용하여 Visual Studio 2010 Service Pack 1을 설치해 보았다.

기본 설치 파일은 800KB 정도로 인터넷을 통해 구성 파일을 다운 받아 설치하는 방식이다. 본인의 경우 대략 600MB 정도 다운로드 받아야 했다.

설치될 사항들구성 다운로드




설치 후 설치 경로의 예제 중에서 D2D 관련 예제를 실행해 보았다.

Direct2D 관련 예제는 4개가 있었으며 이 중 MFCDxgiSample 은 컴파일 되지 않았고(DirectX 10.0 설치가 필요한 것 같았다.) 나머지 세개의 예제는 컴파일 되고 동작을 하였다.


MFCDirect2DApp

MFCDirect2DApp 실행화면



MFCDirect2DHelloWorld

MFCDirect2DHelloWorld 실행화면



MFCGdiInteropSample

MFCGdiInteropSample 실행화면



좋은데 단점이 있다면 이 Direct2D 기능에 관련하여서는 Windows 7 에서만 사용할 수 있다는 것이다.

<

Original Post : http://neodreamer-dev.tistory.com/517