A newer version of Max is available. Click here to access the latest version of the documentation

jit.gl.sketch Reference

Use drawing commands with OpenGL

jit.gl.sketch

Description

Records and draws based on 3-D drawing commands. These commands range from simple turtle graphics to the majority of the OpenGL API.

Examples

Discussion

The jit.gl.sketch object requires one argument: the name of a drawing context. A named drawing context is a named instance of a jit.window, jit.pwindow, or jit.matrix object that has an instance of the jit.gl.render object associated with it. Additionally it can reference the name of a jit.gl.node sub-context. This value may also be set via the OB3D drawto attribute. If no argument is present, the object is implicitly added to the first valid drawing context or sub-context found in the current patch or by searching up the patcher hierarchy.

Attributes

autonormal [int]

Automatically generate normals for tri and quad primitives (default = 0)

displaylist [int]

Cache in a displaylist (default = 0)

immediate [int]

Toggles immediate mode. When immediate mode is enabled, a message will be executed when it is submitted rather than on draw.

pushstate [int]

Toggles pushing all attributes on draw.

Common Box Attributes

OB3D Attributes

Messages

anything

The jit.gl.sketch object accepts a list of drawing commands.

beginstroke

Begin definition of a stroked path of the style specified by a following stroke_style argument. Currently supported stroke styles are "
basic2d
line

circle

Arguments

radius [float]
theta-start [float]
theta-end [float]
Draws a circle with radius specified by radius and center point at the current drawing position. If theta-start and theta-end are specified, then an arc will be drawn instead of a full circle. The theta-start and theta-end arguments are in terms of degrees (0-360). The current shapeorient and shapeslice values will also affect the drawing.

cmd_delete

Deletes index or all instances of the command specified by the command argument from the command list.

cmd_enable

Arguments

mutex group
index [int]
command [symbol]
endmutex group
0/1 [int]
Enables/disables command in the command list.

cmd_insert

Arguments

index [int]
command [symbol]
command-args [variable]
Inserts command at position index in the command list.

cmd_replace

Arguments

index [int]
command [symbol]
command-args [variable]
Replaces position index in the command list with command .

cube

Arguments

scale-x [float]
scale-y [float]
scale-z [float]
Draws a box with width 2* scale-x , height 2* scale-y , depth 2* scale-z , and center point at the current drawing position. If scale-y and scale-z are not specified, they will assume the same value as scale-x . The current shapeorient , shapeslice , and shapeprim values will also affect the drawing.

cylinder

Arguments

radius1 [float]
radius2 [float]
mag [float]
theta-start [float]
theta-end [float]
Draws a cylinder with top radius specified by radius1 , bottom radius specified by radius2 , length specified by mag , and center point at the current drawing position. If theta-start and theta-end are specified, then a patch will be drawn instead of a full cylinder. The theta-start and theta-end arguments are in terms of degrees (0-360). The current shapeorient, shapeslice, and shapeprim values will also affect the drawing.

dimorient

The word dimorient followed by a zero or one, affects the drawmatrix command. The default is 0.

drawmatrix

Draws a matrix. The format of the message is
drawmatrix <matrixname> <drawing primitive> <texflag> <normalflag> <colorflag>
texflag values are specified as follows: 0=use, 1=ignore, 2=auto
normalflag values are specified as follows: 0=use, 1=ignore, 2=auto
colorflag values are specified as follows: 0=use, 1=ignore
edgeflag values are specified as follows: 0=use, 1=ignore

drawobject

The word drawobject, followed by a symbol that specifies an object name and a 0/1 flag that specifies whether or not to ignore the OB3D attributes, draws a named jit.gl object.

ellipse

Arguments

radius1 [float]
radius2 [float]
theta-start [float]
theta-end [float]
Draws the ellipse specified by radius1 , radius2 and center point at the current drawing position. If theta-start and theta-end are specified, then an arc will be drawn instead of a full ellipse. The theta-start and theta-end arguments are in terms of degrees (0-360). The current shapeorient and shapeslice values will also affect the drawing.

endstroke

Ends the definition of a stroked path and renders the path.

framecircle

Arguments

