| Function Name | Parameter | Return | Explain |
| setcolor | dword | dword | Sets current color, returns the color being replaced. See remark. |
| setbkcolor | dword | dword | Sets background color, returns the color being replaced. See remark. |
| gradingmode | boolean | boolean | Toggles grading mode. Affected function: lineto |
| setBlendMode | dword srcBlend, destBlend |
dword srcBlend, destBlend |
Set blend mode for alpha blending, returns the mode being
replaced. See remark. |
| getRenderTarget | number index | nil or d3dsurface | Retrieve the current render target surface, return nil if failed. |
| setRenderTarget | d3dsurface
surf, [ number index ] |
boolean | Set the specified render target; The index indicates 0 based render target index; if the index is absent, set the first render target. |
| Function Name | Parameter | Return | Explain |
| point | number x, y | None | Draws a point using the current color at the position specified by x and y. |
| moveto | number x, y | point | Moves the current position to the point specified by x and y. |
| lineto | number x, y | boolean | Draws a line from the current position up to, but not including, a point. If grading mode is off, draws with current color; if grading mode is on, draws from current color to background color. |
| triangle | point p1, p2, p3 | boolean | Draws a triangle using the current color. Three points must arrange as clockwise order. |
| filltriangle | point p1, p2, p3 | boolean | Fills a triangle using the background color. Three points must arrange as clockwise order. |
| circle | point center number radius, segments | boolean | Draws a circle using the current color. The minimum of segments is 3. |
| fillcircle | point center number radius, segments | boolean | Fills a circle using the background color. The minimum of segments is 3. |
| rect | rect | boolean | Draws a rectangle using the current color. |
| fillrect | rect | boolean | Fills a rectangle using the background color. |
| textout | number x, y string text | boolean | Writes a character string at a specified location using the current color. |
| getTextExtent | string text | number cx, cy | Computes the width and height of a line of text. |
| blt | number x, y, texid | boolean | Transfers texture bitmap assigned by texid to a specified location.Also do color blending, the result is Texture X Background Color, include alpha element. |
| stretchblt | rect rect number texid | boolean | Copies a bitmap into a destination rectangle, stretching or compressing the bitmap if necessary to fit the dimensions of the destination rectangle. Also do color blending, the result is Texture X Background Color, include alpha element. |
| Function Name | Parameter | Return | Explain |
| point | vec | None | Draws a point using the current color at the position specified by vec. |
| moveto | vec | vec | Moves the current position to the point specified by vec. |
| lineto | vec | boolean | Draws a line from the current position up to a point. If grading mode is off, draws with current color; if grading mode is on, draws from current color to background color. |
| triangle | vec v1, v2, v3 | boolean | Draws a triangle using the current color. Three points must arrange as clockwise order. |
| filltriangle | vec v1, v2, v3 | boolean | Fills a triangle using the background color. Three points must arrange as clockwise order. |
| circle | vec center,
dir number radius, segments boolean newmode |
boolean | Draws a circle locating at center and facing along dir
using the current color. The minimum of segments is 3. See remark newmode. |
| fillcircle | vec center,
dir number radius, segments boolean newmode |
boolean | Fills a circle locating at center and facing along dir
using the background color. The minimum of segments is 3. See remark newmode. |
| box | vec min, max | boolean | Draws a frame of box bounded by min and max, using the current color. |
| cylinder | vec center,
dir number height, radius1, radius2, segments boolean newmode |
boolean | Draws a frame of cylinder using the current color. The minimum
of segments is 3. See remark newmode. |
| setmatrix | matrix | matrix | Changes current transform matrix, returns the matrix being replaced. All 3D drawing will affected by this matrix. |
| ztest | boolean | boolean | Toggles Depth Buffering, returns the state being replaced. If turn off ztest, later drawing will cover previous drawing no matter what position relation. |
A dword color's every element is described by one bytes. From high to low in turn is Alpha, Red, Green, Blue. For example, a dword with value 0xAABBCCDD express Alpha=0xAA, Red=0xBB, Green=0xCC, Blue=0xDD. There are Predefined Colors to provide convenience of using dword color.
newmode:
For circle, fillcircle and cylinder functions, there are two
matrices affect drawing: the inner matrix of function (fun_mat) and public matrix of the
draw3d class (pub_mat). In old mode (default, newmode = false), the total matrix is
pub_mat x fun_mat; in new mode (newmode = true), the total matrix is fun_mat
x pub_mat.
When Direct3D renders a primitive, it generates a color for the primitive based on the primitive's material (or the colors of its vertices) and lighting information. If an application enables texture blending, Direct3D must then blend the texel colors of one or more textures with the primitive's current colors. Direct3D uses the following formula to determine the final color for each pixel in the primitive's image.
![]()
In the preceding formula, FinalColor is the pixel color that is output to the
target rendering surface. TexelColor stands for the color of the texel that
corresponds to the current pixel. SourceBlendFactor is a calculated value that
Direct3D uses to determine the percentage of the texel color to apply to the final color. PixelColor
is the color of the current pixel in the primitive's image. DestBlendFactor
represents the percentage of the current pixel's color that will be used in the final
color.
| Blend Mode | Blend Factor | Explain |
| BLEND_ZERO | (0, 0, 0, 0) | all zero for r, g, b, a |
| BLEND_ONE | (1, 1, 1, 1) | all one for r, g, b, a |
| BLEND_SRCCOLOR | (Rs, Gs, Bs, As) | source color (TexelColor in the preceding formula) |
| BLEND_INVSRCCOLOR | (1Rs, 1Gs, 1Bs, 1As) | inverse source color |
| BLEND_SRCALPHA | (As, As, As, As) | source alpha |
| BLEND_INVSRCALPHA | (1As, 1As, 1As, 1As) | inverse source alpha |
| BLEND_DESTALPHA | (Ad, Ad, Ad, Ad) | destination alpha |
| BLEND_INVDESTALPHA | (1Ad, 1Ad, 1Ad, 1Ad) | inverse destination alpha |
| BLEND_DESTCOLOR | (Rd, Gd, Bd, Ad) | destination color (PixelColor in the preceding formula) |
| BLEND_INVDESTCOLOR | (1Rd, 1Gd, 1Bd, 1Ad) | inverse destination color |
| BLEND_SRCALPHASAT | (f, f, f, 1); f = min(As, 1Ad). | use the minimum value of source alpha and inverse destination alpha |
All blend modes are stored in the draw table, so you must reference them with a 'draw.' prefix. For example:
local
srcblend,destblend=draw.setBlendMode(draw.BLEND_ONE,draw.BLEND_ONE)
draw.stretchblt(r,tex)
draw.setBlendMode(srcblend,destblend)