From MS: "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. Direct2D provides Win32 developers with the ability to perform 2-D graphics rendering tasks with superior performance and visual quality."
Direct2D support is implemented as COM objects, that are encapsulated in GFA-BASIC like commands. These command names start with D2, like D2Color, D2Line, D2Brush, etc. To use Direct2D include the GFA-BASIC 32 library direct2d.lg32 in your program. The library exports GFA-BASIC like commands and functions that correspond to the set of graphic commands GFA-BASIC already offers. The syntax of D2Line mimics the behaviour of the Line command, D2DefFill selects a new fill brush as DefFill does, etc. Because the Direct2D commands have a great resemblance with GFA-BASIC's commands, they can be used in almost the same manner. The big difference between the two is that Direct2D batches the drawing operations between a call to D2BeginDraw and D2EndDraw. The drawing is usually centralized in a separate render procedure that handles all output. The render procedure is called by the form's WM_PAINT handler the _Paint event sub. Most of the samples simply handle the drawing form inside the _Paint event sub.
The different Direct2D command's help topics discus Direct2D specifics. You are encouraged to step through the samples in the Samples\Direct2D directory or start reading with the D2GetRT topic in this help. D2GetRT is the base in each program to initalize Direct2D and to provide a render target (canvas) to draw on. A good place to start reading.
You can also find a lot of articles on the internet. Because Direct2D is COM based many introduction articles spent quite some text on the handling of the COM interfaces. This is of little importance to the GB-programmer using the Direct2D library. The Direct2D library encapsulates the COM calls and hides the complex interface calls.
Since many Direct2D resources are COM objects, the D2 library functions return the COM objects in GB's Object type. These Objects cannot be used to call the interface methods, they're simply used to store the pointer to the COM object. The advantage of the use of Object for COM pointer storage is their automatic release when the Object goes out of scope. For instance, a call to D2GetRT will return the COM object that represents the render target. The GFA-BASIC application stores the object in a global Object variable using the Set command. When the program terminates the global Object variable goes out of scope and the referenced COM object will be released.
Direct2D uses a general display independent (DIP) coordinate system. One DIP is 1/96 inch and conforms to one physical pixel on a regular 96-dots-per-inch display. The DIP is also used on high-resolution display, however a DIP pixel will occupy multiple physical display pixels. Direct2D facilitates the development dpi-aware applications. The coordinate system is the same as default 96-dots-per-inch we are used to with GDI output and GB's graphical commands. Many of the D2* command samples demonstrate the use of DIPs. In particular, the D2Pset.g32 example uses the mouse to draw on the render target and shows how to convert mouse input to DPI.
Since all Direct2D based applications need a render target you might want to start with Direct2D by examining the D2GetRT function first.
D2GetRT
Dpi-aware Applications
MS SDK Overview of Direct2D
MSDN Magazine Introducing Direct2D
There are many more Direct2D articles to be found, you might search for "direct2d introduction".
Back to: Creating An Application.
{Created by Sjouke Hamstra; Last updated: 16/05/2020 by James Gaite}