radius [float]
theta-start [float]
theta-end [float]
Draws the circumference of the circle with radius specified by radius and center point at the current drawing position. If theta-start and theta-end are specified, then an arc will be drawn instead of a full circle. The theta-start and theta-end arguments are in terms of degrees (0-360). The current shapeorient and shapeslice values will also affect the drawing.

frameellipse

Arguments

radius1 [float]
radius2 [float]
theta-start [float]
theta-end [float]
Draws the circumference of the ellipse specified by radius1 , radius2 and center point at the current drawing position. If theta-start and theta-end are specified, then an arc will be drawn instead of a full ellipse. The theta-start and theta-end arguments are in terms of degrees (0-360). The current shapeorient and shapeslice values will also affect the drawing.

framequad

Arguments

x1 [float]
y1 [float]
z1 [float]
x2 [float]
y2 [float]
z2 [float]
x3 [float]
y3 [float]
z3 [float]
x4 [float]
y4 [float]
z4 [float]
Draws the frame of the quadrilateral specified by the four points x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4 .

frametri

Arguments

x1 [float]
y1 [float]
z1 [float]
x2 [float]
y2 [float]
z2 [float]
x3 [float]
y3 [float]
z3 [float]
Draws the frame of the triangle specified by the three points x1 y1 z1 x2 y2 z2 x3 y3 z3 .

getcamera

Returns the x, y, and z coordinates of the camera location.

getcmd_index

Arguments

index [int]
Sends the command list item at index as a message out the object's right outlet.

getcmdlist

Sends the command list as a series of messages out the object's right outlet. The command list is bracketed by max messages that indicate the beginning and the of the current command list, and the command list is output between these two lines, one line per command. The output takes the form:
cmdlist_begin index
cmdlist index command-name command-arg1 ... command-argN
cmdlist index ....
cmdlist_end

glalphafunc

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glbegin

Arguments

draw-prim [symbol]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glbindprogram

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glbindtexture

Arguments

texture-name [symbol]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glblendfunc

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glclear

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glclearcolor

Arguments

