Click here to Skip to main content
15,794,795 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
So I've been working on an unmanaged C++ 2D MFC system in Visual Studio 2013 using GDI+ (Document View architecture). I need simple shapes shaded from each vertex of the shape - either a triangle with a color in each corner, blending those colors to the interior, or a rectangle doing the same.

In GDI plus, this is quite straightforward:

using namespace Gdiplus;
void DrawGradientTriangle( Graphics &rGraphics )
	Gdiplus::GraphicsPath gpath;
	gpath.AddLine( 100, 400, 200, 400 );
	gpath.AddLine( 200, 400, 150, 300 );

	int nColorCount = 3;
	Color agdiClr[] =

	PathGradientBrush gbrush( &gpath );
	gbrush.SetSurroundColors( agdiClr, &nColorCount );
	gbrush.SetCenterColor( Color::White );
	rGraphics.FillPath( &gbrush, &gpath );

However, I have enough of these shapes that hardware acceleration would be appreciated, so I would like to move to D2D. Windows7 is the target and my understanding is that hardware acceleration is not necessarily provided with GDI+ in more recent OS's.

Is there any equivalent to this in Direct2D? I have been able to get most aspects of the system working well in D2D, but have not found any convenient way to mimic the above behavior. I know it can be done in Direct3D, but the infrastructure to get that going in an mfc program is a bit odious, and I'm not excited about going in that direction.

Any direction would be greatly appreciated.

What I have tried:

I have looked at more current options within D2D, especially drawing a gradient mesh (see but these features appear to be only supported in Windows10 or later.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900