2014-09-29 1 views
1

Direct2D를 사용하여 직사각형을 그려 봅니다.ID2D1DeviceContext EndDraw 드로잉 직사각형 후 D2DERR_WRONG_STATE

HRESULT result; 
    result = g_d2dContext->CreateSolidColorBrush(
    D2D1::ColorF(D2D1::ColorF::Blue), 
    &g_SolidBrush 
    ); 

    D2D1_RECT_F rect = D2D1::RectF(
    g_targetRect.left + 10.0f, 
    g_targetRect.top + 10.0f, 
    g_targetRect.right - 10.0f, 
    g_targetRect.bottom - 10.0f); 

    g_d2dContext->BeginDraw(); 
    { 
    g_d2dContext->DrawRectangle(rect, g_SolidBrush, 5.0f); 
    } 
    result = g_d2dContext->EndDraw(); 

    if (FAILED(result)) 
    { 
    OutputDebugStringW(L"The object was not in the correct state to process the method."); 
    } 

EndDraw() 메소드는 다음 HRESULT를 반환 : 0x88990001 (D2DERR_WRONG_STATE) - The object was not in the correct state to process the method 다음과 같이 Direct2D의 장치와 Direct2D의 디바이스 컨텍스트를 초기화하고 다음 MSDN article에 기재된 렌더 타겟들을 설정 한 후, I는 사각형을 그리려고.

사각형이 그려지지 않습니다. 나는 검은 이미지 만 얻는다.

편집 :

나는 문제가가/비트 맵에 NULL 포인터를 얻을 CreateBitmapFromDxgiSurface를 호출 한 후 대상을 렌더링한다는 것을 가정

.

g_d2dContext->CreateBitmapFromDxgiSurface(
    dxgiBackBuffer.Get(), 
    &bitmapProperties, 
    &g_targetBitmap); 

    g_d2dContext->SetTarget(g_targetBitmap.Get()); 

왜 targetBitmap이 NULL입니까?

아이디어가 있으십니까?

미리 감사드립니다.

답변

0

방금 ​​문제가 해결되었습니다. 비트 맵 속성을 잘못된 값으로 초기화했습니다.

는 이제 작동합니다

D2D1_BITMAP_PROPERTIES1 bitmapProperties = 
    D2D1::BitmapProperties1(
    D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW, 
    D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE), 
    96.0f, // dpi 
    96.0f // dpi 
    ); 

    // Direct2D needs the dxgi version of the backbuffer surface pointer. 
    ComPtr<IDXGISurface> dxgiBackBuffer; 
    hr = g_swapChain->GetBuffer(0, IID_PPV_ARGS(&dxgiBackBuffer)); 

    // Get a D2D surface from the DXGI back buffer to use as the D2D render target. 
    hr = g_d2dContext->CreateBitmapFromDxgiSurface(
    dxgiBackBuffer.Get(), 
    bitmapProperties, 
    g_targetBitmap.GetAddressOf()); 

    // Now we can set the Direct2D render target. 
    g_d2dContext->SetTarget(g_targetBitmap.Get()); 
관련 문제