none
What is the correct way to use ID2D1PathGeometry in Direct2D? Why is my program reporting an error? RRS feed

  • 问题

  • I want to draw a polygon, according to the tutorial, I wrote code like this:

    void b2DrawD2D::DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)//bug0x88990001
    {
    
    	pSolidBrush->SetColor(D2D1::ColorF(color.r, color.g, color.b, color.a));
    
    	HRESULT hr = pPathGeometry->Open(&pGeometrySink);//<-this line,  Next time I call DrawSolidPolygon(), hr becomes 0x88990001, "The object was not in the correct state to process the method."
    	if (SUCCEEDED(hr))
    	{
    		b2Vec2 v1 = vertices[vertexCount - 1];
    		pGeometrySink->BeginFigure(D2D1::Point2F(v1.x, v1.y), D2D1_FIGURE_BEGIN::D2D1_FIGURE_BEGIN_FILLED);
    		for (int i = 0; i < vertexCount; i++)
    		{
    			auto v = vertices[i];
    			pGeometrySink->AddLine(D2D1::Point2F(v.x, v.y));
    		}
    		pGeometrySink->EndFigure(D2D1_FIGURE_END::D2D1_FIGURE_END_CLOSED);//D2D1_FIGURE_END_CLOSED
    		hr = pGeometrySink->Close();
    
    		//pRenderTarget->DrawGeometry(pPathGeometry, pSolidBrush, 1.0F, 0);//ID2D1StrokeStyle *strokeStyle = NULL
    		pRenderTarget->FillGeometry(pPathGeometry, pSolidBrush, 0);//ID2D1Brush *opacityBrush = NULL
    		///////hr = pRenderTarget->Flush();
    		SafeRelease(&pGeometrySink);
    
    	}
    	else
    	{
    
    	}
    }
    
    //
    //------------------
    pRenderTarget->BeginDraw();
    DrawSolidPolygon(...)//<---it only works once.
    pRenderTarget->EndDraw();
    //------------------
    pRenderTarget is a ID2D1HwndRenderTarget instance I created with ID2D1Factory

    Is my routine correct?

    My development environment: Windows Server2012R2/DX11/Windows SDK 10.0.17763.0/vs2017 community.


    2019年3月30日 0:39

全部回复