<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>
<chapter name="Appendix B: The OpenGL Matrix Format">

<previous name="jitterchapter99_appendixa">QuickTime Confidential</previous>
<next name="jitterchapter99_appendixc">The JXS File Format</next>
<parent name="jitindex">Jitter Tutorials</parent>



<h1>Appendix B: The OpenGL Matrix Format</h1>
<h2>Matrices, Video and OpenGL</h2>
<p>OpenGL is a standard which specifies a virtual machine for turning lists of numbers into 2D images. The lists may contain the 3D locations of vertices to connect with lines or polygons. They can also contain other data such as coordinates for texture mapping, normals for lighting, colors and edge flags.</p>

<p>Jitter treats video as a type of data which can be processed in its general matrix system. When manipulating video data in Jitter, each cell of a matrix represents one pixel. The four planes of the matrix store the <m>A, R, G</m> and <m>B</m> components of that pixel. This is Jitter's convention for storing video.</p>

<p>Jitter also has a convention, used by all the objects in the GL group, for storing OpenGL-compatible image descriptions in a matrix. Like video data, these descriptions can be read, processed, and output by various objects. This document  specifies Jitter's convention for storing OpenGL data in matrices and the syntax of messages to the <o>jit.gl.render</o> object containing these matrices.</p>

<b>When You Need This Reference</b>
<p>Objects in the GL group send out matrices in the format described here when they have their <m>matrixoutput</m> attributes set to 1. In order to process these geometries through your own patches, you will need to know this format. If you want to make geometries directly using the <o>jit.op</o> object and other matrix operators, you will also need to know the format. But if Jitter's GL objects are flexible enough for your drawing needs, you can continue to let these objects draw behind the scenes without any knowledge of the OpenGL matrix format.</p>

<h2>GL Matrix Reference</h2>
<h3>Message Format</h3>
<p>OpenGL data can be passed to the <o>jit.gl.render</o> object in Max messages of the forms</p>

<p><m>jit_matrix [geometry matrix] </m></p>

<p><m>jit_matrix [geometry matrix] [draw primitive] </m></p>

<p><m>and</m></p>

<p><m>jit_matrix [geometry matrix] [connections matrix] [draw primitive].</m></p>

<h3>Draw Primitive</h3>
<p>The draw primitive specifies how to draw the connections between vertices in the geometry matrix. When a draw primitive is not passed to the <o>jit.gl.render</o> object along with the geometry matrix, the current primitive of the <o>jit.gl.render</o> object is used. The current primitive can be changed by sending a message containing just the primitive. When a draw primitive accompanies the geometry matrix, it is used only to draw the given geometry and the current primitive is unchanged. </p>

<p>The draw primitive can be one of the following symbols:</p>
<list>
<li><m>points</m> Draws each vertex as a single point. </li>

<li><m>lines</m> Connects eavery other pair of vertices with a line. Given a geometry matrix with vertices A, B, C and D, it draws line segments AB and CD. </li>

<li><m>line_strip</m> Connects each pair of vertices with a line. Given a geometry matrix with vertices A, B, C and D, it draws line segments AB, BC and CD. </li>

<li><m>line_loop</m> Like line_strip but a line segment is drawn connecting the last vertex in the matrix back to the first one. </li>

<li><m>triangles</m> Draws unconnected triangles. Given vertices A B C D E F, draws triangles ABC and DEF. </li>

<li><m>tri_strip</m> Draws a strip of connected triangles. Given vertices A B C D E F, draws triangles ABC, CBD, CDE and EDF. Note the order of the vertices, which is swapped so that all the triangles face the same way (see Tutorial 33: Polygon Modes, Colors and Blending).</li>

<li><m>tri_fan</m> Draws a fan of triangles. Given vertices A B C D E F, draws triangles ABC, ACD, ADE and AEF. </li>

<li><m>quads</m> Draws unconnected quadrilaterals. Given vertices A B C D E F G H, draws quadrilaterals ABCD and EFGH. </li>

<li><m>quad_strip</m> Draws connected quadrilaterals. Given vertices A B C D E F, draws quadrilateral ABCD and CDFE. </li>

<li><m>polygon</m> Draws a single polygon using all the vertices in the matrix. If the polygon is not simple and convex, the results are undefined. </li>

<li><m>tri_grid</m> If the geometry matrix has two dimensions, triangles are drawn which link each vertex to its neighbors in the matrix to form a surface. </li>

<li><m>quad_grid</m> If the geometry matrix has two dimensions, quadrilaterals are drawn which link each vertex to its neighbors in the matrix to form a surface. </li>
</list>
<h3>The Connections Matrix</h3>
<p>A connections matrix must be one-dimensional and contain either <i>long</i> or <i>char</i> data. If present, it specifies the order in which to connect the vertices in the geometry matrix. By leaving the geometry matrix constant and changing the connections matrix which indexes into it, a changing set of connections between the same vertices can be drawn. </p>

<h3>The Geometry Matrix</h3>
<p>Geometry matrices must contain data in <i>long</i>, <i>float32</i>, or <i>float64</i> format, <i>float32</i> being the most common choice. <i>Float64</i> has more precision than is normally needed for rendering to the screen. The long data type restricts values to integers, which is generally not desired when specifying coordinates. </p>

<p>Each cell of the matrix represents one vertex. The image is rendered by drawing connections between vertices, either along the rows or the columns of the matrix. A one cell wide matrix will be connected along columns (its only column). A one cell high matrix will be connected along rows. If the matrix is more than one cell in both width and height, the <m>geom_rows</m> attribute of the <o>jit.gl.render</o> object determines whether rows or columns will be followed. If the <m>tri_grid</m> or <m>quad_grid</m> primitives are specified, both the rows and the columns of the matrix are always connected.</p>

<p>Matrices with anywhere from two to 13 planes can be used. Planes 13 and up are reserved for later use and will currently be ignored. Each plane represents a different value in one of five groups: vertices, texture coordinates, normals, vertex color and edges. If enough planes are present to specify a given group, that group is used in rendering the matrix. To be used, each group must be totally present, with the exception of vertices. If only <i>x</i> and <i>y</i> values for vertices are present, the <i>z</i> coordinate of all vertices is set to 0, and an 2D image on the <i>xy</i> plane results.</p>

<list>

<li>plane 0:            <i>x</i> coordinate of vertex</li>

<li>plane 1:            <i>y</i> coordinate of vertex</li>

<li>plane 2:            <i>z</i> coordinate of vertex</li>

<li>plane 3:            <i>s</i> coordinate of texture at vertex, if textured</li>

<li>plane 4:            <i>t</i> coordinate of texture at vertex, if textured</li>

<li>plane 5:            <i>x</i> component of lighting normal at vertex</li>

<li>plane 6:            <i>y</i> component of lighting normal at vertex</li>

<li>plane 7:            <i>z</i> component of lighting normal at vertex</li>

<li>plane 8:            red component of vertex color</li>

<li>plane 9:            green component of vertex color</li>

<li>plane 10:          blue component of vertex color</li>

<li>plane 11:          alpha component of vertex color</li>

<li>plane 12:          edge flag for connection to next vertex: if = 0, no line is drawn.</li>
</list>

</chapter>
