Direct2D Base Driver
This driver represents a base driver for all system-dependent drivers implemented in the Microsoft Windows system,
but uses a new API called Direct2D. The drivers Native Window, IUP, Image and Double Buffer
The main motivation for the use of Direct2D was transparency for all the primitives. Beyond that we got other features
like anti-aliasing, gradient filling and bezier lines.
This driver still does not completely replace the GDI Windows base driver, because Direct2D does not have support for
XOR, EMF nor Printer. Also the applications need to adapt the rendering of text that is slightly different from GDI. It is know that
Direct2D can be slower than GDI in some cases (specially when drawing in
integer coordinates) and faster in other cases.
It has features similar to the GDI+ driver. But does not support the regular
metafile input/output. On the other hand it seems to be faster than GDI+. It is
similar to the OpenGL driver in the sense it was designed for display only.
Printer support exists since Windows 8 only, but it is complicated and not
implemented in CD.
To be able to use the driver the function
cdInitDirect2D must be called. Notice
that this is NOT a context plus driver.
The application must be linked with the "cddirect2d.lib" library
and use the "cddirect2d.h" header. This driver only works in
In Lua, you should do require"cdluadirect2d". The
cdInitDirect2D call is not necessary in
Extra Drivers (cddirect2d.h)
These are not ContextPlus drivers.
CD_DIRECT2D_NATIVEWINDOW - Native window Driver
Same as CD_NATIVEWINDOW, uses the same creation
parameters. It is already double buffered and requires cdCanvasFlush
to be called.
CD_DIRECT2D_IMAGE - Server Image Driver
Same as CD_IMAGE, uses a server image created by the native window driver.
CD_DIRECT2D_IMAGERGB - RGB Client Image Driver
Similar to CD_IMAGERGB, but accept only the size "wxh"
as parameter. The image is always 32 bits per pixel RGBA and created
internally. The data buffer can be obtained using the
Behavior of Functions
does nothing, returns CD_ERROR.
Coordinate System and Clipping
UpdateYAxis: the orientation of axis Y is the opposite to its orientation in the CD
library. Except when using transformations.
- Floating point primitives are supported.
draws a circle with 1 pixel size.
WriteMode: does nothing. There is no support for XOR or NOT_XOR.
Pattern: each pixel can contain transparency information.
LineStyle: uses a custom Direct2D style when line width is 1. In World Coordinates the line style
has its scaled changed.
the maximum width is estimated from the character "W".
TextAlignment: is simulated. Although Direct2D has text alignment, the results
do not match the CD text alignment.
NativeFont: also accepts "-d"
to show the font-selection dialog box.
"System" is mapped to "MS Sans Serif", "Courier" is mapped to "Courier New",
"Helvetica" is mapped to "Arial", and "Times" is mapped to "Times New Roman".
Underline and Strikeout are supported.
GetImageRGB: NOT supported. Except when using the
returns "1". So the application can detect if the driver uses the Direct2D base
driver. Other drivers that do not implement this attribute will return NULL.
- "IMGINTERP": changes how
interpolation is used in image scale. Can be "BEST" (highest-quality),
"BILINEAR" (linear interpolation), "GOOD" (quality similar to BILINEAR),
"NEAREST" (nearest-neighbor filtering) or "FAST" (quality similar to NEAREST).
- "HATCHBOXSIZE": size of the hatch grid in pixels used to create hatches.
- "PATTERNIMAGE": defines
a filled interior style using a server image as pattern. Data must be a server
image handle created with the Direct2D base driver. Interior style is set to
- "RADIALGRADIENT": defines
a filled interior style that uses a radial gradient between two colors. It
uses a center point and a radius ("%d %d %d" = xc yc r). It starts
at the center using the foreground color, and end at the radius using the background color. If a regular interior style is
set after the attribute, the gradient is lost. Interior style is set to CD_CUSTOMPATTERN. For example:
cdCanvasSetfAttribute(canvas, "RADIALGRADIENT", "%d %d 50", w - 125, 325);
cdCanvasSector(canvas, w - 125, 325, 50, 50, 0, 360);
- "ROTATE": allows the usage of 1 angle and 1 coordinate (x, y), that
define a global rotation transformation centered in the specified coordinate. Use 1 real and 2 integer values inside a
string ("%g %d %d" = angle x y). Can not be set if a transformation
is already set.
- "LINEARGRADIENT": defines a filled interior style that uses a linear gradient
between two colors. It uses 2 points ("%d %d %d %d" = x1 y1 x2 y2), one for the starting point using (using the
foreground color), and another one for the end point (using the background color).
If a regular interior style is set, the gradient is lost. Interior style is
set to CD_CUSTOMPATTERN. For example:
cdCanvasSetfAttribute(canvas, "LINEARGRADIENT", "%d 200 %d 250", w - 150, w - 100); /* x1 y1 x2 y2 */
cdCanvasBox(canvas, w - 150, w - 100, 200, 250);
- "UTF8MODE": enables the usage
of the UTF-8 encoding for strings. It can have the following
values: "1" or "0". Default is "0".