The first parameter indicates the Direct3D device where the swap chain resources will be allocated, and the second is the target HWND where the front buffer will be presented. If all goes well, the swap chain is created. One thing to keep in mind is that only a single swap chain can be associated with a given HWND.
The next step is to create the Direct2D device. Like the Direct3D device, it serves as a resource manager. This device represents the display adapter in Direct2D. What you really need it for is to create the Direct2D device context:. Unlike the HWND render target, which could only ever target the window for which it was created, the device context can switch targets at run time and initially has no target set at all.
You can define the bitmap properties as follows:. PixelFormat just describes to Direct2D what the underlying swap chain buffer looks like. You can now create a Direct2D bitmap to point to the swap chain back buffer and point the device context to this bitmap:. Finally, you need to tell Direct2D how to scale its logical coordinate system to the physical display embodied by the DXGI surface:.
Figure 4 provides the basic outline of the Render method. As with the HWND render target, the Render method first checks whether the render target needs to be created. The Render method then follows the usual pattern of bracketing draw commands with the BeginDraw and EndDraw methods. Instead, it merely concludes rendering to the target bitmap. In this case, there are three scenarios to deal with. One source of occlusion, however, is when the active desktop is switched.
Every resource pointer represents a reference directly or indirectly to the underlying device. Each one must be released in order for the device to be properly re-created. At a minimum, you need to hold on to the render target so that you can actually issue drawing commands and the swap chain so that you can present. Of course, this will fail unless all references to these buffers have been released.
Figure 5 shows you how. Setting this to a nullptr value releases that final reference so that the ResizeBuffers method will succeed. If anything goes wrong, I simply release the device and all of its resources; the Render method will take care of re-creating it all when the time comes. You now have everything you need to render in a desktop window with Direct2D 1.
Join me next time as I continue to explore Direct2D. He blogs at kennykerr. Thanks to the following technical expert for reviewing this article: Worachai Chaoweeraprasit Microsoft. Skip to main content. Was this information helpful? Yes No. Thank you! Any more feedback? The more you tell us the more we can help. Can you help us improve? Resolved my issue. Clear instructions. Easy to follow. No jargon. Direct2D is a hardware-accelerated, immediate-mode, 2-D graphics API that provides high performance and high-quality rendering for 2-D geometry, bitmaps, and text.
Third-party applications that require Platform Update for Windows Vista or Platform Update for Windows Server can have Windows Update detect whether the required updated is installed; if it is not, Windows Update will download and install it in the background. For more information about both updates, see Platform Update for Windows Vista. Skip to main content. This browser is no longer supported.
0コメント