red [float]
green [float]
blue [float]
alpha [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glcleardepth

Arguments

depth [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glclipplane

Arguments

mutex group
plane-name [symbol]
plane-number [int]
endmutex group
coefficient1 [float]
coefficient2 [float]
coefficient3 [float]
coefficient4 [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glcolor

Arguments

near [float]
far [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glcolormask

Arguments

red [int]
green [int]
blue [int]
alpha [int]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glcolormaterial

Arguments

mutex group
face-name [symbol]
face-number [int]
endmutex group
lighting-mode [sumbol]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glcullface

Please see the OpenGL "Red Book" or "Blue Book" for more information.

gldepthmask

Arguments

0/1 [int]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gldepthrange

Please see the OpenGL "Red Book" or "Blue Book" for more information.

gldisable

Arguments

capability [symbol]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gldrawpixels

Arguments

matrix-name [symbol]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gledgeflag

Arguments

0/1 [int]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glenable

Arguments

capability [symbol]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glend

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glfinish

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glflush

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glfog

Arguments

parameter-name [symbol]
parameter-value [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glfrustum

Arguments

left [float]
right [float]
bottom [float]
top [float]
near [float]
far [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glget

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glhint

Arguments

target [symbol]
mode [symbol]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gllight

Arguments

mutex group
light-name [symbol]
light-number [int]
endmutex group
parameter-name [symbol]
parameter-values [float list]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gllightmodel

Arguments

light-model [symbol]
values [float list]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gllinestipple

Arguments

factor [int]
bit-pattern [int]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gllinewidth

Arguments

width [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glloadidentity

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glloadmatrix

Arguments

matrix-name [symbol]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gllogicop

Arguments

opcode [symbol]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glmaterial

Arguments

mutex group
face-name [symbol]
face-number [int]
endmutex group
parameter-name [symbol]
parameter-values [float list]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glmatrixmode

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glmultmatrix

Arguments

matrix-name [symbol]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glnormal

Arguments

x [float]
y [float]
z [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glortho

Arguments

left [float]
right [float]
bottom [float]
top [float]
near [float]
far [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glpixeltransfer

Arguments

parameter-name [symbol]
parameter-value [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glpixelzoom

Arguments

x-factor [float]
y-factor [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glpointsize

Arguments

size [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glpolygonmode

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glpolygonoffset

Arguments

factor [float]
units [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glpopattrib

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glpopmatrix

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glpushattrib

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glpushmatrix

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glrasterpos

Arguments

x [float]
y [float]
z [float]
w [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glreadpixels

Arguments

matrix-name [symbol]
x [int]
y [int]
width [int]
height [int]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glrect

Arguments

x1 [float]
y1 [float]
x2 [float]
y2 [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glrotate

Arguments

angle [float]
x [float]
y [float]
z [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glscale

Arguments

x-scale [float]
y-scale [float]
z-scale [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glscissor

Arguments

x [int]
y [int]
width [int]
height [int]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glshademodel

Please see the OpenGL "Red Book" or "Blue Book" for more info.

gltexcoord

Arguments

s [float]
t [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gltexenv

Arguments

parameter-name [symbol]
parameter-values [float list]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gltexgen

Arguments

mutex group
coordinate-name [symbol]
coordinate-number [int]
endmutex group
mutex group
parameter-name [symbol]
parameter-number [int]
endmutex group
parameter-values [float list]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gltexparameter

Arguments

parameter-name [symbol]
parameter-values [list]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gltranslate

Arguments

delta-x [float]
delta-y [float]
delta-z [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glulookat

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glunbindprogram

Please see the OpenGL "Red Book" or "Blue Book" for more information.

gluortho2d

Arguments

left [float]
right [float]
bottom [float]
top [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

gluperspective

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glutessbegincontour

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glutessbeginpolygon

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glutessedgeflag

Arguments

0/1 [int]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glutessendcontour

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glutessendpolygon

Please see the OpenGL "Red Book" or "Blue Book" for more information.

glutessmatrix

Arguments

matrix-name [symbol]
Draws a matrix using the tessellator as a set of vertices and colors. Dim 0 represents a single vertex/color. Dim 1 represents a single contour. Dim 2 represents a single polygon.

glutessnormal

Arguments

x [float]
y [float]
z [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glutessproperty

Arguments

property-name [symbol]
property-values [list]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glutessvertex

Arguments

x [float]
y [float]
z [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glvertex

Arguments

x [float]
y [float]
z [float]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

glviewport

Arguments

x [int]
y [int]
width [int]
height [int]
Please see the OpenGL "Red Book" or "Blue Book" for more information.

line

Arguments

delta-x [float]
delta-y [float]
delta-z [float]
Draws a line from the current drawing position to the location delta-x delta-y delta-z relative to the current drawing position.

linesegment

Arguments

x1 [float]
y1 [float]
z1 [float]
x2 [float]
y2 [float]
z2 [float]
Draws a line from the location specified by x1 y1 z1 to the location specified by x2 y2 z2 .

lineto

Arguments

x [float]
y [float]
z [float]
Draws a line from the current drawing position to the location specified by x y z .

move

Arguments

delta-x [float]
delta-y [float]
delta-z [float]
Moves the drawing position delta-x delta-y delta-z relative to the current drawing position.

moveto

Arguments

x [float]
y [float]
z [float]
Moves the drawing position to the location specified by x y z .

plane

Arguments

scale-x1 [float]
scale-y1 [float]
scale-x2 [float]
scale-y2 [float]
Draws a plane with top width 2* scale-x1 , left height 2* scale-y1 , bottom width 2* scale-x2 , right height 2* scale-y2 , and center point at the current drawing position. If scale-y1 is not specified, it will assume the same value as scale-x1 . If scale-x2 and scale-y2 are not specified, they will assume the same values as scale-x1 and scale-y1 respectively. The current shapeorient, shapeslice, and shapeprim values will also affect the drawing.

point

Arguments

x [float]
y [float]
z [float]
Draws a point at the location specified by x y z .

quad

Arguments

x1 [float]
y1 [float]
z1 [float]
x2 [float]
y2 [float]
z2 [float]
x3 [float]
y3 [float]
z3 [float]
x4 [float]
y4 [float]
z4 [float]
Draws the quadrilateral specified by the four points x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4 .

reset

Delete all elements of the command list.

roundedplane

The message roundedplane round_amount scale_x scale_y draws a rounded plane with width 2 * scale_x , and height 2 * scale_y and center point at the current drawing position. The size of the rounded portion of the plane is determined by the round_amount argument. If scale_y is not specified, it will assume the same value as scale_x .

screentoworld

The word screentoworld, followed by a pair of numbers that specify x and y coordinates, returns an array containing the x , y , and z world coordinates associated with a given screen pixel using the same the depth from the camera as 0,0,0. Optionally a third depth arg may be specified, which may be useful for hit detection and other applications. The depth value is typically specified in the range 0.-1. where 0 is the near clipping plane, and 1. is the far clipping plane.

shapeorient

Arguments

rot-x [float]
rot-y [float]
rot-z [float]
Sets the current orientation for shape drawing commands (circle, framecircle, ellipse, frameellipse, sphere, cylinder, torus, cube, and plane). The rot-x , rot-y , and rot-z arguments are in terms of degrees (0-360). The order in which the orientation is applied is first rotate about x axis rot-x , then rotate about y axis rot-y , and finally rotate about z axis rot-z .

shapeprim

Arguments

draw-prim [symbol]
Sets the current drawing primitive for shape drawing commands (circle, framecircle, ellipse, frameellipse, sphere, cylinder, torus, cube, and plane). Valid values for draw-prim are:
lines
line_loop
line_strip
points
polygon
quads
quad_grid
quad_strip
triangles
tri_grid
tri_fan
tri_strip

shapeslice

Arguments

slice-a [int]
slice-b [int]
Sets the current level of decimation (resolution) for shape drawing commands (circle, framecircle, ellipse, frameellipse, sphere, cylinder, torus, cube, and plane).

sphere

Arguments

radius [float]
theta1-start [float]
theta1-end [float]
theta2-start [float]
theta2-end [float]
Draws a sphere with radius specified by radius and center point at the current drawing position. If theta1-start , theta1-end , theta2-start , and theta2-end are specified, then a patch will be drawn instead of a full sphere. The theta1-start , theta1-end , theta2-start , and theta2-end arguments are in terms of degrees (0-360). The current shapeorient, shapeslice, and shapeprim values will also affect the drawing.

strokeparam

The word strokeparam, followed by a parameter name argument and a list of parameter values, sets the current value of the parameter specified by the parameter_name argument to be the value specified by parameter_value argument(s). Some parameters are global for the extent of a stroked path definition, while others may vary on a point by point basis.

strokepoint

The word strokepoint, followed by three numbers that specify x , y , z coordinates, defines an anchor point at the location specified by those coordinates. Some stroke styles (such as basic2d) will ignore the z coordinate.

torus

Arguments

radius1 [float]
radius2 [float]
theta1-start [float]
theta1-end [float]
theta2-start [float]
theta2-end [float]
Draws a torus with major radius specified by radius1 , minor radius specified by radius1 , and center point at the current drawing position. If theta1-start , theta1-end , theta2-start , and theta2-end are specified, then a patch will be drawn instead of a full torus. The theta1-start , theta1-end , theta2-start , and theta2-end arguments are in terms of degrees (0-360). The current shapeorient, shapeslice, and shapeprim values will also affect the drawing.

tri

Arguments

x1 [float]
y1 [float]
z1 [float]
x2 [float]
y2 [float]
z2 [float]
x3 [float]
y3 [float]
z3 [float]
Draws the triangle specified by the three points x1 y1 z1 x2 y2 z2 x3 y3 z3 .

worldtoscreen

The word worldtoscreen, followed by three numbers that specify x , y , z coordinates, returns an array containing the x , y , and depth screen coordinates associated with a given world coordinate. The depth value is typically specified in the range 0.-1. where 0 is the near clipping plane, and 1. is the far clipping plane.

OB3D Messages

See Also

Name Description
Working with OpenGL Working with OpenGL
Lua in Max Lua in Max
jit.gl.graph
jit.gl.gridshape
jit.gl.handle
jit.gl.isosurf
jit.gl.mesh
jit.gl.model
jit.gl.nurbs
jit.gl.plato
jit.gl.render
jit.gl.shader
jit.gl.slab
jit.gl.text2d
jit.gl.text3d
jit.gl.texture
jit.gl.videoplane
jit.gl.volume
Tutorial 40: Drawing in OpenGL using jit.gl.sketch Tutorial 40: Drawing in OpenGL using jit.gl.sketch