draw

 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.
getTextExtent string text number  cx, cy Computes the width and height of a line of text.
       
getFont None nil or font Retrieves the current font
setFont [ font ] None Sets current font
createFont number  height
[ string fontname ]
[ number texturesize ]
nil or font Creates a font, height is size of character.
fontname
is Arial, Consolas, etc.
texturesize is the buffer image size ( 256, 512, 1024, 2048 ), bigger height needs bigger texturesize. default is 512.
deleteFont font boolean If the font is used, delete will failed.
getFontsHead None dword  
getFontsNext dword font font, dword pos  

 

draw2d arrow.png (238 ??)draw

 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
[ number seg = -1 ]
boolean Draws a circle using the current color. The minimum of segments is 3.
See remark seg
fillcircle point  center   number radius, segments
[ number seg = -1 ]
boolean Fills a circle using the background color. The minimum of segments is 3.
See remark seg
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  [ number wscale, hscale ] boolean Writes a character string at a specified location using the current color.
wscale, hscale : the width scale and height scale, default is 1,1
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.

 

draw3d arrow.png (238 ??)draw

 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, [ number t1, t2, t3, tex ] boolean Fills a triangle using the background color. Three points must arrange as clockwise order.
if tex specified, using t1,t2,t3 as texture coord, draw textured triangle.
circle vec  center, dir   number radius, segments
[ boolean newmode = false ]
[ number seg = -1 ]
boolean Draws a circle locating at center and facing along dir using the current color. The minimum of segments is 3.
See remark newmode, seg
fillcircle vec  center, dir   number radius, segments
[ boolean newmode = false ]
[ number seg = -1 ]
boolean Fills a circle locating at center and facing along dir using the background color. The minimum of segments is 3.
See remark newmode, seg
rect vec  coner, width, height None Draws a rectangle using the current color
fillrect vec  coner, width, height, [ number tex ] None Fills a rectangle using the background color or texture
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 = false ]
[ number seg = -1 ]
boolean Draws a frame of cylinder using the current color. The minimum of segments is 3.
See remark newmode, seg
textout vec  org, widthdir, heightdir, string text  [ number wscale, hscale ] boolean Draws 3d text at a specified location using the current color.
wscale, hscale : the width scale and height scale, default is 1,1
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.

 

Remark

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.

seg:
For circle, fillcircle and cylinder functions, if seg is -1, then draw full circle; otherwise, draw specific seg / segments percents of circle.

alpha blending:

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 (1–Rs, 1–Gs, 1–Bs, 1–As) inverse source color
BLEND_SRCALPHA (As, As, As, As) source alpha
BLEND_INVSRCALPHA (1–As, 1–As, 1–As, 1–As) inverse source alpha
BLEND_DESTALPHA (Ad, Ad, Ad, Ad) destination alpha
BLEND_INVDESTALPHA (1–Ad, 1–Ad, 1–Ad, 1–Ad) inverse destination alpha
BLEND_DESTCOLOR (Rd, Gd, Bd, Ad) destination color (PixelColor in the  preceding formula)
BLEND_INVDESTCOLOR (1–Rd, 1–Gd, 1–Bd, 1–Ad) inverse destination color
BLEND_SRCALPHASAT (f, f, f, 1); f = min(As, 1–Ad). 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)