Classes


Last modified: 2013-3-2

Class Sketch

Javascript files loaded by the jsui object have access to the Sketch object, which may be used for drawing graphics. We will refer to the Sketch object and the methods it exposes as the Sketch API. The Sketch API is built upon the cross platform OpenGL API, and can be divided into two categories: "OpenGL Methods" and "High Level Methods". The "OpenGL Methods" are a direct binding for a large portion of the low level OpenGL API, and the "High Level Methods" are extensions built upon lower level OpenGL calls.

Sketch in Cycling '74 Reference

Class Summary
Constructor Attributes Constructor Name and Description
<private>  
Sketch()
No constructor.
Field Summary
Field Attributes Field Name and Description
Number get/set 
not documented
Boolean get/set 
not documented
Boolean get/set 
Turns on/off full scene antialiasing.
Number get/set 
not documented
Array[2] get/set 
size[0] is width size[1] is height.
Method Summary
Method Attributes Method Name and Description
void 
beginstroke(stroke_style)
Begin definition of a stroked path of the style specified by the stroke_style argument.
void 
circle(radius, ctheta_start, theta_end)
Draws a filled circle with radius specified by the radius argument.
void 
copypixels(source_object, destination_x, destination_y, source_x, source_y, width, height)
Copies pixels from the source object to the location specified by the destination_x and destination_y arguments.
void 
cube(scale_x, scale_y, scale_z)
Draws a cube with width 2*scale_x, height 2*scale_y, depth 2*scale_z, and center point at the current drawing position.
void 
cylinder(radius1, radius2, mag, theta_start, theta_end)
Draws a cylinder with top radius specified by the radius1 argument, bottom radius specified by the radius2 argument, length specified by the mag argument, and center point at the current drawing position.
void 
The default2d method is a simple way to set the graphics state to default properties useful for 2D graphics.
void 
The default3d method is a simple way to set the graphics state to default properties useful for 3D graphics.
Float 
depthatpixel(x, y)
Returns the depth value associated with the currently rendered pixel at a given absolute screen coordinate.
void 
ellipse(radius1, radius2, theta_start, theta_end)
Draws a filled ellipse with radii specified by the radius1 and radius2 arguments.
void 
End definition of a stroked path, and render the path.
void 
font(fontname)
Sets the current font to the fontname specified by the fontname argument.
void 
fontsize(points)
Sets the fontsize to the size specified by the points argument.
void 
framecircle(radius, theta_start, theta_end)
Draws a framed circle with radius specified by the radius argument.
void 
frameellipse(radius1, radius2, theta_start, theta_end)
Draws a framed ellipse with radii specified by the radius1 and radius2 arguments.
void 
framequad(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
Draws a framed quadrilateral with four corners specified by the x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, and z4 arguments.
void 
frametri(x1, y1, z1, x2, y2, z2, x3, y3, z3)
Draws a framed triangle with three corners specified by the x1, y1, z1, x2, y2, z2, x3, y3, and z3 arguments.
void 
Frees the image data from the native c peer, which is not considered by the JavaScript garbage collector, and may consume lots of memory until the garbage collector decides to run based on JS allocated memory.
Float Array[4] 
getpixel(x, y)
Returns an array containing the pixel value at the specified location.
Array[2] 
gettextinfo(string)
Returns an array containing the width and height of the given string in absolute screen coordinates, taking into account the current font and fontsize.
void 
glbegin(mode)
delimit the vertices of a primitive or a group of like primitives.
void 
glbindtexture(image_object)
bind a named texture to a texturing target.
void 
glblendfunc(src_function, dst_function)
specify pixel arithmetic.
void 
clear buffers to preset values.
void 
glclearcolor(red, green, blue, alpha)
specify clear values for the color buffers.
void 
glcleardepth(depth)
specify the clear value for the depth buffer.
void 
glclipplane(plane, coeff1, coeff2, coeff3, coeff4)
specify a plane against which all geometry is clipped.
void 
glcolor(red, green, blue, alpha)
changes the color of the next objects to be drawn.
void 
glcolormask(red, green, blue, alpha)
enable and disable writing of frame buffer color components.
void 
glcolormaterial(face, mode)
The glColorMaterial function causes a material color to track the current color.
void 
glcullface(mode)
specify whether front- or back-facing facets can be culled.
void 
enable or disable writing into the depth buffer.
void 
gldepthrange(near, far)
specify mapping of depth values from normalized device coordinates to window coordinates.
void 
gldisable(capability)
disable server-side GL capabilities.
void 
gldrawpixels(image)
write a block of pixels to the frame buffer.
void 
Flags polygon edges as either boundary or nonboundary edges.
void 
glenable(capability)
enable server-side GL capabilities.
void 
glend()
delimit the vertices of a primitive or a group of like primitives.
void 
block until all GL execution is complete.
void 
force execution of GL commands in finite time.
void 
glfog(parameter_name, value)
Fog is initially disabled.
void 
glfrustum(left, right, bottom, top, near, far)
multiply the current matrix by a perspective matrix.
void 
glhint(target, mode)
specify implementation-specific hints.
void 
gllight(light, parameter_name, value)
not documented

See OpenGL Reference
void 
gllightmodel(parameter_name, value)
not documented

See OpenGL Reference
void 
gllinestipple(factor, bit_pattern)
not documented

See OpenGL Reference
void 
gllinewidth(width)
not documented

See OpenGL Reference
void 
not documented

See OpenGL Reference
void 
glloadmatrix(matrix_array)
not documented

See OpenGL Reference
void 
gllogicop(opcode)
not documented

See OpenGL Reference
void 
not documented

See OpenGL Reference
void 
glmatrixmode(mode)
not documented

See OpenGL Reference
void 
glmultmatrix(matrix_array)
not documented

See OpenGL Reference
void 
glnormal(x, y, z)
not documented

See OpenGL Reference
void 
glortho(left, right, bottom, top, near, far)
not documented

See OpenGL Reference
void 
glpointsize(size)
not documented

See OpenGL Reference
void 
glpolygonmode(face, mode)
not documented

See OpenGL Reference
void 
glpolygonoffset(factor, units)
not documented

See OpenGL Reference
void 
not documented

See OpenGL Reference
void 
not documented

See OpenGL Reference
void 
not documented

See OpenGL Reference
void 
not documented

See OpenGL Reference
void 
glrect(x1, y1, x2, y2)
not documented

See OpenGL Reference
void 
glrotate(angle, x, y, z)
not documented

See OpenGL Reference
void 
glscale(x_scale, y_scale, z_scale)
not documented

See OpenGL Reference
void 
glscissor(x, y, width, height)
not documented

See OpenGL Reference
void 
glshademodel(mode)
not documented

See OpenGL Reference
void 
gltexcoord(s, t)
not documented

See OpenGL Reference
void 
gltexenv(parameter_name, val1, val2, val3, val4)
not documented

See OpenGL Reference
void 
gltexgen(coord, parameter_name, val1, val2, val3, val4)
not documented

See OpenGL Reference
void 
gltexparameter(parameter_name, val1, val2, val3, val4)
not documented

See OpenGL Reference
void 
gltranslate(delta_x, delta_y, delta_z)
not documented

See OpenGL Reference
void 
glulookat(eye_x, eye_y, eye_z, center_x, center_y, center_z, up_x, up_y, up_z)
not documented

See OpenGL Reference
void 
gluortho2d(left, right, bottom, top)
not documented

See OpenGL Reference
void 
gluperspective(fovy, aspect, near, far)
not documented

See OpenGL Reference
void 
gluvertex(x, y, z)
not documented

See OpenGL Reference
void 
glviewport(x, y, width, height)
not documented

See OpenGL Reference
void 
line(delta_x, delta_y, delta_z)
Draws a line from the current drawing position to the location specified the sum of the current drawing position and the delta x, y, and z arguments.
void 
linesegment(x1, y1, z1, x2, y2, z2)
Draws a line from the location specified by the x1, y1, and z1 arguments to the location specified by the x2, y2, and z2 arguments.
void 
lineto(x, y, z)
Draws a line from the current drawing position to the location specified by the x, y, and z arguments.
void 
move(delta_x, delta_y, delta_z)
Moves the drawing position to the location specified by the sum of the current drawing position and the delta x, y, and z arguments.
void 
moveto(x, y, z)
Moves the drawing position to the location specified by the x, y, and z arguments.
void 
The orth3d method is a simple way to set the graphics state to default properties useful for 3D graphics, using an orthographic projection (i.e.
void 
plane(scale_x1, scale_y1, scale_x2, scale_y2)
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.
void 
point(x, y, z)
Draws a point at the location specified by the x, y, and z arguments.
void 
quad(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
Draws a filled quadrilateral with four corners specified by the x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, and z4 arguments.
void 
Draws a rounded plane with width 2*scale_x, and height 2*scale_y and center point at the current drawing position.
Float Array[3] 
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.
void 
setpixel(x, y, red, green, blue, alpha)
Sets the pixel value at the specified location.
void 
shapeorient(rotation_x, rotation_y, rotation_z)
Sets the rotation for drawing internal to any of the "shape" drawing methods to the rotation specified by the x_rot, y_rot, and rotation_x, rotation_y, and rotation_z arguments.
void 
shapeprim(draw_prim)
Sets the OpenGL drawing primitive to use within any of the "shape" drawing methods.
void 
shapeslice(slice_a, slice_b)
Sets the number of slices to use when rendering any of the "shape" drawing methods.
void 
sphere(radius, theta1_start, theta1_end, theta2_start, theta2_end)
Draws a sphere with radius specified by the radius argument and center point at the current drawing position.
void 
strokeparam(parameter_name, parameter_values)
Set the current value of the parameter specified by the parameter_name argument to be the value specified by parameter_values argument(s).
void 
strokepoint(x, y, z)
Defines an anchor point at the location specified by the x, y, and z arguments.
void 
text(string)
Draws the text specified by the string argument at the current drawing position, taking into account the current font, fontsize, and text alignment.
void 
textalign(align_x, align_y)
Sets the alignment of text to be drawn with respect to the current drawing position.
void 
torus(radius1, radius2, theta1_start, theta1_end, theta2_start, theta2_end)
Draws a torus with major radius specified by the radius1 argument, minor radius specified by the radius2 argument, and center point at the current drawing position.
void 
tri(x1, y1, z1, x2, y2, z2, x3, y3, z3)
Draws a filled triangle with three corners specified by the x1, y1, z1, x2, y2, z2, x3, y3, and z3 arguments.
void 
worldtoscreen(x, y, z)
Returns an array containing the x, y, and depth screen coordinates associated with a given world coordinate.
Class Detail
<private>

Sketch

()
No constructor. Javascript files loaded by the jsui object have access to the Sketch object, which may be used for drawing graphics. We will refer to the Sketch object and the methods it exposes as the Sketch API. The Sketch API is built upon the cross platform OpenGL API, and can be divided into two categories: "OpenGL Methods" and "High Level Methods". The "OpenGL Methods" are a direct binding for a large portion of the low level OpenGL API, and the "High Level Methods" are extensions built upon lower level OpenGL calls.
An example of a high level method would be sketch.sphere(0.1) which calculates all of the geometry and associated information for lighting and color, and based on the current state of the sketch object, issues many OpenGL calls to render a sphere. The sketch.sphere() method is much simpler to use than the underlying OpenGL calls it makes use of. We consider "high level" to be that which isolates the programmer from the intricate details of OpenGL.

OpenGL Conventions and Differences

All OpenGL methods begin with prefix, "gl". While we will provide a listing of supported OpenGL methods in this document, for more in-depth coverage of OpenGL we recommend that you consult either online or printed documentation concerning the OpenGL API. The www.opengl.org website is the official online resource for OpenGL, and is a good starting point for online documentation, tutorials, links, news and other information pertaining to OpenGL. There are a few important differences between the OpenGL API, and the methods which the Sketch object exposes:
  • The Sketch methods are all lowercase, and only exist within the context of a sketch object. For example, this means that glBegin() will be sketch.glbegin(), and glClearColor() will be sketch.glclearcolor(). Javascript's "with" statement may be used to avoid having to type "sketch." for every method call.
  • All symbolic constants are lowercase Javascript strings, and have no "GL_" prefix. For example the constant GL_LIGHTING will be the Javascript string "lighting", and GL_LINE_STRIP is replaced with "line_strip".
  • There are no special versions of vector calls. Only floating point values are supported, and sketch will fill in extra values with defaults. For example glColorv4fv(), glColorv3fv(), etc. will simply be sketch.glcolor().
  • Sketch supports passing Javascript arrays in place of individual arguments. So glColor3f(0.,0.,1.) can be replaced with either sketch.glcolor(0.,0.,1.), or sketch.glcolor(frgb), where frgb is the array [0.,0.,1.].


Colors and Coordinates

As is the convention in OpenGL, color values should be specified with each component as a floating point number in the range of 0.-1., as opposed to an integer in the range 0-255. For example red would be (1.,0.,0.), rather than (255,0,0). OpenGL also supports the use of an alpha channel for transparency and other types of blending modes. Colors with alpha channel values may be specified as RGBA, for example, green with 25% opacity would be (0.,1.,0.,0.25). If there is no alpha channel value present, it is assumed to be 1.--i.e. 100% opaque. By default, alpha blending is enabled. To turn off blending, use sketch.gldisable("blend"). When working in 3D, depth buffering is turned on by default, and will typically interfere with attempts to blend transparent objects. To turn off depth buffering, use sketch.gldisable("depth_test").

Unlike some graphics APIs, the OpenGL API does not distinguish between 2D and 3D drawing. Conventional 2D drawing is simply a subset of 3D drawing calls with specific graphics state--e.g. no lighting, no depth testing, orthorgraphic projection, et cetera. High level utility methods are provided as a convenience to setup up the OpenGL graphics state to something typically used for 2D or 3D graphics. If assuming 2D drawing conventions, one can ordinarily use z coordinates of zero for all methods that require them.

Coordinates in OpenGL are also given in terms of floating point relative world coordinates, rather than absolute pixel coordinates. The scale of these world coordinates will change depending on the current graphics transformation--i.e. translation, rotation, scaling, projection mode, viewport, etc. However, our default mapping is that Y coordinates are in the range -1. to 1 from bottom to top, and X coordinates are in the range -aspect to aspect from left to right, where aspect is equal to the ratio of width/height. In the default case, (0,0) will be center of your object, (-aspect,1.) will be the upper left corner, and (aspect,-1.) will be the lower right corner.

Note that user events are typically provided in terms of absolute screen coordinates. Please see the sketch.screentoworld() and sketch.worldtoscreen() methods for converting between absolute screen coordinates and relative world coordinates.
Example:
sketch.default2d();
// no benefit from antialiasing in this example
sketch.fsaa=0;

var mybrgb = [0.2,0.2,0.2];
var myfrgb = [0.8,0.8,0.8];

draw();

function draw(){
	var str,width,height,aspect,down;
	var cmid = new Array();
	var c1,c2,c3,c4;

	height = box.rect[3] - box.rect[1];
	width = box.rect[2] - box.rect[0];
	aspect = width/height;

	with (sketch) {
		glclearcolor(mybrgb);
		glclear();
		glcolor(myfrgb);
		fontsize(height*0.1);
		textalign("center","center");
		moveto(0,0.5);
		text("size: " + width + "," + height);
		moveto(0,-0.5);
		text("aspect: " + aspect.toFixed(2));
	}
}
Field Detail
{Number get/set}

defaultmode

not documented

{Boolean get/set}

depthbuffer

not documented

{Boolean get/set}

fsaa

Turns on/off full scene antialiasing.

{Number get/set}

quality

not documented

{Array[2] get/set}

size

size[0] is width size[1] is height.
Method Detail
{void}

beginstroke

(stroke_style)
Begin definition of a stroked path of the style specified by the stroke_style argument. Currently supported stroke styles are:
Example:
//TODO
Parameters:
{String} stroke_style
 

{void}

circle

(radius, ctheta_start, theta_end)
Draws a filled circle with radius specified by the radius argument. 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, shapeslice, and shapeprim values will also affect the drawing.
Example:
//TODO
Parameters:
{Float} radius
{Float} ctheta_start
{Float} theta_end
 

{void}

copypixels

(source_object, destination_x, destination_y, source_x, source_y, width, height)
Copies pixels from the source object to the location specified by the destination_x and destination_y arguments. The initial x and y offset into the source and size of the rectangle copied can be speified by the source_x, source_y, width and height arguments. If these are not present an x and y offset of zero and width and height equal to the source image is assumed. No scaling of pixels is supported. The source object can either be an instance of Image, or Sketch. If blending is enabled in the destination sketch object, alpha blending will be performed and the current alpha color will also be applied globally. The copypixels method is much faster than obtaining the equivalent result using glbindtexture() to texture a plane, and is the recommended means of drawing images when scaling and rotation is not required.
Example:
//TODO
Parameters:
{Maxobj} source_object
{Integer} destination_x
{Integer} destination_y
{Integer} source_x
{Integer} source_y
{Integer} width
{Integer} height
 

{void}

cube

(scale_x, scale_y, scale_z)
Draws a cube with width 2*scale_x, height 2*scale_y, depth 2*scale_z, and center point at the current drawing position. If the scale_y and scale_z arguments are not specified, they will assume the same value as scale_x. The current shapeorient, shapeslice, and shapeprim values will also affect the drawing.
Example:
//TODO
Parameters:
{Float} scale_x
{Float} scale_y
{Float} scale_z
 

{void}

cylinder

(radius1, radius2, mag, theta_start, theta_end)
Draws a cylinder with top radius specified by the radius1 argument, bottom radius specified by the radius2 argument, length specified by the mag argument, and center point at the current drawing position. If the theta_start and theta_end arguments 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.
Example:
//TODO
Parameters:
{Float} radius1
{Float} radius2
{Float} mag
{Float} theta_start
{Float} theta_end
 

{void}

default2d

()
The default2d method is a simple way to set the graphics state to default properties useful for 2D graphics. It is called everytime your object is resized if default2d() has been called more recently than default3d(). It is essentially equivalent to the following set of calls:
Example:
with (sketch) {
	glpolygonmode("front_and_back","fill");
	glpointsize(1.);
	gllinewidth(1.);
	gldisable("depth_test");
	gldisable("fog");
	glcolor(0.,0.,0.,1.);
	glshademodel("smooth");
	gldisable("lighting");
	gldisable("normalize");
	gldisable("texture");
	glmatrixmode("projection");
	glloadidentity();
	glortho(-aspect, aspect, -1, 1, -1,100.);
	glmatrixmode("modelview");
	glloadidentity();
	glulookat(0.,0.,2.,0.,0.,0.,0.,0.,1.);
	glclearcolor(1., 1., 1., 1.);
	glclear();
	glenable("blend");
	glblendfunc("src_alpha","one_minus_src_alpha");
}

{void}

default3d

()
The default3d method is a simple way to set the graphics state to default properties useful for 3D graphics. It is called everytime the jsui object is resized if default3d() has been called more recently than default2d().

It is essentially equivalent to the following set of calls:
Example:
with (sketch) {
	glpolygonmode("front_and_back","fill");
	glpointsize(1.);
	gllinewidth(1.);
	glenable("depth_test");
	glenable("fog");
	glcolor(0.,0.,0.,1.);
	glshademodel("smooth");
	gllightmodel("two_side", "true");
	glenable("lighting");
	glenable("light0");
	glenable("normalize");
	gldisable("texture");
	glmatrixmode("projection");
	glloadidentity();
	gluperspective(default_lens_angle, aspect, 0.1, 100.);
	glmatrixmode("modelview");
	glloadidentity();
	glulookat(0.,0.,2.,0.,0.,0.,0.,0.,1.);
	glclearcolor(1., 1., 1., 1.);
	glclear();
	glenable("blend");
	glblendfunc("src_alpha","one_minus_src_alpha");
}

{Float}

depthatpixel

(x, y)
Returns the depth value associated with the currently rendered pixel at a given absolute screen coordinate.
Example:
//TODO
Parameters:
{Integer} x
{Integer} y
 

{void}

ellipse

(radius1, radius2, theta_start, theta_end)
Draws a filled ellipse with radii specified by the radius1 and radius2 arguments. 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, shapeslice, and shapeprim values will also affect the drawing.
Example:
//TODO
Parameters:
{Float} radius1
{Float} radius2
{Float} theta_start
{Float} theta_end
 

{void}

endstroke

()
End definition of a stroked path, and render the path.
Example:
//TODO

{void}

font

(fontname)
Sets the current font to the fontname specified by the fontname argument.
Example:
//TODO
Parameters:
{String} fontname
 

{void}

fontsize

(points)
Sets the fontsize to the size specified by the points argument. Note that this size is an absolute, rather than relative value.
Example:
//TODO
Parameters:
{Float} points
 

{void}

framecircle

(radius, theta_start, theta_end)
Draws a framed circle with radius specified by the radius argument. 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, shapeslice, and shapeprim values will also affect the drawing.
Example:
//TODO
Parameters:
{Float} radius
{Float} theta_start
{Float} theta_end
 

{void}

frameellipse

(radius1, radius2, theta_start, theta_end)
Draws a framed ellipse with radii specified by the radius1 and radius2 arguments. 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, shapeslice, and shapeprim values will also affect the drawing.
Example:
//TODO
Parameters:
{Float} radius1
{Float} radius2
{Float} theta_start
{Float} theta_end
 

{void}

framequad

(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
Draws a framed quadrilateral with four corners specified by the x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, and z4 arguments. After this method has been called, the drawing position is updated to the location specified by the x4, y4, and z4 arguments.
Example:
//TODO
Parameters:
{Float} x1
{Float} y1
{Float} z1
{Float} x2
{Float} y2
{Float} z2
{Float} x3
{Float} y3
{Float} z3
{Float} x4
{Float} y4
{Float} z4
 

{void}

frametri

(x1, y1, z1, x2, y2, z2, x3, y3, z3)
Draws a framed triangle with three corners specified by the x1, y1, z1, x2, y2, z2, x3, y3, and z3 arguments. After this method has been called, the drawing position is updated to the location specified by the x3, y3, and z3 arguments.
Example:
//TODO
Parameters:
{Float} x1
{Float} y1
{Float} z1
{Float} x2
{Float} y2
{Float} z2
{Float} x3
{Float} y3
{Float} z3
 

{void}

freepeer

()
Frees the image data from the native c peer, which is not considered by the JavaScript garbage collector, and may consume lots of memory until the garbage collector decides to run based on JS allocated memory. Once called, the Sketch object is not available for any other use.
Example:
//TODO

{Float Array[4]}

getpixel

(x, y)
Returns an array containing the pixel value at the specified location. This array is ordered RGBA, i.e. array element 0 is red, 1, green, 2, blue, 3 alpha. Color values are floating point numbers in the range 0.-1.
Example:
//TODO
Parameters:
{Integer} x
{Integer} y
 

{Array[2]}

gettextinfo

(string)
Returns an array containing the width and height of the given string in absolute screen coordinates, taking into account the current font and fontsize.
Example:
//TODO
Parameters:
{String} string
 

{void}

glbegin

(mode)
delimit the vertices of a primitive or a group of like primitives.

See OpenGL Reference
Example:
//TODO
Parameters:
{String} mode
Specifies the primitive or primitives that will be created from vertices presented between glBegin and the subsequent glEnd. Ten symbolic constants are accepted:
  • points
  • lines
  • line_strip
  • line_loop
  • triangles
  • triangle_strip
  • triangle_fan
  • quads
  • quad_strip
  • polygon
 

{void}

glbindtexture

(image_object)
bind a named texture to a texturing target. Note: this method also calls glenable(texture)

See OpenGL Reference
Example:
//TODO
Parameters:
{Image} image_object
 

{void}

glblendfunc

(src_function, dst_function)
specify pixel arithmetic.

See OpenGL Reference
Example:
//TODO
Parameters:
{String} src_function
Specifies how the red, green, blue, and alpha source blending factors are computed. Nine symbolic constants are accepted:
  • zero
  • one
  • dst_color
  • one_minus_dst_color
  • src_alpha
  • one_minus_src_alpha
  • dst_alpha
  • one_minus_dst_alpha
  • src_alpha_saturate
The initial value is 'one'.
{String} dst_function
Specifies how the red, green, blue, and alpha destination blending factors are computed. Eight symbolic constants are accepted:
  • zero
  • one
  • src_color
  • one_minus_src_color
  • src_alpha
  • one_minus_src_alpha
  • dst_alpha
  • one_minus_dst_alpha
The initial value is 'zero'.
 

{void}

glclear

()
clear buffers to preset values.

See OpenGL Reference
Example:
//TODO

{void}

glclearcolor

(red, green, blue, alpha)
specify clear values for the color buffers.

See OpenGL Reference
Example:
//TODO
Parameters:
{Float} red
{Float} green
{Float} blue
{Float} alpha
 

{void}

glcleardepth

(depth)
specify the clear value for the depth buffer.

See OpenGL Reference
Example:
//TODO
Parameters:
{Float} depth
 

{void}

glclipplane

(plane, coeff1, coeff2, coeff3, coeff4)
specify a plane against which all geometry is clipped.

See OpenGL Reference
Example:
//TODO
Parameters:
{Integer} plane
{Float} coeff1
{Float} coeff2
{Float} coeff3
{Float} coeff4
 

{void}

glcolor

(red, green, blue, alpha)
changes the color of the next objects to be drawn.

See OpenGL Reference
Example:
//TODO
Parameters:
{Float} red
{Float} green
{Float} blue
{Float} alpha
 

{void}

glcolormask

(red, green, blue, alpha)
enable and disable writing of frame buffer color components. Specify whether red, green, blue, and alpha are to be written into the frame buffer. The initial values are all 'true', indicating that the color components are written.

See OpenGL Reference
Example:
//TODO
Parameters:
{Boolean} red
{Boolean} green
{Boolean} blue
{Boolean} alpha
 

{void}

glcolormaterial

(face, mode)
The glColorMaterial function causes a material color to track the current color.

See OpenGL Reference
Example:
//TODO
Parameters:
{String} face
Specifies whether front, back, or both front and back material parameters should track the current color. Accepted values are front, back, and front_and_back. The default value is front_and_back.
{String} mode
Specifies which of several material parameters track the current color. Accepted values are emission, ambient, diffuse, specular, and ambient_and_diffuse. The default value is ambient_and_diffuse.
 

{void}

glcullface

(mode)
specify whether front- or back-facing facets can be culled.

See OpenGL Reference
Example:
//TODO
Parameters:
{String} mode
Specifies whether front- or back-facing facets are candidates for culling. Symbolic constants front, back, and front_and_back are accepted. The initial value is back.
 

{void}

gldepthmask

(on)
enable or disable writing into the depth buffer.

See OpenGL Reference
Example:
//TODO
Parameters:
{Boolean} on
 

{void}

gldepthrange

(near, far)
specify mapping of depth values from normalized device coordinates to window coordinates.

See OpenGL Reference
Example:
//TODO
Parameters:
{Float} near
Specifies the mapping of the near clipping plane to window coordinates. The initial value is 0.
{Float} far
Specifies the mapping of the far clipping plane to window coordinates. The initial value is 1.
 

{void}

gldisable

(capability)
disable server-side GL capabilities.

See OpenGL Reference
Example:
//TODO
Parameters:
{String} capability
 

{void}

gldrawpixels

(image)
write a block of pixels to the frame buffer.

See OpenGL Reference
Example:
//TODO
Parameters:
{Maxobj} image
 

{void}

gledgeflag

(on)
Flags polygon edges as either boundary or nonboundary edges. This can be used to determine whether interior surface lines are visible.

See OpenGL Reference
Example:
//TODO
Parameters:
{Boolean} on
 

{void}

glenable

(capability)
enable server-side GL capabilities.

See OpenGL Reference
Example:
//TODO
Parameters:
capability
 

{void}

glend

()
delimit the vertices of a primitive or a group of like primitives.

See OpenGL Reference
Example:
//TODO

{void}

glfinish

()
block until all GL execution is complete. glFinish does not return until the effects of all previously called GL commands are complete. Such effects include all changes to GL state, all changes to connection state, and all changes to the frame buffer contents.

See OpenGL Reference
Example:
//TODO

{void}

glflush

()
force execution of GL commands in finite time. Different GL implementations buffer commands in several different locations, including network buffers and the graphics accelerator itself. glFlush empties all of these buffers, causing all issued commands to be executed as quickly as they are accepted by the actual rendering engine. Though this execution may not be completed in any particular time period, it does complete in finite time. Because any GL program might be executed over a network, or on an accelerator that buffers commands, all programs should call glFlush whenever they count on having all of their previously issued commands completed. For example, call glFlush before waiting for user input that depends on the generated image.

See OpenGL Reference
Example:
//TODO

{void}

glfog

(parameter_name, value)
Fog is initially disabled. While enabled, fog affects rasterized geometry, bitmaps, and pixel blocks, but not buffer clear operations. To enable and disable fog, call glEnable and glDisable with argument GL_FOG. glFog assigns the value or values in params to the fog parameter specified by pname.

See OpenGL Reference
Example:
//TODO
Parameters:
{String} parameter_name
The following values are accepted for pname:
  • fog_mode
    params is a single integer or floating-point value that specifies the equation to be used to compute the fog blend factor, f. Three symbolic constants are accepted:
    • linear
    • exp
    • exp2
    The equations corresponding to these symbolic constants are defined below. The initial fog mode is exp.
  • fog_density
    params is a single integer or floating-point value that specifies density, the fog density used in both exponential fog equations. Only nonnegative densities are accepted. The initial fog density is 1.
  • fog_start
    params is a single integer or floating-point value that specifies start, the near distance used in the linear fog equation. The initial near distance is 0.
  • fog_end
    params is a single integer or floating-point value that specifies end, the far distance used in the linear fog equation. The initial far distance is 1.
  • fog_index
    params is a single integer or floating-point value that specifies if, the fog color index. The initial fog index is 0.
  • fog_color
    params contains four integer or floating-point values that specify Cf, the fog color. Integer values are mapped linearly such that the most positive representable value maps to 1.0, and the most negative representable value maps to -1.0. Floating-point values are mapped directly. After conversion, all color components are clamped to the range [0, 1]. The initial fog color is (0, 0, 0, 0).
{mixed} value
depends on parameter_name
 

{void}

glfrustum

(left, right, bottom, top, near, far)
multiply the current matrix by a perspective matrix.

See OpenGL Reference
Example:
//TODO
Parameters:
{Float} left
Specify the coordinates for the left and right vertical clipping planes.
{Float} right
Specify the coordinates for the left and right vertical clipping planes.
{Float} bottom
Specify the coordinates for the bottom and top horizontal clipping planes.
{Float} top
Specify the coordinates for the bottom and top horizontal clipping planes.
{Float} near
Specify the distances to the near and far depth clipping planes. Both distances must be positive.
{Float} far
Specify the distances to the near and far depth clipping planes. Both distances must be positive.
 

{void}

glhint

(target, mode)
specify implementation-specific hints.

See OpenGL Reference
Example:
//TODO
Parameters:
target
mode
 

{void}

gllight

(light, parameter_name, value)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
light
parameter_name
value
 

{void}

gllightmodel

(parameter_name, value)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
parameter_name
value
 

{void}

gllinestipple

(factor, bit_pattern)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
factor
bit_pattern
 

{void}

gllinewidth

(width)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
width
 

{void}

glloadidentity

()
not documented

See OpenGL Reference
Example:
//TODO

{void}

glloadmatrix

(matrix_array)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
matrix_array
 

{void}

gllogicop

(opcode)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
opcode
 

{void}

glmaterial

()
not documented

See OpenGL Reference
Example:
//TODO

{void}

glmatrixmode

(mode)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
mode
 

{void}

glmultmatrix

(matrix_array)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
matrix_array
 

{void}

glnormal

(x, y, z)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
x
y
z
 

{void}

glortho

(left, right, bottom, top, near, far)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
left
right
bottom
top
near
far
 

{void}

glpointsize

(size)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
size
 

{void}

glpolygonmode

(face, mode)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
face
mode
 

{void}

glpolygonoffset

(factor, units)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
factor
units
 

{void}

glpopattrib

()
not documented

See OpenGL Reference
Example:
//TODO

{void}

glpopmatrix

()
not documented

See OpenGL Reference
Example:
//TODO

{void}

glpushattrib

()
not documented

See OpenGL Reference
Example:
//TODO

{void}

glpushmatrix

()
not documented

See OpenGL Reference
Example:
//TODO

{void}

glrect

(x1, y1, x2, y2)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
x1
y1
x2
y2
 

{void}

glrotate

(angle, x, y, z)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
angle
x
y
z
 

{void}

glscale

(x_scale, y_scale, z_scale)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
x_scale
y_scale
z_scale
 

{void}

glscissor

(x, y, width, height)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
x
y
width
height
 

{void}

glshademodel

(mode)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
mode
 

{void}

gltexcoord

(s, t)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
s
t
 

{void}

gltexenv

(parameter_name, val1, val2, val3, val4)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
parameter_name
val1
val2
val3
val4
 

{void}

gltexgen

(coord, parameter_name, val1, val2, val3, val4)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
coord
parameter_name
val1
val2
val3
val4
 

{void}

gltexparameter

(parameter_name, val1, val2, val3, val4)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
parameter_name
val1
val2
val3
val4
 

{void}

gltranslate

(delta_x, delta_y, delta_z)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
delta_x
delta_y
delta_z
 

{void}

glulookat

(eye_x, eye_y, eye_z, center_x, center_y, center_z, up_x, up_y, up_z)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
eye_x
eye_y
eye_z
center_x
center_y
center_z
up_x
up_y
up_z
 

{void}

gluortho2d

(left, right, bottom, top)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
left
right
bottom
top
 

{void}

gluperspective

(fovy, aspect, near, far)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
fovy
aspect
near
far
 

{void}

gluvertex

(x, y, z)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
x
y
z
 

{void}

glviewport

(x, y, width, height)
not documented

See OpenGL Reference
Example:
//TODO
Parameters:
x
y
width
height
 

{void}

line

(delta_x, delta_y, delta_z)
Draws a line from the current drawing position to the location specified the sum of the current drawing position and the delta x, y, and z arguments. After this method has been called, the drawing position is updated to the location specified by the sum of the current drawing position and the delta x, y, and z arguments.
Example:
//TODO
Parameters:
{Float} delta_x
{Float} delta_y
{Float} delta_z
 

{void}

linesegment

(x1, y1, z1, x2, y2, z2)
Draws a line from the location specified by the x1, y1, and z1 arguments to the location specified by the x2, y2, and z2 arguments. After this method has been called, the drawing position is updated to the location specified by the x2, y2, and z2 arguments.
Example:
//TODO
Parameters:
{Float} x1
{Float} y1
{Float} z1
{Float} x2
{Float} y2
{Float} z2
 

{void}

lineto

(x, y, z)
Draws a line from the current drawing position to the location specified by the x, y, and z arguments. After this method has been called, the drawing position is updated to the location specified by the x, y, and z arguments.
Example:
//TODO
Parameters:
{Float} x
{Float} y
{Float} z
 

{void}

move

(delta_x, delta_y, delta_z)
Moves the drawing position to the location specified by the sum of the current drawing position and the delta x, y, and z arguments.
Example:
//TODO
Parameters:
{Float} delta_x
{Float} delta_y
{Float} delta_z
 

{void}

moveto

(x, y, z)
Moves the drawing position to the location specified by the x, y, and z arguments.
Example:
//TODO
Parameters:
{Float} x
{Float} y
{Float} z
 

{void}

ortho3d

()
The orth3d method is a simple way to set the graphics state to default properties useful for 3D graphics, using an orthographic projection (i.e. object scale is not affected by distance from the camera). It is called every time the jsui object is resized if ortho3d() has been called more recently than default2d(), or default3d().

It is essentially equivalent to the following set of calls:
Example:
with (sketch) {
	glpolygonmode("front_and_back","fill");
	glpointsize(1.);
	gllinewidth(1.);
	glenable("depth_test");
	glenable("fog");
	glcolor(0.,0.,0.,1.);
	glshademodel("smooth");
	gllightmodel("two_side", "true");
	glenable("lighting");
	glenable("light0");
	glenable("normalize");
	gldisable("texture");
	glmatrixmode("projection");
	glloadidentity();
	glortho(-aspect, aspect, -1, 1, -1,100.);
	glmatrixmode("modelview");
	glloadidentity();
	glulookat(0.,0.,2.,0.,0.,0.,0.,0.,1.);
	glclearcolor(1., 1., 1., 1.);
	glenable("blend");
	glblendfunc("src_alpha","one_minus_src_alpha");
}

{void}

plane

(scale_x1, scale_y1, scale_x2, scale_y2)
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.
Example:
//TODO
Parameters:
{Float} scale_x1
{Float} scale_y1
{Float} scale_x2
{Float} scale_y2
 

{void}

point

(x, y, z)
Draws a point at the location specified by the x, y, and z arguments. After this method has been called, the drawing position is updated to the location specified by the x, y, and z arguments.
Example:
//TODO
Parameters:
{Float} x
{Float} y
{Float} z
 

{void}

quad

(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
Draws a filled quadrilateral with four corners specified by the x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, and z4 arguments. After this method has been called, the drawing position is updated to the location specified by the x4, y4, and z4 arguments.
Example:
//TODO
Parameters:
{Float} x1
{Float} y1
{Float} z1
{Float} x2
{Float} y2
{Float} z2
{Float} x3
{Float} y3
{Float} z3
{Float} x4
{Float} y4
{Float} z4
 

{void}

roundedplane

()
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. The current shapeorient, shapeslice, and shapeprim values will also affect the drawing.
Example:
//TODO

{Float Array[3]}

screentoworld

(x, y)
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. The worldtoscreen method can be used to determine the depth value of a given world coordinate, and the depthatpixel method can be used to determine the depth value associated with the currently rendered pixel at a given absolute screen coordinate.
Example:
//TODO
Parameters:
{Integer} x
{Integer} y
 

{void}

setpixel

(x, y, red, green, blue, alpha)
Sets the pixel value at the specified location. Color values are floating point numbers in the range 0.-1.
Example:
//TODO
Parameters:
{Integer} x
{Integer} y
{Float} red
{Float} green
{Float} blue
{Float} alpha
 

{void}

shapeorient

(rotation_x, rotation_y, rotation_z)
Sets the rotation for drawing internal to any of the "shape" drawing methods to the rotation specified by the x_rot, y_rot, and rotation_x, rotation_y, and rotation_z arguments. Its use internal to a given shape method such as torus(0.1) would essentially be equivalent to the following set of OpenGL calls.
Example:
with (sketch) {
	glmatrixmode("modelview");
	glpushmatrix();
	glrotate(rotation_x,1.,0.,0.);
	glrotate(rotation_y,1.,1.,0.);
	glrotate(rotation_z,0.,0.,1.);
	torus(0.5,0.2);
	glpopmatrix();
}
Parameters:
{Float} rotation_x
{Float} rotation_y
{Float} rotation_z
 

{void}

shapeprim

(draw_prim)
Sets the OpenGL drawing primitive to use within any of the "shape" drawing methods. Acceptable values for the draw_prim argument are the following strings:
Example:
//TODO
Parameters:
{String} draw_prim
 

{void}

shapeslice

(slice_a, slice_b)
Sets the number of slices to use when rendering any of the "shape" drawing methods. Increasing the slice_a and slice_b arguments will increase the quality at which the shape is rendered, while decreasing these values will improve performance.
Example:
//TODO
Parameters:
{Float} slice_a
{Float} slice_b
 

{void}

sphere

(radius, theta1_start, theta1_end, theta2_start, theta2_end)
Draws a sphere with radius specified by the radius argument and center point at the current drawing position. If the theta1_start, theta1_end, theta2_start, and theta2_end arguments 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.
Example:
//TODO
Parameters:
{Float} radius
{Float} theta1_start
{Float} theta1_end
{Float} theta2_start
{Float} theta2_end
 

{void}

strokeparam

(parameter_name, parameter_values)
Set the current value of the parameter specified by the parameter_name argument to be the value specified by parameter_values argument(s). Some parameters are global for the extent of a stroked path definition, while others may vary on a point by point basis.

Basic 2D Stroke Style Parameters Line Stroke Style Parameters
Example:
//TODO
Parameters:
{String} parameter_name
{mixed list} parameter_values
 

{void}

strokepoint

(x, y, z)
Defines an anchor point at the location specified by the x, y, and z arguments. Some stroke styles such as "basic2d" will ignore the z coordinate.
Example:
//TODO
Parameters:
{Float} x
{Float} y
{Float} z
 

{void}

text

(string)
Draws the text specified by the string argument at the current drawing position, taking into account the current font, fontsize, and text alignment. Text is strictly 2D, and does not take into account any world transformations. After calling the text method, if the x axis text alignment is set to "left", the current drawing position will be updated to reflect the world position associated with the end of the string. If the x axis text alignment is set to "right", the current drawing position will be updated to reflect the world position associated with the end of the string. If the x axis text alignment is set to "center", the current drawing position will remain unchanged.
Example:
//TODO
Parameters:
{String} string
 

{void}

textalign

(align_x, align_y)
Sets the alignment of text to be drawn with respect to the current drawing position. Acceptable values for the x axis alignment are: Acceptable values for the y axis alignment are: The default alignment is "left", "bottom".
Example:
//TODO
Parameters:
{String} align_x
{String} align_y
 

{void}

torus

(radius1, radius2, theta1_start, theta1_end, theta2_start, theta2_end)
Draws a torus with major radius specified by the radius1 argument, minor radius specified by the radius2 argument, 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.
Example:
//TODO
Parameters:
{Float} radius1
{Float} radius2
{Float} theta1_start
{Float} theta1_end
{Float} theta2_start
{Float} theta2_end
 

{void}

tri

(x1, y1, z1, x2, y2, z2, x3, y3, z3)
Draws a filled triangle with three corners specified by the x1, y1, z1, x2, y2, z2, x3, y3, and z3 arguments. After this method has been called, the drawing position is updated to the location specified by the x3, y3, and z3 arguments.
Example:
//TODO
Parameters:
{Float} x1
{Float} y1
{Float} z1
{Float} x2
{Float} y2
{Float} z2
{Float} x3
{Float} y3
{Float} z3
 

{void}

worldtoscreen

(x, y, z)
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.
Example:
//TODO
Parameters:
{Float} x
{Float} y
{Float} z
 

©2012-2013
Max MSP Documentation copied to JsDoc by Tim Schenk SEO Frelancer Berlin. Some examples are by him. Some descriptions of classes, interfaces, properties, methods or events are by him. Until now, most of it is a copy. Published with permission of Cycling '74. This document might be wrong or incomplete. All informations without any warranty. All trademarks are the property of their respective owners. Documentation generated by JsDoc Toolkit on 2013-3-2