MFC Support for Direct2D – Transforms (1)

Direct2D supports linear transforms like translation, scale, rotation and skew. If using MFC, we can apply transforms to render targets by calling CRenderTarget::SetTransform. Here is an example that shifts the render target 100 points on x-axis and 150 points on y-axis.

It looks not very handy to fill the matrix structure, so Matrix3x2F utility […]

MFC Support for Direct2D – Part 8: Lost Render Target

As stated in the Direct2D documentation, the graphics device might become unavailable. If the device is lost, the render target also becomes invalid, along with any device-dependent resources that were associated with the device. That happens infrequently (e.g. if the user removes the display adapter), but once something bad can happen, a good programmer must […]

MFC Support for Direct2D – Part 7: Saving to files

Once have enabled Direct2D support in an MFC application, there is no sweat to load an image from a file, by using one of CD2DBitmap constructors. Unfortunately, we cannot find a CD2DBitmap method to save it into a image file (something similar to CImage::Save or Gdiplus::Image::Save). No problem, we can try to do it ourselves. […]

MFC Support for Direct2D – Part 6: Composite Effects

We can combine two or more images and/or effects by using the composite effect. Here is an example. Drawing shadows using Direct2D composite effects

Demo project Download: You can set the amount of blur and the color as well as the distance of the shadow. Resources and related articles MSDN: Composite effect MSDN: Shadow […]

MFC Support for Direct2D – Part 5: Interoperability with GDI

There are two ways to combine Direct2D with Windows GDI API in the same application: Drawing Direct2D content to a GDI device context Drawing GDI content to a Direct2D GDI-compatible render target Let’s see each one! Drawing Direct2D content to a GDI device context For this purpose, use ID2D1DCRenderTarget instead of ID2D1HwndRenderTarget interface. If using MFC […]

MFC Support for Direct2D – Part 4: Built-in Effects

Direct2D has built-in support for image processing like changing brightness or contrast, blurring, creating drop shadows, and so on. Basically, we can use for this purpose the CreateEffect and DrawImage methods of ID2D1DeviceContext interface. So far, there is no MFC wrapper class for ID2D1DeviceContext but that’s not so big issue. Once having a valid ID2D1RenderTarget […]

MFC Support for Direct2D – Part 3: Multithreading

As shown in previous articles, we can enable MFC Direct2D support for a window by a call of CWnd::EnableD2DSupport. Example:

So far so good as long as all windows which use Direct2D are running in the same thread (usually the application main thread). But let’s say we have more than one window with intensive […]