GLDraw {
statement1;
statement2;
...
statementK;
}
The statements should be Mathscript-OpenGL statements. These are just like OpenGL statements except that the functions are not case sensitive, and they do not contain the prefixes: "gl", "glu", or "aux". The constants (such as "GL_LINESTRIP" must be capitalized). The effect is to create an anonymous actor, which may be removed using the "refresh" command, or from the Graph3D menu: Refresh. Anonymous actors created with GLDraw actually accumulate to the limit of approximately 16,656 OpenGL statements, so you may have several of them. After that, you must refresh to create more. The Dodecahedron example below consists of 5 statements.
Mathscript (actually, LISP) first creates a "compiled list" which is the translation of all the OpenGL commands into binary form. Nothing is drawn on the screen at this time. It then sends this compiled list to OpenGL. When the end of the GLDraw { ...} block is encountered, OpenGL draws the resulting anonymous actor. At this point, OpenGL has what it needs to display the actor, and never refers to Mathscript again to draw it. So OpenGL may rotate and translate the actor in real-time.
The GLDraw {..} Protocol is the low-level entry point to OpenGL's wide range of functions. It makes it possible easily to experiment with geometry at the command line. For example, one can write a graph command like the following, that creates a minimal grapher to be used in orthogonal projection mode.
Command glgraph (fn ff) { 'This creates a new command called GLGraph'
local (ve #2 v2) (ve #3 v3) { 'These Local declarations tell the compiler that v2 and v3 are vectors'
make variable x;
let v2 be [-10,10];
let re be 500;
let fg(x) be [x, ff(x), 0]; 'This defines the vector-valued function (curve) to be drawn.'
let a be v2(1);
let b be v2(2);
let inc be (b-a)/re;
gldraw { 'Finally call OpenGL with the GLDraw protocol'
begin(GL_LINE_STRIP); 'Draw the graph as a sequence of segments'
do
i = 0
until i >= re {
v3 := fg(a+i*inc); 'This object form is the next vertex'
vertex(v3); 'Give the vertex to OpenGL'
i := i+1;
}
end();
}
}
}
Then
glgraph sin;
or
make f(x) x^2/10;
glgraph f;
will draw the graphs, with a difference. You may rotate these!
Do not use the Draw Protocol in Actor Definition Scripts (Actor, Edit an Actor) because it is already called for you there.
For example, you may create an anonymous actor by executing:
gldraw {
linewidth(3);
glColor(0,0, 255, 255);
wiredodecahedron(10.1);
glColor(255, 0, 128, 255);
Soliddodecahedron(10);
}
