Hello guys,

I've been playing with Direct2D lately, and found out (from a presentation) that converting geometries into meshes makes rendering a lot faster
So, how do I do this?

I tried this:

hr = RenderEngine.D2DFactory->CreateRectangleGeometry(D2D1::RectF(0,0,10,10), &pGem);
	hr = RenderEngine.RenderTarget->CreateMesh(&pMesh);
	hr = pMesh->Open(&pSink);
	hr = pGem->Tessellate(D2D1::Matrix3x2F::Identity(), pSink);
	hr = pSink->Close();
	SafeReplace(&pFillMesh, pMesh);

Where pGem is of the ID2D1RectangleGeometry type
pMesh is of the ID2D1Mesh type
pSink is of the ID2D1TesselationSink type

And then in the render function I called

for(int i=0;i<total;i++)
RenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(p[i].x, p[i].y));
RenderTarget->FillMesh(NULL, pFillMesh)

But nothing draws.
I ran debug and tested if all the HRESULTs of the mesh creation were allright, and they were all on S_OK
When i replace the draw code with FillGeometry it draws fine.
I also tried commenting out the pMesh->Release() line.

BTW, the compiler doesn't give errors

Please help me fix this code or give me a (link to a) simple example where meshes are used, because the example on msdn has almost 90kb of code.

Thanks in advance,


This was posted 10 years ago, but I came across this same issue while trying to learn Direct2D. I modeled my code similar to this one and got it to work, see code below.

My code is similar, except I added the anti alias thingy and it seems to work. The FillMesh was incorrect also. The example on MSDOCS tries to do the following: path_geo->Open(&geo_sink) first to create a strokestyle, widen the geomety and apply a matrix. This does not work. If you just omit that and skip to RenderTarget->CreateMesh(&mesh) part then you will be ok. The thing about that is if you are using an existing path_geometry the path_geo->Open will fail. My guess is because you cannot edit a completed geometry. The MSDN code probably applies if you create the mesh while creating the path_geometry.

This code below works:


//the document requires that this is done before displaying the mesh
//do note that if you do not change it back the following lines and circles drawn will look jagged


RenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(x, y));

//RenderTarget->FillMesh(NULL, pFillMesh)

RenderTarget->FillMesh(pFillMesh, pBrush);



Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.