Graphics in CsoundAV

by Gabriel Maldonado
http://csounds.com/maldonado


Graphics-related opcode quick reference


Introduction

CsoundAV can handle animated three-dimensional graphics, basing on the OpenGL widespread standard. OpenGL was chosen because it is supported by most platforms, and by most accelerated graphic cards. Furthermore OpenGL is easier to understand and to program than other 3D API (such as, for example Direct3D).

In order to handle realtime rendering processes, new concepts have been added to previous Csound versions. Firstly, a new engine, the graphic engine, has been added.

Note for programmers: this engine runs into its own thread, that is, independently from sound thread. At present time, only a very primitive type of synchronization between these two threads is provided, but in most cases this should not be a big problem, because i-rate and k-rate signals are accessible by both engines at the same time, so graphic animation timing is actually under user control. A sort of trivial hand-made semaphores have been used to avoid both threads to access critical sections of code at the same time, this will be probably improved in the future, possibly using operating system API. But, for now I intend to yield maximum priority to portability. Actually, graphics-related thread is the same thread of widget opcodes, but frames of graphic-output window can be updated by means of a callback mechanism. The insertion of the chunks of code belonging to OpenGL opcodes in the engine chain is done by copying all data to vector objects. This is not the most optimized way to implement the mechanism, and it will be improved in the future. Code has been written taking it into account portability between platforms, as much as possible. However, some porting troubles could rise, depending on C++ template support provided by compilers.
End of note

Frame-rate Opcodes

This additional engine works at a rate lower than k-rate. This rate is called “frame-rate” and refers to the rate at which subsequent graphic frames are shown in the screen. This rate is typically in the range of 10 to 50 fps (frames per seconds) even if lower o upper rates can also be set by the user (the upper fps limit is the complexity of scene, computer speed and graphic card hardware acceleration). However frame-rate must not be greater than k-rate.

A new type of variables has been introduced to handle frame-rate. All frame-rate variables begin with letter 't' (lowercase). So the term t-rate is exactly the same term of frame-rate (in the same way as control-rate is identical to k-rate and audio-rate is identical to a-rate).

Several opcodes operating at frame-rate have been introduced, both signal generators and modifiers, as well as opcodes that affect graphic output. Opcodes related to graphic output (and to frame-rate) can be grouped into the following categories:

1.      Graphic engine setup opcodes and opcodes related to the insertion positioning in the rendering chain.

2.      Opcodes that affect graphic output:

o        opcodes that call low-level OpenGL API functions directly,

o        mid-level graphic opcodes and opcodes that call GLU functions directly,

o        high level graphic opcodes and opcodes that call GLUT functions directly,

3.      Signal generators operating at frame-rate

4.      Signal modifier operating at frame-rate

5.      Math operators operating at frame-rate

6.      Opcodes that affect control flow

7.      Opcodes related to video files and video capture

When audio output is suppressed (with command line flag -+Y), t-rate signals are compatible with normal k-rate signals (even if they begin with different letter) but user have to understand and to keep in mind that they are updated at different rates.

init-rate variables, p-fields and constants are fully compatible with both k-rate and t-rate, even when audio output is enabled and can be mixed in expressions with t-rate (but k-rate variables cannot be mixed in expressions with t-rate variables when audio is enabled, they only can when audio is disabled).

A simple example

Notice that, when using graphics in CsoundAV, user need a hardware-accelerated display adapter that supports OpenGL. If user doesn't have this, the output will probably be extremely slow (and crashes could occurr).

HalloCube.orcis a simple example showing a rotating cube.

;***************
; HalloCube.orc
;***************
#include "OpenGL.h"
;*** include file, with a lot of OpenGL definitions. This file is
                                   
;*** distributed together with CsoundAV package
sr=100 ;*** no audio output is required
for this example, so audio rate is set to a low value
kr =100
ksmps=1
nchnls=1 ;*** this is really not necessary, but provided to appear more familiar

        GLfps   30
        GLpanel "OpenGL panel", 512, 512
        GLpanel_end
        FLrun
 
        glLineWidth 4
GLinsert_i $GL_INIT
 
        glMatrixMode ($GL_PROJECTION)
        glLoadIdentity
        glOrtho -2,2,-2,2,-2,2
        glMatrixMode ($GL_MODELVIEW)   
GLinsert_i  $GL_NOT_VALID
 
        glClear 0
GLinsert_i 1



;///////////////////////////////////////////////////
        instr   1
;///////////////////////////////////////////////////
k1      phasor  .1
k2      phasor  .1432
        glLoadIdentity
        glRotate       k1*360,1,0,0
        glRotate       k2*360,0,1,0
        glutCube       1.5
GLinsert               1.5,0
        endin
 
;*** end of orc

and the score:

;**************  
;HalloCube.sco
;**************
i1 0 3600
; *** end of score

Let’s see what the orchestra contains. The first line of code contains an #includeOpenGL.h” statement. “OpenGL.h” is a file that contains a lot of macro definitions, and is included with CsoundAV distribution. This file MUST be included each time you intend to use OpenGL related opcodes. This is necessary because a lot of OpenGL subroutines require a number to specify the actual type of action they will do. In order to help humans, there is no need to remember all the numbers, but user have only to use corresponding mnemonic macro definitions. We see some examples of using define statements in HelloCube.orc .

The orchestra header sets a very low audio rate (sr=100), because, in this first example, we don’t use audio output, but only graphics. In this case, in order to suppress audio output, and to optimize performance, you have to start CsoundAV with the -+Y flag set (a flag that enables real-time without audio output).

Almost all opcodes related to OpenGL have the following prefixes:

·         gl = OpenGL API function call

·         glu = GLU API function call

·         glut = GLUT API function call

·         GL = graphic engine managers, utility opcodes, and high-level routines related to OpenGL graphic output.

GLfps opcode sets the number of frames per second of graphic output window, and initialize the callback mechanism of graphic engine. You are not constrained to use this callback mechanism, and you can update the graphic window frames directly by calling GLredraw opcode, but in most cases you will use GLfps because it guarantees less CPU overhead and is more precise in timing.

GLpanel and GLpanel_end opcodes are similar to FLpanel and FLpanel_end, actually they create the graphic output window, but in most cases there are no other opcodes between them, differently from FLpanel and FLpanel_end.

FLrun starts both OpenGL and FLTK widget operations.

glLineWidth opcode calls corresponding OpenGL API function only once, at the INIT stage (see later), before any other OpenGL function.

GLinsert_i and GLinsert opcodes set the end of an OpenGL instruction block and insert all previous OpenGL functions belonging to the same block into a determinate position of the rendering-engine chain. Their argument is a positive number that informs the rendering-engine-insertion routine about the position where previous instruction block must be inserted. Greater numbers make the instruction block to be positioned later than blocks corresponding to smaller numbers. So the user can control the execution order of instruction blocks. Normally, the argument of GLinsert and GLinsert_i is a positive number. Numbers -1 (defined in the macro definition $GL_INIT) and 0 (or macro definition $GL_NOT_VALID) have a particular meaning: -1 inserts previous instruction block at the INIT stage, and 0 inserts previous instruction block at a special “resize” stage, i.e. a stage that is called by graphics engine only when graphic-output window is invalidated (i.e. when it is moved or resized). See reference section of GLinsert for more details.

glMatrixMode, glLoadIdentity, and glOrtho opcodes call OpenGL API functions at the INIT stage and when graphic window is invalidated (i.e. it is moved or resized).

glClear makes graphic engine to call corresponding OpenGL function every frame, at position 1 of the rendering chain (because of the subsequent statement GLinsert_i 1).

We have now terminated the description of instr 0. All OpenGL statements declared inside instr 0 (i.e. at the header position, externally to any Csound instrument) should remain active for all duration of current session. This is done by GLinsert_i opcode.

All OpenGL statements declared inside a normal Csound instrument, are active only for corresponding instrument duration, i.e. they are inserted in the rendering chain at the beginning of corresponding note, and are removed at the end of the note itself. So user can activate/deactivate OpenGL scenes by playing notes, in the same way Csound produces sounds and pauses with audio opcodes. In this simple example we have a single note with the duration of an hour.

Inside instr 1 we can see two normal k-rate generators (phasor opcodes) that output two k-rate signals used to control some parameter of OpenGL opcodes (in this case they make the cube to rotate). Notice that you should not use k-rate variables for OpenGL opcode input arguments directly, when CsoundAV is generating both graphics and audio (the reason will be explained later). But in this case we don’t generate audio, only graphics, so this limitation doesn’t apply now, and we can use k-rate signals directly to control OpenGL-related opcodes.

glLoadIdentity, glRotate and glutCube are OpenGL opcodes that are inserted at the position 1.1 of the rendering chain by GLinsert opcode (i.e. they will executed always AFTER the glClear statement).

This is enough, for now, about this simple orchestra.

control-rate and frame-rate

Perhaps the relationship between k-rate and t-rate (that is frame-rate) is the most difficult thing to understand of of CsoundAV graphics programming. But it is even one the most fundamental. You have to take it for granted that k-rate is the basic rate for audio engine and t-rate is the basic (and the only) rate for the graphic engine. k-rate MUST be greater than t-rate (this is not a real limitation, because usually frame-rate is in the order of 10-50 fps). I remember that you can set k-rate with kr=krate statement and t-rate with GLfps opcode. All OpenGL-related opcodes (i.e. all opcodes that begin with the prefixes gl, GL, glu and glut work at t-rate.

Both k-rate and frame-rate variables can begin with the letterk’ when audio is suppressed and Csound parser doesn’t complain if user uses a k-variable instead of a t-rate variable. Actually, it is absolutely OK to mix k-rate and t-rate variables when the audio output of CsoundAV is suppressed (-+Y flag) and sr is set to a low value (for example 100, as in the previous example; I remember that to suppress audio with real-time oriented orchestras CsoundAV must be called with the command line flag -+Y), however k-rate requires more CPU cycles than frame rates, because it is a higher rate. When audio is suppressed, you will anyway be warned in the case of expressions mixing k-rate with t-rate variables. But if you are using both audio and graphics, you must not confuse (or mix) t-rate variables with k-rate variables. In this case, parse errors will occurr instead of warnings (if this restriction would not be present, graphic animation would not be smooth, and it would proceed jerkily).

NOTE for experts: The reason of the prohibition of mixing t-variables with k-variables when audio is enabled, is that audio buffering mechanism stops processing when buffer is full and restores processing when buffer is half-empty. This makes k-rate signal flow not to have a regular timing inside audio engine. Frame-rate timing must be very regular instead, so if you use a k-rate to smooth signal to control motion of a graphic object, you will notice an irregular, disturbing motion. This doesn’t happen if you suppress audio, because in this case main thread engine timing is under the control of a system timer, not under the control of audio buffering mechanism. So, normally, you will use k-rate variables to directly control graphic motion only if audio output is suppressed (but you can still use MIDI out). There are many frame-rate opcodes that do similar or identical tasks with respect of corresponding k-rate opcodes. These opcodes should be used when both audio and graphics are running in parallel in the same orchestra or in frame-rate loops (see later). Some opcodes that behave like converters from k-rate to t-rate are also provided ( t(kvar), tabk2t and set_t_del, see reference section). So user could use k-rate opcodes to generate control-signals, and convert them only at the last stage, directly at the input arguments of the graphic-output opcodes operating at t-rate; however this will demand more CPU cycles.


Graphics-related opcode reference


Graphic engine setup-related

GLpanel name [, iwidth, iheight, ix, iy, iborder]
GLpanel_end

GLfps ifps [, iresolution]

GLinsert iposition
GLinsert_i iposition

GLfullscreen iflag
GLredraw ktrig        (works at k-rate not  at t-rate)

GLclearwhen trig, imask
GLwaitInitStage

GLratio iratio, iflag

DESCRIPTION

Define several setup parameters of animated graphics.

INTIALIZATION

name - double-quoted string containing the title of graphics-output window
iwidth, iheigth, ix, iy - Width, height and position of graphics-output window
iborder - border style of graphics-output window. See FLpanel or other FLTK containers for a list of possible border styles.
ifps - frames per second
iresolution - fps timing resolution. Range is 0 to 1. Zero is the finest resolution precision
iposition - position priority of previous instruction block in the OpenGL engine instruction list lo
op
iflag - a flag that modifies the behavior of corresponding opcode. Valid values are 0 or 1. See below.
imask - OpenGL parameter (see OpenGL API documentation of glClear() )
iratio - width/height ratio of the graphics displayed in OpenGL windows. A ratio of 1/1 leaves the aspect intact in normal computer screens.

FRAME-RATE PERFORMANCE

trig - trigger signal that bangs actions of corresponding opcodes at t-rate

PERFORMACE

ktrig - trigger signal that bangs actions of corresponding opcodes at k-rate

GLpanel creates an OpenGL output window. It must be followed by the opcode GLpanel_end. These opcodes are similar to FLpanel and FLpanel_end, but, at present time cannot contain any child widget. So, no opcode should be placed between GLpanel and GLpanel_end. However OpenGL output window CAN be contained by another FLTK container, by which it is considered as a normal widget. At present time ONLY ONE OpenGL window can be created in an orchestra. If you create more than one OpenGL windows, unpredictable results could occur.

GLfps opcode sets the frame-rate and activates automatic frame updating. If it is not present in an orchestra, frames can be updated by the user by means of GLredraw opcode, to achieve special effects; this is a particular case. Normally it should be present with animated graphics. It is possible to set the timing resolution, a common value of iresolution argument is 0.5

GLinsert and GLinsert_i are special opcodes that indicate the end of an OpenGL instruction block, and insert all previous OpenGL functions belonging to the same block into a determinate position of the rendering-engine chain. Their argument is a positive number that informs the engine-chain-insertion routine about the position where previous instruction block must be inserted. Greater numbers make the block to be positioned later than blocks corresponding to smaller numbers. So the user can control the execution order of instruction blocks. Normally, the argument of GLinsert and GLinsert_i is a positive number. Numbers -1 (defined in the macro definition $GL_INIT) and 0 (or macro definition $GL_NOT_VALID) have a particular meaning: the first inserts previous instruction block at the INIT stage, and the second inserts previous instruction block at a special “resizing” stage, i.e. a stage that is called by graphics engine when graphic-output window is invalidated (i.e. when it is moved or resized). Only opcodes operating at frame-rate are inserted in the engine chain. All other opocdes (i.e. k-rate and a-rate opcodes) are ignored by GLinsert and GLinsert_i, even if they are placed in between two frame-rate opcode lines.

The difference between GLinsert and GLinsert_i is in that instructions inserted with GLinsert are removed from rendering chain when the instrument containing that instruction block is switched off; whereas instructions inserted with GLinsert_i remain active for all Csound session.

GLfullscreen makes the OpenGL window to be enlarged to fit full screen size, when iflag argument is set to 1. OpenGL window can be restored to previous size when GLfullscreen is called with iflag set to zero.

GLredraw allows to “manually” update OpenGL window time ktrig argument is filled with a non-zero value. This opcode must not be used if GLfps is present in the orchestra.  GLredraw operates at k-rate not at t-rate, so, due to audio buffering issues, actual timing is not reliable. It is suggested to use GLredraw without audio enabled, or, if audio is enabled, at very low rates (max 1/2 second) otherwise animation flow will appear very irregular and choppy.

GLclearwhen opcode is similar to low-level glClear API, the difference is that it clears the screen only when trig argument assumes a non-zero value.

GLwaitInitStage blocks the execution of main Csound engine thread until init-stage of graphics engine thread has been executed. Useful in most cases, to avoid that some instruments containing OpenGL instructions are activated before some required OpenGL initializations have been done or some graphics objects have been created.

GLratio sets the width/height ratio of the graphics displayed in OpenGL windows. An iratio value of 1/1 leaves the aspect intact in normal computer screens. A iratio value greater than 1 stretches the horizontal size, whereas a value smaller than 1 shrinks it.


Low-level OpenGL API-wrapping opcodes

In current version of CsoundAV there is wrapping of most OpenGL v.1.1 API functions. This is an alphabetical list of current implemented OpenGL wrapping opcodes:

glStencilFunc

glStencilOp

glClearStencil

  • glArrayElement
  • glBegin

·         glBindTexture

·         glBlendFunc

·         glCallList

·         glClear

·         glClearColor

  • glClearStencil

·         glClipPlane

·         glColor

·         glColor3

·         glColorPointer

·         glCullFace

·         glDisable

·         glDisableClientState

  • glDrawArrays

·         glDrawBuffer

·         glDrawElements

·         glEdgeFlagPointer

·         glEnable

·         glEnableClientState

  • glEnd

·         glEndList

·         glEvalCoord1

·         glEvalCoord2

·         glEvalMesh1

·         glEvalMesh2

·         glFrontFace

·         glFrustum

·         glHint

·         glIndexPointer

·         glLight

·         glLightModel

·         glLightModelv

·         glLightv

·         glLineWidth

·         glLoadIdentity

·         glLoadMatrix

·         glLoadMatrixv

·         glMap1

·         glMap2

  • glMapGrid1
  • glMapGrid2

·         glMaterial

·         glMatrixMode

·         glMultMatrix

·         glMultMatrixv

·         glNewList

·         glNormal3

·         glNormalPointer

·         glOrtho

·         glPixelMap

·         glPixelTransfer

·         glPopMatrix

·         glPushMatrix

·         glRotate

·         glScale

·         glShadeModel

·         GLshininess

  • glStencilFunc
  • glStencilOp

·         glTexCoord2

·         glTexCoordPointer

  • glTexEnvfv

·         glTexEnvi

·         glTexGenfv

·         glTexGeni

·         glTranslate

·         glVertex3

·         glVertexPointer

Notice that:

·         Many opcodes have names similar to corresponding OpenGL wrapped functions, but not identical.

·         All CsoundAV opcodes only accept floats as arguments, whereas corresponding wrapped functions accept doubles, integers, bytes or array pointers. In these cases an internal conversion to the proper data types is done.

·         Sometimes array pointers are changed to a list of arguments corresponding to all elements of the OpenGL wrapped array, sometimes array pointers are replaced by Csound function table numbers. In the last case, Csound table is considered to be an array, and array elements are actually stored into table data space.

·         Number of arguments of CsoundAV opcodes can be different from corresponding OpenGL wrapped functions,  because of the following reasons:

1.      an eventual array pointer that is an argument of a wrapped function is extended in CsoundAV opcode to make each element to correspond to a different opcode argument.

2.      Some wrapped function arguments are removed because they are hidden internally, and set to a default value.

·         Almost all symbolic constant definitions that can be used with the wrapping opcodes are contained in the include file OpenGL.h that is provided with CsoundAV. Even if it is a text file, it should never be modified by the user. All constant definition names are the same of corresponding OpenGL API, but the values are mostly different. User should don’t be worry about this, only use the symbolic name in the proper opcode arguments, by preceding them with a ‘$’ character (that is the way Csound handles the references of macro definitions).

·         All the documentation provided here describes only the difference between the wrapping opcodes and the corresponding OpenGL wrapped function. A further documentation is provided only in special cases. In almost all cases user has to read also the documentation of the original OpenGL API functions.

There is a book, called the OpenGL Blue Book (OpenGL Reference Manual: The Official Reference Document to OpenGL, Version 1.2 or later) that contains a reference documentation. Also, an online reference of OpenGL API is placed at:

http://tc1.chemie.uni-bielefeld.de/doc/OpenGL/hp/Reference.html

I also recommend the OpenGL Red Book (OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 1.2 or later), to learn OpenGL basics. An online version of Red Book is placed at:

http://fly.cc.fer.hr/~unreal/theredbook/

Both books are surely not easy to understand for non-programmers (and even for programmers with no experience of 3D graphics). If user doesn't understand these books, I suggest to start with the csd examples provided with CsoundAV and eventually attempt to modify them with a trial/error method. There is also an easier book about OpenGL programming, titled “OpenGL SuperBible, second edition” but it covers OpenGL topics only partially, and is mainly Windows oriented. However, there are a lot of OpenGL tutorials spread on the Internet. The following links could be useful:

The Official OpenGL Site - News, downloads, tutorials, books & links:-

http://www.opengl.org

The OpenGL Repository - Downloads for OpenGL implementations:-

http://www.fortunecity.com/skyscraper/nuclear/274/

The EFnet OpenGL FAQ:-

http://www.geocities.com/SiliconValley/Park/5625/opengl/

Information on the GLUT API:-

http://www.opengl.org/developers/documentation/glut.html

The Mesa 3-D graphics library:-

http://www.mesa3d.org

SGI OpenGL Sample Implementation (downloadable source):-

http://oss.sgi.com/projects/ogl-sample/

Some nice OpenGL tutorials for beginners:-

http://nehe.gamedev.net/

Nate Robins OpenGL Page (some tutorials and code)

http://www.xmission.com/~nate/opengl.html

The GLSetup project page:-

http://www.glsetup.com/

OpenGL Usenet groups:-

news:comp.graphics.api.opengl

Follows a list of the group of functions. Many OpenGL API are missing at present time. These ones are indicated with “not implemented yet”.


Vertex-related 1

glBegin tmode
glEnd

glColor tred, tgreen, tblue, talpha
glColor3 tred, tgreen, tblue

glColorMaterial ----- not implemented yet -----
glEdgeFlag* ----- not implemented yet -----

glFrontFace imode

glIndex ----- not implemented yet -----

glLight ilight, ipname, tparam
glLightv ilight, ipname, tparam0, tparam1, tparam2, tparam3
glLightModel ipname, tparam
glLightModelv ipname, tparam0, tparam1, tparam2, tparam3

glLoadIdentity
glLoadMatrix
t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15
glLoadMatrixv imatrixFunc
glMatrixMode tmode
glMultMatrix t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15
glMultMatrixv imatrixFunc
glPushMatrix
glPopMatrix

DESCRIPTION

glBegin and glEnd are the wrapping opcodes of
void glBegin(GLenum mode) and
void glEnd(void) OpenGL API functions

glColor and glColor3 are the wrapping opcodes of
void glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) and
void glColor3f (GLfloat red, GLfloat green, GLfloat blue) OpenGL API functions

glFrontFace is the wrapping opcode of
void glFrontFace(GLenum mode) OpenGL API function

glLight and glLightv are the wrapping opcodes of
void glLightf(GLenum light, GLenum pname, GLfloat param) and
void glLightfv(GLenum light, GLenum pname, const GLfloat *params) OpenGL API functions.
Note that, in glLightv opcode, original GLfloat *params array pointer is turned into its four elements tparam0, tparam1, tparam2, tparam3

glLightModel and glLightModelv are the wrapping opcodes of
void glLightModelf(GLenum pname, GLfloat param) and
void glLightModelfv(GLenum pname, const GLfloat *params) OpenGL API functions.
Note that, in glLightModelv opcode, original GLfloat *params array pointer is turned into its four elements tparam0, tparam1, tparam2, tparam3

glLoadIdentity, glLoadMatrix, glLoadMatrixv, glMatrixMode, glMultMatrix, glMultMatrixv, glPushMatrix and glPopMatrix are the wrapping opcodes of
void glLoadIdentity(void),
void glLoadMatrixf(const GLfloat *m),
void glMatrixMode(GLenum mode),
void glMultMatrixf(const GLfloat *m),
void glPushMatrix(void)
and
void glPopMatrix(void) OpenGL API functions.
Note that, in glLoadMatrix and glMultMatrix opcodes, original GLfloat *m array pointer is turned into its 16 elements t0, t1, ..., t15; and that, in glLoadMatrixv and glMultMatrixv opcodes, original GLfloat *m array pointer is turned into the Csound table number imatrixFunc

 


Vertex-related 2

glMaterial tpname, tred, tgreen, tblue, talpha
Glshininess tparam

glNormal3 tnx, tny, tnz

glRasterPos* ----- not implemented yet -----
glRect* ----- not implemented yet -----

glRotate tangle, tx, ty, tz
glScale tx, ty, tz
glTranslate tx, ty, tz

glShadeModel tmode

glTexCoord1 ----- not implemented yet -----
glTexCoord2 ts, tt
glTexCoord3 ----- not implemented yet -----
glTexCoord4 ----- not implemented yet -----

glTexGeni icoord, tparam
glTexGenfv icoord, ipname, tparam0, tparam1, tparam2, tparam3

glVertex1 ----- not implemented yet -----
glVertex2 ----- not implemented yet -----

glVertex3 tx, ty, tz
glVertex4 ----- not implemented yet -----

DESCRIPTION

glMaterial is the wrapping opcode of
void glMaterialfv (GLenum face, GLenum pname, const GLfloat *params) OpenGL API function.
Note that original GLfloat *params array pointer is turned into four elements tred, tgreen, tblue, talpha, and the original argument GLenum face is set to GL_FRONT default value.

Glshininess is the wrapping opcode of
void glMaterialf (GLenum face, GLenum pname, GLfloat param) OpenGL API function.
Note that original argument GLenum face is set to GL_FRONT_AND_BACK default value, and the original argument GLenum pname is set to GL_SHININESS default value.

glNormal3 is the wrapping opcode of
void glNormal3f (GLfloat nx, GLfloat ny, GLfloat nz) OpenGL API function.
glRotate, glScale and glTranslate are the wrapping opcodes of
void glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)

void glScalef (GLfloat x, GLfloat y, GLfloat z) and

void glTranslatef (GLfloat x, GLfloat y, GLfloat z) OpenGL API functions.
glShadeModel is the wrapping opcode of
void glShadeModel (GLenum mode) OpenGL API function.

glTexCoord2 is the wrapping opcode of
void glTexCoord2f (GLfloat s, GLfloat t) OpenGL API function.

glTexGeni and glTexGeni are the wrapping opcodes of
void glTexGeni (GLenum coord, GLenum pname, GLint param) and
void glTexGenfv (GLenum coord, GLenum pname, GLfloat *params) OpenGL API functions.

Note that, in glTexGeni opcode, original argument GLenum pname is set to GL_TEXTURE_GEN_MODE default value, and that, in glTexGenfv opcode, original GLfloat *params array pointer is spliced into its four elements tparam0, tparam1, tparam2, tparam3

glVertex3 is the wrapping opcode of
void glVertex3f (GLfloat x, GLfloat y, GLfloat z) OpenGL API function.


Primitives

glBitmap ----- not implemented yet -----

glClipPlane iplane, tcoeff1, tcoeff2, tcoeff3, tcoeff4
glCullFace tmode

glDepthRange ----- not implemented yet -----
glDrawPixels ----- not implemented yet -----
glFog ----- not implemented yet -----

glFrontFace tmode

glFrustum tleft, tright, tbottom, ttop, tznear, tzfar
glOrtho tleft, tright, tbottom, ttop, tnear, tfar

glLineStipple ----- not implemented yet -----
glLineWidth twidth

glPixelMap imap, imapsize, ifn_values

glPixelStore* ----- not implemented yet -----

glPixelTransfer ipname, tparam

glPixelZoom ----- not implemented yet -----
glPointSize ----- not implemented yet -----
glPolygonMode ----- not implemented yet -----
glPolygonStipple ----- not implemented yet -----
glRasterPos* ----- not implemented yet -----
glViewport ----- not implemented yet -----

glClearColor tred, tgreen, tblue, talpha

glDrawBuffer imode

glReadBuffer ----- not implemented yet -----

DESCRIPTION

glClipPlane is the wrapping opcode of
void glClipPlane (GLenum plane, GLdouble *equation) OpenGL API function.

Note that original GLdouble *equation array pointer is turned into four elements tcoeff1, tcoeff2, tcoeff3, tcoeff4

glCullFace and glFrontFace are the wrapping opcodes of
void glCullFace (GLenum mode) and
void glFrontFace (GLenum mode) OpenGL API functions.

glFrustum is the wrapping opcode of
void glFrustum (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar) OpenGL API function.
glOrtho is the wrapping opcode of
void glOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar) OpenGL API function.

glLineWidth is the wrapping opcode of
void glLineWidth (GLfloat width) OpenGL API function.

glPixelMap is the wrapping opcode of
void glPixelMapfv (GLenum map, GLsizei mapsize, const GLfloat *values) OpenGL API function.
Note that original GLfloat *values array pointer is turned into the Csound table number ifn_values

glClearColor is the wrapping opcode of
void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) OpenGL API function.

glDrawBuffer is the wrapping opcode of
void glDrawBuffer (GLenum mode) OpenGL API function.


Fragments

glAlphaFunc ----- not implemented yet -----
glBlendFunc tsfactor, tdfactor
glDepthFunc ----- not implemented yet -----
glLogicOp ----- not implemented yet -----
glScissor ----- not implemented yet -----
glStencilFunc  tfunc, tref, tmask
glStencilOp  tfail, tzfail, tzpass
glClearStencil ts

DESCRIPTION

glBlendFunc is the wrapping opcode of
void glBlendFunc (GLenum sfactor, GLenum dfactor) OpenGL API function.

glStencilFunc is the wrapping opcode of
void glStencilFunc( GLenum func, GLint ref, GLuint mask )

glStencilOp is the wrapping opcode of
void glStencilOp( GLenum fail, GLenum zfail, GLenum zpass )

glClearStencil is the wrapping opcode of
void glClearStencil( GLint s )


Texture mapping

glBindTexture tTexHandle

glTexCoord2 ts, tt
glTexCoord3 ----- not implemented yet -----
glTexCoord4 ----- not implemented yet -----

glTexGeni icoord, tparam
glTexGenfv icoord, ipname, tcoeffx, tcoeffy, tcoeffz, tcoeffw

glTexEnvi tparam
glTexEnvfv tred, tgreen, tblue, talpha

glTexImage1D ----- not implemented yet -----
glTexImage2D ----- not implemented yet -----

glTexParameter* ----- not implemented yet -----

DESCRIPTION

glBindTexture is the wrapping opcode of
void glBindTexture (GLenum target, GLuint texture) OpenGL API function.
Note that original argument GLenum target is set to GL_TEXTURE_2D default value

glTexCoord2 is the wrapping opcode of
void glTexCoord2f (GLfloat s, GLfloat t) OpenGL API function.
glTexGen and glTexGenfv are the wrapping opcodes of
void glTexGeni (GLenum coord, GLenum pname, GLint param) and
void glTexGenfv (GLenum coord, GLenum pname, GLfloat *params) OpenGL API functions.

Note that, in glTexGeni opcode, original argument GLenum pname is set to GL_TEXTURE_GEN_MODE default value. Furthermore, original GLfloat *params array pointer is turned into the four elements tcoeffx, tcoeffy, tcoeffz, tcoeffw in glTexGenfv opcode.

glTexEnvi and glTexEnvfv are the wrapping opcodes of
void glTexEnvi (GLenum target, GLenum pname, GLint param) and
void glTexEnvfv (GLenum target, GLenum pname, GLfloat *params) OpenGL API functions.

Note that original argument GLenum target is set to GL_TEXTURE_ENV default value and original argument GLenum pname is set to GL_TEXTURE_ENV_MODE in glTexEnvi opcode, and to GL_TEXTURE_ENV_COLOR in glTexEnvfv opcode. Furthermore, original GLfloat *params array pointer is turned into four elements tred, tgreen, tblue, talpha in glTexEnvfv opcode.


Evaluators

glEvalCoord1 tu
glEvalCoord2 tu, tv

glEvalMesh1 tmode, ti1, ti2
glEvalMesh2 tmode, ti1, ti2, tj1, tj2

glEvalPoint ----- not implemented yet -----

glMap1 itarget, iu1, iu2, iustride, iuorder, ifn_points
glMap2 itarget, iu1, iu2, iustride, iuorder, iv1, iv2, ivstride, ivorder, ifn_points

glMapGrid1 tun, tu1, tu2
glMapGrid2 tun, tu1, tu2, tvn, tv1, tv2

DESCRIPTION

glEvalCoord1 and glEvalCoord2 are the wrapping opcodes of
void glEvalCoord1f (GLfloat u) and
void glEvalCoord2f (GLfloat u, GLfloat v) OpenGL API functions.

glEvalMesh1 and glEvalMesh2 are the wrapping opcodes of
void glEvalMesh1 (GLenum mode, GLint i1, GLint i2) and
void glEvalMesh2 (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2) OpenGL API functions.

glMap1 and glMap2 are the wrapping opcodes of
void glMap1f (GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, GLfloat *points) and

void glMap2f (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat *points) OpenGL API functions.
Note that original GLfloat *points array pointer is turned into Csound table number ifn_points.

glMapGrid1 and glMapGrid2 are the wrapping opcodes of
void glMapGrid1f (GLint un, GLfloat u1, GLfloat u2) and
void glMapGrid2f (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2) OpenGL API functions.


Selection and Feedback

glRenderMode ----- not implemented yet -----
glInitNames ----- not implemented yet -----
glLoadName ----- not implemented yet -----
glPopName ----- not implemented yet -----
glPushName ----- not implemented yet -----
glSelectBuffer ----- not implemented yet -----
gluPickMatrix ----- not implemented yet -----
glFeedbackBuffer ----- not implemented yet -----
glPassThrough ----- not implemented yet -----


Display Lists

glCallList ilist
glCallLists ----- not implemented yet -----
glDeleteLists ----- not implemented yet -----

glEndList
glGenLists ----- not implemented yet -----
glIsLis ----- not implemented yet -----
glListBase ----- not implemented yet -----

ilist glNewList

DESCRIPTION

glCallList is the wrapping opcode of
void glCallList (GLuint list) OpenGL API function.

glEndList is the wrapping opcode of
void glEndList (void) OpenGL API function.

glNewList is the wrapping opcode of
void glNewList (GLuint list, GLenum mode) OpenGL API function. The first input argument is generated internally by calling glGenLists(1) and the OpenGL function is called by setting mode to GL_COMPILE.  It returns the list object (an integer number to be used as list handle).

 


Vertex arrays

glArrayElement tindex
glDrawArrays tmode, tfirst, tcount

glVertexPointer istride, ioffset, itable
glNormalPointer istride, ioffset, itable
glColorPointer istride, ioffset, itable
glIndexPointer istride, ioffset, itable
glTexCoordPointer istride, ioffset, itable
glEdgeFlagPointer istride, ioffset, itable

glGetPointerv ----- not implemented yet -----
glDrawElements tmode, icount, ifn

glInterleavedArrays ----- not implemented yet -----

glEnableClientState iarray
glDisableClientState iarray

DESCRIPTION

N.B. In many of these opcodes there is the additional argument ioffset, that defines the first element to read in the corresponding Csound table.

glArrayElement is the wrapping opcode of
void glArrayElement (GLint i) OpenGL API function.

glDrawArrays is the wrapping opcode of
void glDrawArrays (GLenum mode, GLint first, GLsizei count) OpenGL API function.

glVertexPointer is the wrapping opcode of
void glVertexPointer (GLint size, GLenum type, GLsizei stride, GLvoid *pointer) OpenGL API function.
Notice that original GLint size argument is set to 3, GLenum type is set to GL_FLOAT, and GLvoid *pointer array pointer is turned into Csound table number itable.

glNormalPointer is the wrapping opcode of
void glNormalPointer (GLenum type, GLsizei stride, GLvoid *pointer) OpenGL API function.
Notice that original GLenum type argument is set to GL_FLOAT and GLvoid *pointer array pointer is turned into Csound table number itable

glColorPointer is the wrapping opcode of
void glColorPointer (GLint size, GLenum type, GLsizei stride, GLvoid *pointer) OpenGL API function.
Notice that original GLint size argument is set to 3, GLenum type argument is set to GL_FLOAT, and GLvoid *pointer array pointer is turned into Csound table number itable

glIndexPointer is the wrapping opcode of
void glIndexPointer (GLenum type, GLsizei stride, GLvoid *pointer) OpenGL API function.
Notice that original GLenum type argument is set to GL_FLOAT, and GLvoid *pointer array pointer is turned into Csound table number itable

glTexCoordPointer is the wrapping opcode of
void glTexCoordPointer (GLint size, GLenum type, GLsizei stride, GLvoid *pointer) OpenGL API function.
Notice that original GLint size argument is set to 2, GLenum type argument is set to GL_FLOAT, and GLvoid *pointer array pointer is turned into Csound table number itable

glEdgeFlagPointer is the wrapping opcode of
void glEdgeFlagPointer (GLsizei stride, GLvoid *pointer) OpenGL API function.
Notice that GLvoid *pointer array pointer is turned into Csound table number itable

glDrawElements is the wrapping opcode of
void glDrawElements (GLenum mode, GLsizei count, GLenum type, GLvoid *indices) OpenGL API function.
Notice that original GLenum type argument is set to GL_FLOAT, and GLvoid *indices array pointer is turned into Csound table number ifn

glEnableClientState and glDisableClientState are the wrapping opcodes of
void glEnableClientState (GLenum array) and
void glDisableClientState (GLenum array) OpenGL API functions.

 


Modes and Execution Reference

glEnable icap
glDisable icap

glFinish ----- not implemented yet -----
glFlush ----- not implemented yet -----

glHint itarget, imode

glIsEnabled ----- not implemented yet -----

DESCRIPTION

glEnable and glDisable are the wrapping opcodes of
void glEnable (GLenum cap) and
void glDisable (GLenum cap) OpenGL API functions.

glHint is the wrapping opcode of

void glHint (GLenum target, GLenum mode) OpenGL API function.

 


State Information

glGet ----- not implemented yet -----
glGetBooleanv ----- not implemented yet -----
glGetClipPlane ----- not implemented yet -----
glGetDoublev ----- not implemented yet -----
glGetError ----- not implemented yet -----
glGetFloatv ----- not implemented yet -----
glGetIntegerv ----- not implemented yet -----
glIsEnabled ----- not implemented yet -----
glGetLight ----- not implemented yet -----

glGetMap ----- not implemented yet -----
glGetMaterial ----- not implemented yet -----
glGetPixelMap ----- not implemented yet -----
glGetPolygonStipple ----- not implemented yet -----
glGetString ----- not implemented yet -----
glGetTexEnv ----- not implemented yet -----
glGetTexGen ----- not implemented yet -----
glGetTexImage ----- not implemented yet -----
glGetTexLevelParameter ----- not implemented yet -----
glGetTexParameter ----- not implemented yet -----
glPopAttrib ----- not implemented yet -----
glPushAttrib ----- not implemented yet -----



Middle-level and GLU-related Opcodes


Persepctive and Point of View (trasforming coordinates)

gluPerspective tfovy, tzNear, tzFar

gluLookAt teyex, teyey, teyez, tcenterx, tcentery, tcenterz, tupx, tupy, tupz

gluOrtho2D ----- not implemented yet -----

DESCRIPTION

gluPerspective is the wrapping opcode of
void gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) GLU library function.
Notice that original GLdouble aspect argument is set externally, by means GLratio opcode.

GluLookAt is the wrapping opcode of
void gluLookAt (GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz) GLU library function.

 


Simple Quadric Surfaces

ihandle gluNewQuadric [iflag]

gluSphere ihandle, tradius, tslices, tstacts
gluCylinder ihandle, tBaseRadius, tTopRadius, theight, tslices, tstacks
gluDisk ihandle, tInnerRadius, tOuterRadius, tslices, tloops;

gluQuadricDrawStyle ihandle, tDrawStyle

gluQuadricNormals ihandle, tnormals
gluQuadricTexture ihandle, tTextureCoords

DESCRIPTION

gluNewQuadric is the wrapping opcode of
GLUquadric* gluNewQuadric (void) GLU library function.
Notice that gluNewQuadric opcode not only wraps gluNewQuadric( ) function, but also
void gluQuadricOrientation (GLUquadric *quadObject, GLenum orientation) GLU library function.
If optional argument iflag is set to a nonzero value, quadric orientation will be set to GLU_OUTSIDE, else, if this argument is missing, orientation is set to GLU_INSIDE by default.
gluNewQuadric opcode creates a quadric object and returns an identifier (ihandle argument, that is an integer number) that identifies such object and can be used by further quadric opcodes. The quadric object just created is automatically destroyed at the end of a CsoundAV session.

gluSphere is the wrapping opcode of
void gluSphere (GLUquadric *qobj, GLdouble radius, GLint slices, GLint stacks) GLU library function.
Notice that original quadric object pointer GLUquadric *qobj is replaced by ihandle identifier generated by gluNewQuadric opcode.

gluCylinder is the wrapping opcode of
void gluCylinder (GLUquadric *qobj, GLdouble baseRadius, GLdouble topRadius, GLdouble height, GLint slices, GLint stacks) GLU library function. Notice that original quadric object pointer GLUquadric *qobj is replaced by ihandle identifier generated by gluNewQuadric opcode.

gluDisk is the wrapping opcode of
void gluDisk (GLUquadric *qobj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint loops) GLU library function. Notice that original quadric object pointer GLUquadric *qobj is replaced by ihandle identifier generated by gluNewQuadric opcode.

gluQuadricDrawStyle is the wrapping opcode of
void gluQuadricDrawStyle (GLUquadric *quadObject, GLenum drawStyle) GLU library function.
Notice that original quadric object pointer GLUquadric *qobj is replaced by ihandle identifier generated by gluNewQuadric opcode.

gluQuadricNormals is the wrapping opcode of
void gluQuadricNormals (GLUquadric *quadObject, GLenum normals); GLU library function.
Notice that original quadric object pointer GLUquadric *qobj is replaced by ihandle identifier generated by gluNewQuadric opcode.

gluQuadricTexture is the wrapping opcode of
void gluQuadricTexture (GLUquadric *quadObject, GLboolean textureCoords) GLU library function.
Notice that original quadric object pointer GLUquadric *qobj is replaced by ihandle identifier generated by gluNewQuadric opcode.

 


Polygon tessellation

gluTessBeginPolygon
gluTessEndPolygon

gluTessBeginContour
gluTessEndContour

gluTessVertex tx, ty, tz
gluTessVertexv ifn, tindex

DESCRIPTION

gluTessBeginPolygon is the wrapping opcode of
void gluTessBeginPolygon (GLUtesselator *tess, void *polygon_data ) GLU library function.
Notice that gluTessBeginPolygon opcode not only wraps gluTessBeginPolygon( ) function, but also
GLUtesselator* gluNewTess (void) and
void gluTessCallback (GLUtesselator *tess, GLenum which, void (CALLBACK *fn)( )) GLU library functions.
Internally, gluNewTess( ) creates a hidden tessellator object that is used by subsequent tessellation opcodes. gluTessCallback( ) is internally called for three times with the following which arguments and (*fn)( ) function-pointers:
GLU_BEGIN with glBegin( ),
GLU_VERTEX with glVertex3dv( )
GLU_END with glEnd( )
The hidden tessellator object is automatically destroyed by gluTessEndPolygon opcode (see below).

gluTessEndPolygon is the wrapping opcode of
void gluTessEndPolygon (GLUtesselator *tess) GLU library function.
Notice that gluTessEndPolygon opcode not only wraps gluTessEndPolygon( ) function, but also
void gluDeleteTess (GLUtesselator *tess)
Inter
nally, gluDeleteTess( ) deletes corresponding tessellator object.

gluTessBeginContour and gluTessEndContour are the wrapping opcodes of
void gluTessBeginContour (GLUtesselator *tess) and
void gluTessEndContour (GLUtesselator *tess ) GLU library functions.
Notice that GLUtesselator *tess object pointer is not visible externally, so these opocdes have no arguments.

gluTessVertex is the wrapping opcode of
void gluTessVertex (GLUtesselator *tess, GLdouble coords[3], void *data ) GLU library function
Notice that original arguments GLUtesselator *tess and void *data are passed internally and are invisible. Actually the only arguments present in gluTessVertex opcode are the coords[3] array that is changed into its three elements tx, ty and tz
gl
uTessVertexv is also a wrapping opcode of gluTessVertex( ) GLU library function, but in this case the three elements of the coords[3] array are stored into ifn Csound table. tindex argument sets an offset in the table, so the first element of coords[3] array can be associated to an element of ifn table different from the first.

 


NURBS Curves

ihandle gluNewNurbsRenderer

gluBeginCurve ihandle
gluEndCurve ihandle

gluBeginSurface ihandle
gluEndSurface ihandle

gluBeginTrim ihandle
gluEndTrim ihandle

gluNurbsCurve ihandle, inknots, ifn_knot, istride, ifn_ctlarray, iorder, itype
gluNurbsSurface ihandle, isknot_count, ifn_sknot, itknot_count, ifn_tknot, is_stride, it_stride, ifn_ctlarray, isorder, itorder, itype;

gluNurbsProperty ihandle, iproperty, tvalue
gluPwlCurve ihandle, icount, ifn_array, istride, itype

gluNurbsCallback ----- not implemented yet -----

DESCRIPTION

gluNewNurbsRenderer is the wrapping opcode of
GLUnurbs* gluNewNurbsRenderer (void) GLU library function.
Notice that gluNewQuadric opcode creates a NURBS object and returns an identifier (ihandle argument, that is an integer number) that identifies such object and can be used by further NURBS-related opcodes. The NURBS object just created is automatically destroyed at the end of a CsoundAV session.

gluBeginCurve and gluEndCurve are the wrapping opcodes of
void gluBeginCurve (GLUnurbs *nobj) and
void gluEndCurve (GLUnurbs *nobj) GLU library functions.
Notice that original NURBS object pointer GLUnurbs *nobj is replaced by ihandle identifier generated by gluNewNurbsRenderer opcode.

gluBeginSurface and gluEndSurface are the wrapping opcodes of
void gluBeginSurface (GLUnurbs *nobj) and
void gluEndSurface (GLUnurbs *nobj) GLU library functions.
Notice that original NURBS object pointer GLUnurbs *nobj is replaced by ihandle identifier generated by gluNewNurbsRenderer opcode.

gluBeginTrim and gluBeginTrim are the wrapping opcodes of
void gluBeginTrim (GLUnurbs *nobj) and
void gluEndTrim (GLUnurbs *nobj) GLU library functions.
Notice that original NURBS object pointer GLUnurbs *nobj is replaced by ihandle identifier generated by gluNewNurbsRenderer opcode.

gluNurbsCurve is the wrapping opcode of
void gluNurbsCurve (GLUnurbs *nobj, GLint nknots, GLfloat *knot, GLint stride, GLfloat *ctlarray, GLint order GLenum type) GLU library function.
Notice that original NURBS object pointer GLUnurbs *nobj is replaced by ihandle identifier generated by gluNewNurbsRenderer opcode. Also, GLfloat *knot array pointer is changed into table number ifn_knot, and GLfloat *ctlarray array pointer is changed into table number ifn_ctlarray

gluNurbsSurface is the wrapping opcode of
void gluNurbsSurface(GLUnurbs *nobj, GLint sknot_count, float *sknot, GLint tknot_count, GLfloat *tknot, GLint s_stride, GLint t_stride, GLfloat *ctlarray, GLint sorder, GLint torder, GLenum type) GLU library function.
Notice that original NURBS object pointer GLUnurbs *nobj is replaced by ihandle identifier generated by gluNewNurbsRenderer opcode. Also, GLfloat *sknot array pointer is changed into table number ifn_sknot, GLfloat *tknot array pointer is changed into table number ifn_tknot, and GLfloat *ctlarray array pointer is changed into table number ifn_ctlarray

gluNurbsProperty is the wrapping opcode of
void gluNurbsProperty (GLUnurbs *nobj, GLenum property, GLfloat value ) GLU library function.
Notice that original NURBS object pointer GLUnurbs *nobj is replaced by ihandle identifier generated by gluNewNurbsRenderer opcode.

gluPwlCurve is the wrapping opcode of
void gluPwlCurve (GLUnurbs *nobj, GLint count, GLfloat *array, GLint stride, GLenum type); GLU library function. Notice that original NURBS object pointer GLUnurbs *nobj is replaced by ihandle identifier generated by gluNewNurbsRenderer opcode. Also, GLfloat *array pointer is changed into table number ifn_array.



High-level OpenGL opcodes


GLUT shapes

glutSphere tradius, tslices, tstacts, itype
glutTorus tinnerRadius, touterRadius, tsides, trings, itype
glutCube tsize, itype
glutDodecahedron itype
glutOctahedron itype
glutTetrahedron itype
glutIcosahedron itype

DESCRIPTION

These 3D shapes wrapped opcodes from GLUT library API. Original GLUT API separates wireframe rendering and solid rendering into two different functions, whereas under CsoundAV both are wrapped into a single opcode, by providing the itype argument to allow the user to choose solid (if itype is set to a nonzero value) or wireframe (if itype is set to zero) rendering.

glutSphere is the wrapping opcode of
void glutWireSphere(GLdouble radius, GLint slices, GLint stacks) and
void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks) GLUT library functions.

glutTorus is the wrapping opcode of
void glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings) and
void glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings) GLUT library functions.

glutCube is the wrapping opcode of
void glutWireCube(GLdouble size) and
void glutSolidCube(GLdouble size) GLUT library functions.

glutDodecahedron is the wrapping opcode of
void glutWireDodecahedron( ) and
void glutSolidDodecahedron( ) GLUT library functions.

glutOctahedron is the wrapping opcode of
void glutWireOctahedron( ) and
void glutSolidOctahedron( )
GLUT library functions.

glutTetrahedron is the wrapping opcode of
void glutWireTetrahedron( )and
void glutSolidTetrahedron( ) GLUT library functions.

glutIcosahedron is the wrapping opcode of
void glutWireIcosahedron( ) and
void glutSolidIcosahedron( ) GLUT library functions.


3D Models

iDispList GLwavefrontModel “filename”, imode, ismooth_angle, itexture_type, iwireframe

ihandle GL3dStudioModel ----- not implemented yet -----
GLrender3dStudioModel ----- not implemented yet -----

iHandle, iNumPieces GLloadPicasso “filename”
GLrenderPicasso tHandle, tmode, tp1, tr1, tg1, tb1, ta1 [, tp2, tr2, tg2, tb2, ta2, ... , tpN, trN, tgN, tbN, taN]

DESCRIPTION

These opcodes load and render 3D models in various formats. Some opcodes create a display list that can be called to draw the model, other opcodes have their own rendering engine.

INITIALIZATION

iDispList - generated display list handle
“filename”
- a double-quoted string that contains the file name of the model
imode - rendering mode (see below)
ismooth_angle - weight of vertex normals vs. facet normals. A higher value smoothes vertex angles progressively.
itexture_type - if the 3D object to load has not texture coordinates, they will be automatically generated according the following values of this argument :
0) no texture coordinates
1) linear texture coords
2) sphere map texture coords
iwireframe - if this argument is set to zero model will be rendered in solid mode, else in wireframe mode
iHandle - generated 3D object handle
iNumPieces - number of sub-objects that make up the 3D object

FRAME-RATE PERFORMACE

tHandle - handle of the 3D object
tmode - Rendering mode. Can be set to one of the following macro definitions:
$GL_POINTS, $GL_LINES, $GL_LINE_LOOP, $GL_LINE_STRIP, $GL_TRIANGLES, $GL_TRIANGLE_STRIP, $GL_TRIANGLE_FAN, $GL_QUADS, $GL_QUAD_STRIP, $GL_POLYGON
tp1, tp2,...,tpN - dynamic parameters
tr1, tg1, tb1, ta1,...,trN, tgN, tbN, taN - RGBA components of colors of each sub-object of the model

GLwavefrontModel opcode loads an Alias-Wavefront format model and builds a display list that can be called to render it. imode input argument can set rendering mode to the following flags expressed by means of symbolic macro definitions:
$GLM_NONE - render with vertices only
$GLM_FLAT - render with facet normals
$GLM_SMOOTH - render with vertex normals
$GLM_TEXTURE - render with texture coords
$GLM_COLOR - render with colors (color material)
$GLM_MATERIAL - render with materials

More than one flag can be set at the same time by summing them. $GLM_COLOR and $GLM_MATERIAL should not be specified at the same time.
GLwavefrontModel should be called only once per session, at the header section of the orchestra. Object is automatically destroyed at the end of a CsoundAV session.

GLloadPicasso and GLrenderPicasso load and render dynamic Picassian women objects created by Prof. Celestino Soddu.


Texture Mapping Related

iTexHandle GLloadTexture “filename”, itrans, iwrapst [, imipmaps, iminmagfilt]
iwidth, iheigth, idepth GLtexInfo iTexHandle

GLtexSquare tsize, tcoord1s, tcoord1t, tcoord2s, tcoord2t, tcoord3s, tcoord3t, tcoord4s, tcoord4t
GLtexCube tsize, tcoord1s, tcoord1t, tcoor
d2s, tcoord2t, tcoord3s, tcoord3t, tcoord4s, tcoord4t
GLtexCircle tradius, islices, tcoord1s, tcoord1t, tzooms, tzoomt

DESCRIPTION

Load an image file and create a texture object. Render some shapes providing user control of texture-mapping coordinates.

INITIALIZATION

iTexHandle - handle to texture object just created

“filename” - a double-quoted string that contains the file name of the RGBA image. Only PNG files are supported at present time.
itrans - transparency setting when loading a PNG file
. It can be one of the following:
       $PNG_ALPHA - to use alpha channel in PNG file, if there is one
       $PNG_SOLID - for no transparen
cy
       $PNG_STENCIL - to set pixels of a certain value to alpha 0, otherwise 1
       $PNG_BLEND1 - to set alpha to r+g+b
       $PNG_BLEND2 - to set alpha to (r+g+b)/2
       $PNG_BLEND3 - to set alpha to (r+g+b)/3
       $PNG_BLEND4 - to set alpha to r2+g2+b2
       $PNG_BLEND5 - to set alpha to (r2+g2+b2)/2
       $PNG_BLEND6 - to set alpha to (r2+g2+b2)/3
       $PNG_BLEND7 - to set alpha to (r2+g2+b2)/4
       $PNG_BLEND8 - to set alpha to (r2+g2+b2)/4

iwrapst - can be set to $GL_CLAMP or $GL_REPEAT to be used internally by glTexParameteri( ) API function

imipmaps -  (optional) can be set to:
       $PNG_BUILDMIPMAPS - in this case mipmaps are build and the texture uses them
       $PNG_NOMIPMAPS - no mipmaps are used
       $PNG_SIMPLEMIPMAPS - a simplified set of mipmaps are built and used
The default value of imipmaps is $PNG_BUILDMIPMAPS.

iminmagfilt - (optional) can be set to:
       $GL_LINEAR_MIPMAP_NEAREST - uses mipmaps without iterpolation and linearly interpolates between pixels
       $GL_NEAREST_MIPMAP_NEAREST - uses mipmaps without interpolation
       $GL_NEAREST_MIPMAP_LINEAR - does't interpolates between pixels but interpolates between mipmaps
       $GL_LINEAR_MIPMAP_LINEAR - interpolates both between pixels and between mipmaps
       $GL_LINEAR - doesn't use mipmaps but interpolates between pixels
       $GL_NEAREST - doesn't use mimaps and doesn't interpolate
The default value of iminmagfilt is  $GL_LINEAR_MIPMAP_NEAREST.

iwidth - width, in pixels, of the original image
iheigth - height, in pixels, of the original image.
idepth - depth, in bit per pixels, of the original image

islices - number of slices of circle tessellation

FRAME-RATE PERFORMANCE

GLtexSquare tsize, tcoord1s, tcoord1t, tcoord2s, tcoord2t, tcoord3s, tcoord3t, tcoord4s, tcoord4t
GLtexCube tsize, tcoord1s, tcoord1t, tcoor
d2s, tcoord2t, tcoord3s, tcoord3t, tcoord4s, tcoord4t

tsize - size. In GLtexSquare and GLtexCube size is the X, Y and Z distance from origin. Since both GLtexSquare and GLtexCube draw centered objects, the actual size of an edge of a square or cube is 2 * tsize.
tcoord1s, tcoord1t,
tcoord2s, tcoord2t, tcoord3s, tcoord3t, tcoord4s, tcoord4t - texture coordinates
tradius - circle radius
tzooms, tzoomt - texture-mapping zoom factors

GLloadTexture loads a PNG image and converts it into a texture object that can be used later by accessing iTexHandle argument with glBindTexture opcode. It should be called only once per session, at the header section of the orchestra. Object is automatically destroyed at the end of a CsoundAV session.

GLtexSquare tsize, tcoord1s, tcoord1t, tcoord2s, tcoord2t, tcoord3s, tcoord3t, tcoord4s, tcoord4t

GLtexSquare renders a square and allows to set and vary texture-mapping coordinates.
The coordinates are ordered in the following way:
              coord1s, tcoord1t - refer to the left lower vertex of the square;
              tcoord2s, tcoord2t - refer to the left-upper vertex;
              tcoord3s, tcoord3t - refer to the rigth-upper vertex;
              tcoord4s, tcoord4t - refer to the rigth-lower vertex of the square;

GLtexCube renders a cube and allows to set and vary texture-mapping coordinates

GLtexCircle renders a circle and allows to set and vary texture-mapping coordinates. Notice that, in order to obtain a circle, islices argument should be set to a number near 100. 100 is actually the maximum number of slices allowed. However, any kind of regular polygons, starting from equilateral triangle, can be obtained by setting islices to a lower number

 


3D Text

ihandle GLfont3d “itypeface”, idepth, iweight, italic   à Windows only
GLtext3d “textString”, ihandle   à Windows only

DESCRIPTION

Create and render 3D text

INITIALIZATION

ihandle - handle of font-set object just created
“itypeface” - a double-quoted string containing the name of a system-loaded font (for example “Courier New” or “Times New Roman”)
idepth - thickness of the fonts in the z dimension
iweight - amount of weight of the fonts. Range is 0 to 1000. For example, a value of , 400 is normal and 700 is bold
italic - if nonzero the fonts are rendered in italic style

textString - a double-quoted string containing the text to be rendered

FRAME-RATE PERFORMANCE

GLfont3d creates a 3D font-set object. It should be called only once per session, at the header section of the orchestra. However multiple font-set objects can be created with several lines containing GLfont3d. Object is automatically destroyed at the end of a CsoundAV session.

GLtext3d renders a 3D text-string

Both opcodes are Windows-specific at present time


Video

iVideoHandle GLopenVideoFile “filename”, iAlpha   àWindows only
tTexHandle GLvideo2tex tVideoHandle, tReqFrame   àWindows only

GLvideoCapture idevice_num, ivid_xsize, ivid_ysize, img_handle [, img_xsize, img_ysize, ivid_xpos, ivid_ypos] àWindows only; could be changed in the future

DESCRIPTION

Allow to use animated AVI frames or realtime camera-captured frames in a texture, for further 3D processing

INITIALIZATION

iVideoHandle - handle of a video-stream object. Only video is supported, no audio tracks.
“filename” - a double-quoted string denoting the AVI file to be accessed
iAlpha - sets the alpha channel of video frames. Range is 0 to 255

idevice_num - number of capture device. Several capture devices could be activated at the same time.
ivid_xsize, ivid_ysize - width and height of texture object in texels
. Must be power of two values
img_handle - handle of a previously created image object (with bmopen or imgCreate opcodes)
img_xsize, img_ysize - width and height of image object in pixels. Optional.
ivid_xpos, ivid_ypos - position of the video frame space inside the image space.


FRAME-RATE PERFORMANCE

tTexHandle - handle of texture object
tVideoHandle - handle of a video-stream object
tReqFrame - frame number of a video object

GLopenVideoFile opens an AVI file and creates a video-stream object. It should be called only once per session, at the header section of the orchestra. However multiple video-stream objects can be created with several lines of code containing GLfont3d. Each object is automatically destroyed at the end of a CsoundAV session.

GLvideo2tex converts video stream identified by tVideoHandle argument into a texture object.

GLvideoCapture captures a real-time video stream and automatically converts it into a texture object


Controlling Execution Flow of Graphic Engine

tvar GLfor tstart, tstop, tincr
GLend_for

GLwhile (tbool)
GLend_while

GLdoWhile
GLend_doWhile (tbool)

GLif  (tbool)
GLelse
GLend_if

DESCRIPTION

These opcodes, working at frame-rate, allow to control the execution flow of opcodes operating at frame-rate. The execution flow of all eventual opcodes operating at a rate different from frame-rate is not affected.

FRAME-RATE PERFORMANCE

tbool - boolean value (this is actually a floating-point t-rate argument). Can be a t-variable or any expression  made up of  t-rate variables together with relational and logical operators ( >, >=, <, <=, ==, !=, &&, || ) and parenhteses. If it contains an expression with relational or logic operators, it MUST be included in parenteses, for example: GLif (tx<ty) if you write the line GLif tx<ty (without parentheses) an error will occurr.
tvar - an output variable whose value is incremented each loop cycle
tstart - initial value of tvar
tstop - reference value with which to make comparisons with tvar to end loop. Can be updated during the loop, but user should put attention to avoid infinite loops that would hang the computer.
tincr - value with which
tvar is incremented each loop cycle. Can be negative. Can also be updated during the loop, but user should put attention not to change its sign, to avoid infinite loops that would hang the computer.

GLfor and GLend_for opcodes allow to define loops. This construction is similar to ‘for...next’ blocks of high-level languages. For example:

tindex GLfor  1, 10, 1  ;*** iterates from 1 to 10 and tindex
                       ;*** is incremented by 1 each iteration
     .....              ;*** code block at t-rate
GLend_for

GLwhile and GLend_while are similar to'while...wend' blocks of structured languages. Notice that, at present time, due to a limitation of Csound parser, user MUST put the comparison INSIDE the block by assigning its result to a t-rate variable that is used as boolean argument of GLwhile. Also an initialization of such t-variable should be done BEFORE the block. For example:

tx = 1 ;*** index is initialized
tbool = (tx <= 10)  ;*** tbool variable must be also initialized before block,
                    ;*** by filling it with the result of a boolean expression
GLwhile tbool       ;*** at present time you can't use boolean expressions directly
   tbool =(tx <=10) ;*** comparison must appear inside the block in order to be evaluated each cycle
   .......          ;*** code of block must not use k-variables (only i-rate and t-rate)
   tx = tx + 1      ;*** index is incremented to put the condition to exit the loop after 10 iterations
GLend_while
 

GLdoWhile and GLend_doWhile are similar to 'do...while( )' blocks of structured languages. In this case at least one iteration is done anyway. GLdoWhile and GLend_doWhile don't suffer of the syntax limitation of GLwhile and GLend_while, so you can use boolean expressions directly at the place of GLend_while argument. The only restriction is that boolean expressions must be included in parentheses. For example:

tindex = 0                 ;*** index is initialized
GLdoWhile
   ....                    ;*** code block at t-rate
   tindex = tindex + 1     ;*** index is incremented to put the condition to exit the loop after 10 iterations
GLend_doWhile (tindex < 10);*** comparison expressions must be surrounded by parentheses

GLif, GLelse and GLend_if are similar to ‘if...then...else’ blocks of high-level programming languages. For example:

GLif (tx <=ty) ;*** comparison expressions must be surrounded by parentheses
     ....      ;*** code block at t-rate
GLelse
     ....      ;*** code block at t-rate
GLendif

Only execution flow of opcodes working at frame-rate is affected by these flow controllers. Flow of all other opcodes is not modified.


Frame-rate Assign and Math Operators

tvar = tx
tvar = ix
tvar init ix
tvar = t(kexpression)

tr = ta + tb
tr = ta - tb
tr = ta * tb
tr = ta / tb
tr = ta % tb
tr = ta ^ tb

tr GLsum ta, tb
tr GLsub ta, tb
tr GLmul ta, tb
tr GLdiv ta, tb
tr GLmod ta, tb
tr GLpow ta, tb

tr GLint tx
tr GLfrac tx
tr GLrnd tx
tr GLbirnd tx
tr GLabs tx
tr GLexp tx
tr GLlog tx
tr GLsqr tx
tr GLsin tx
tr GLcos tx
tr GLtan tx
tr GLasin tx
tr GLacos tx
tr GLatan tx
tr GLsinh tx
tr GLcosh tx
tr GLtanh tx
tr GLlog10 tx

tr GLlimit tsig, tlow, thigh
tr GLwrap tsig, tlow, thigh
tr GLmirror tsig, tlow, thigh

DESCRIPTION

These math operators and functions are identical to the corresponding ones already present in Csound, but operate at frame-rate

FRAME-RATE PERFORMANCE

tr - result
ta, tb - operands
tx - function input variable
tsig - input signal
tlow, thigh - lower and upper thresholds

When audio output is enabled, it is very important that frame rate arguments are not polluted with expressions containing k-rate. Parse errors will occur otherwise. Whe audio is disabled (command line flag -+Y) user can mix k-rate with t-rate variables (in this case Csound parser will inform the user of these mixes with warnings).

k-rate expressions can be converted to t-rate by means of t(kvar) function (see its documentation for more information).

Functions can be used in function fashion, but as in previous case, their arguments must not contain k-rate expressions when audio output is enabled.


Frame-rate Vector Operators

GLvadd ifn, tval, ielements
GLvmult ifn, tval, ielements
GLvpow ifn, tval, ielements
GLvexp ifn, tval, ielements

GLvaddv ifn1, ifn2, ielements
GLvsubv ifn1, ifn2, ielements
GLvmultv ifn1, ifn2, ielements
GLvdivv ifn1, ifn2, ielements
GLvpowv ifn1, ifn2, ielements
GLvexpv ifn1, ifn2, ielements
GLvcopy ifn1, ifn2, ielements
GLvmap ifn1, ifn2, ielements

GLvlimit ifn, tmin, tmax, ielements
GLvwrap ifn, tmin, tmax, ielements
GLvmirror ifn, tmin, tmax, ielements


DESCRIPTION

Math operators and functions that involve vectors, working at frame-rate.

INITIALIZATION

ifn, ifn1, ifn2 - numbers of tables containing the vectors
ielements - number of elements of corresponding vectors

FRAME-RATE PERFORMACE

tval - scalar operand
tmin, tmax - minimum and maximum limits

See the documentation of corresponding opcodes working at k-rate. The only difference is that their name begins with “GL” and that they work at frame-rate

A parse error will occurr if t-rate expressions are polluted with k-rate variables when audio output is enabled. If audio output is disabled (command line flag -+X) it is possible to mix k-rate with t-rate variables, and only a warning will inform the user of such pollution.

 


Frame-rate Signal Generators

tr GLtab tndx, ifn [, ixmod]
GLtabw tval, tndx, ifn [, ixmod]

GLvtab tndx, ifn, tout1 [, tout2, tout3, .... , toutN ]
GLvtabw tndx, ifn, tinarg1 [, tinarg2, tinarg3 , .... , tinargN ]

tr GLphasor tframes [, iphs]
tr GLoscil tamp, tframes, ifn[, iphs]
tr GLoscili tamp, tframes, ifn[, iphs]
trig GLmetro tframes [, iphs]

GLvphaseseg tphase, ioutab, ielem, itab1,idist1,itab2 [,idist2,itab3,...,idistN-1,itabN]

DESCRIPTION

Oscillators, table-related opcodes and other signal generators that work at frame-rate

INITIALIZATION

ifn - number of table
iphs (optional) - initial phase, expressed as a fraction of a cycle (0 to 1).
ixmode (optional) - indexing data mode. The default value is 0.
== 0 table index is treated as a raw table location,
== 1 table index is normalized (0 to 1)
.

FRAME-RATE PERFORMANCE

tr - result
tndx - table index
tval - value to write into the table
tout1,...,toutN - output values
tinarg1,...,tinargN - input values to write into the table
tframes - frames per cycle
tamp - amplitude
ttrig - trigger signal


These opcodes are almost identical to corresponding opcodes operating at k-rate. The main difference is that, in this case, their name begins with “GL” and that they work at frame-rate

In the case of GLphasor, GLoscil, Gloscili and GLmetro, another important difference is that kcps argument is substituted by tframes argument. In fact, kcps expresses number of cycles per second, whereas tframes expresses number of frames per cycle.

A parse error will occurr if t-rate expressions are polluted with k-rate variables when audio output is enabled. If audio output is disabled (command line flag -+X) it is possible to mix k-rate with t-rate variables, and only a warning will inform the user of such pollution.

GLvphaseseg is identical to vphaseseg but works at frame-rate


RGB Image Processing

iTexHandle img2Gltex ktrig, kimgHandle, kclamp, kMagFilter

kOutTrig imgGain ioutHandle, ktrig, kred, kgreen, kblue, kalpha, ihandle [, iprocessing_time]
imgConvolve ioutHandle, ktrig, kConvRange, kConvMatrix_fn, ihandle

imgPoint ktrig, kx, ky, kred, kgreen, kblue, kalpha, ihandle

imgCreate iwidth, iheight, ibpp, ihandle [, ired, igreen, iblue, ialpha]

DESCRIPTION

Allow to draw and process RGB images, and to convert them into textures

INITIALIZATION
iTexHandle
- handle of texture object

ihandle - handle of input image (an integer number used as unique identifier)
ioutHandle - handle of output image
iprocessing_time - sets the time interval between partial updates
iwidth, iheight - width and height of image to create (must be power of two, if the image has to be converted into a texture)
ibpp - number of bit per pixel (can be 8, 24 or 32)
ired, igreen, iblue, ialpha - components of background color

PERFORMANCE

ktrig - input trigger signal
kOutTrig - output trigger signal
kimgHandle - handle of input image
kclamp - sets the wrap parameter for texture coordinate. Can be $GL_CLAMP or $GL_REPEAT (see glTexParameteri( ) function in OpengGL reference manual to get more information)
kMagFilter - texture ma
gnification function. Can be $GL_NEAREST or $GL_LINEAR (see glTexParameteri( ) function in OpengGL reference manual to get more information)
kred, kgreen, kblue, kalpha - color components
kConvRange - range of convolution. Lower values normally make image brighter
kConvMatrix_fn - table containing convolution matrix
kx, ky - coordinates of point

All these opcodes are working at k-rate except imgCreate (i-rate) and img2Gltex (frame-rate).

img2Gltex converts an image identified by kimgHandle to a texture object identified by iTexHandle. kimgHandle must refer to an already-existing image. User can change the image reference by changing kimgHandle argument at frame-rate. The change is actualized only when ktrig argument is triggered. Eventual changes in arguments kclamp and kMagFilter take also effect only when ktrig is triggered.

imgGain changes the gain of each RGBA component of image identified by ihandle argument separately, and stores the result in ioutHandle image. Original ihandle image is leaved unaffected.
kred, kgreen, kblue and kalpha values are updated only when ktrig is triggered
. If the image to be processed is big, it could take a considerable amount of time to process each pixel, that can affect graphic animation smoothness and cause drop-outs in audio output. In this case you can use iprocessing_time argument to set an interval of time in which image is processed, so, when this time is elapsed, image processing is interrupted yielding CPU time to the other tasks. After that, image processing is restarted, starting from last previously processed pixel. All this cycle can be repeated several times, until the entire image is processed. When image is completed, kOutTrig arguement is triggered, to eventually inform other opcodes of image processing completion. If ktrig is re-triggered before all image is completed, and kred, kgreen, kblue or kalpha values change, various degrees of gain will be present in several areas of the the resulting image. This, normally, should be avoided, but can be use for special effects.

imgConvolve makes convoultion of image identified by ihandle argument, on the basis of user-defined matrices stored in tables identified by kConvMatrix_fn argument. Output is stored into ioutHandle image, and original image is left unaffected. Matrices can be changed at performance time, but user should take into account that convolution is a VERY SLOW process, that could interrupt graphic animation flow (and sound output) for some seconds, depending on the speed of computer, the size of matrix and the size of image. The format of data stored in kConvMatrix_fn table must be the following:

table index

parameter

0

number of rows of matrix (for example, in this case: 3)

1

number of columns of matrix

2

matrix datum of column 0, row 0

3

matrix datum of column 0, row 1

4

matrix datum of column 0, row 2

5

matrix datum of column 1, row 0

6

matrix datum of column 1, row 1

7

matrix datum of column 1, row 2

16 ....

...etcetera...

Structure of table containing convolution matrix

kConvMatrix_fn table should be filled using GEN02. kConvRange argument behaves like a gain factor (lower values increase image brightness).

imgPoint allows to draw points into an image. The image must exist before is affected by imgPoint, user can create an empty image with imgCreate opcode (see below). kx and ky define the coordinate of the point to be drawn, and kred, kgreen, kblue, kalpha arguments set the color of the point. The point is actually drawn when ktrig argument is triggered.

imgCreate creates an empty image having ihandle value (an integer number) as identifier. Optionally, user can set background color with ired, igreen, iblue and ialpha.


Height fields

GLhf   tmode, tscale, inumx, inumy, tnorm, ifn

GLtexHF  tmode, tscale, ts1, tt1, ts2, tt2, inumx, inumy, tnorm, ifn

DESCRIPTION

Draw a height field starting from height data stored into a table.

INITIALIZATION

inumx - number of points along X axis
inumy - number of points along Y axis
ifn - number of table containing the height field data. Table data is organized like an array of y lines. each Y line contain inumy elements. The number of lines is determined by inumx. The total length of the table should be at least (inumx+1) * (inumy+1) to allow extra-bound data to make precise border normals.

FRAME-RATE PERFORMANCE

tmode - rendering mode. can be one of the following macro definitions present in file OpenGL.h:

$GL_POINTS
$GL_LINES
$GL_LINE_LOOP
$GL_LINE_STRIP
$GL_TRIANGLES
$GL_TRIANGLE_STRIP
$GL_TRIANGLE_FAN
$GL_QUADS
$GL_QUAD_STRIP
$GL_POLYGON

tscale - scaling of height field along axis Z. when tscale is set to 1 the table contents is not rescaled, tscale= 0 makes a flat surface, values higher than 1 increase the height of field.
tnorm - handling of surface normals. Can be set to the following values:

0 - no surface normals
1 - facet normals (actually a weird behaviour is obtained, but I like it for some special effects)
2 - vertex normals (smooth surface)

ts1, tt1, ts2, tt2 - texture coordinates of two opposite vertices of a the texture. When  ts1=0, tt1=0, ts2=1 tt2=1 texture bitamap exactly match bounds of height field rectangle.

GLhf draws a height field with a rectangular base. Base rectangle is parallel to X Y plane, and the height vector is parallel to the Z axis.

GLtexHF generates also texture coordinates, according to values ts1, tt1, ts2, tt2 set by the user.

Notice that these two opcodes can be used to display functions of two variables in 3D space. A table can be filled with a function interval. For example, considering the function:

Z = Sin(X)+Cos(X)

in the interval X(-1,1), Y(-1,1)

User can fill a table with this function with the following code in instr 0:

iminX   =       -1
imaxX   =       1
iminY   =       -1
imaxY   =       1
 
ginumX  =       30 ;*** X interval is divided by 30 break-points
ginumY  =       30 ;*** Y interval is divided by 30 break-points
incrX   =       (imaxX-iminX)/ginumX
incrY   =       (imaxY-iminY)/ginumY
 
giFunc  ftgen   20,0,-((ginumX+1) * (ginumY+1)),-2, 0
 
index   =       0       ;*** index of table
ix      =       iminX   ;*** X variable
ij      =       0       ;*** loop index
 
do1:
        iy = iminY     ;*** Y variable
        ik = 0         ;*** loop index
               
        do2:
               tabw_i  sin(ix^2+iy^2), index,giFunc   
               iy = iy+incrY
               ik = ik+1
               index = index+1
        if ik < ginumY igoto do2       
        ix = ix+incrX
        ij = ij+1
 
if ij <= ginumX igoto do1 ;*** generate an additional column 
                     ;*** with respect of row number
                     ;*** to allow margins to be handled correctly
 

then the user can call, for example:

GLtexHF $GL_TRIANGLE_STRIP, 1,  0,0,1,1,   ginumX, ginumY, 2, giFunc

inside an instrument that draws to OpenGL window...


GLE Tubing and Extrusion Library wrapping

glePolyCylinder   tnpoints, ifnPointArray, ifnColorArray, tradius
glePolyCone   tnpoints, ifnPointArray, ifnColorArray, ifnRadiusArray
gleExtrusion   tncp, ifnContour, ifnCont_normal, tup0, tup1, tup2, tnpoints, ifnPointArray, ifnColorArray, ifnXform_array
gleSuperExtrusion   tncp, ifnContour, ifnCont_normal, tup0, tup1, tup2, tnpoints, ifnPointArray, ifnColorArray, ifnXform_array  
gleTwistExtrusion   tncp, ifnContour, ifnCont_normal, tup0, tup1, tup2, tnpoints, ifnPointArray, ifnColorArray, ifnTwist_array
gleTaper   tncp, ifnContour, ifnCont_normal, tup0, tup1, tup2, tnpoints, ifnPointArray, ifnColorArray, ifnTaper, ifnTwist
gleSpiral  tncp, ifnContour, ifnCont_normal, tup0, tup1, tup2, tstartRadius, tdrdTheta, tstartZ, tdzdTheta, ifn_startXform, ifn_dXformdTheta, tstartTheta, tsweepTheta
gleLathe  tncp, ifnContour, ifnCont_normal, tup0, tup1, tup2, tstartRadius, tdrdTheta, tstartZ, tdzdTheta, ifn_startXform, ifn_dXformdTheta, tstartTheta, tsweepTheta
gleHelicoid   trToroid, tstartRadius, tdrdTheta, tstartZ, tdzdTheta, ifn_startXform, ifn_dXformdTheta, tstartTheta, tsweepTheta
gleToroid   trToroid, tstartRadius, tdrdTheta, tstartZ, tdzdTheta, ifn_startXform, ifn_dXformdTheta, tstartTheta, tsweepTheta
gleScrew   tncp, ifnContour, ifnCont_normal, tup0, tup1, tup2, tstartz, tendz, twist
gleBuildNormals  ifnOUT, ifnIN, ielements
gleSetJoinStyle     
tstyle
tstyle   gleGetJoinStyle
gleSetNumSides   tslices
tslices  gleGetNumSides
gleTextureMode   tmode

DESCRIPTION

A set of opcodes suited for drawing tubing, sweeps and extrusions.

INITIALIZATION

ifnPointArray - table containing polyline vertices
ifnColorArray - table containing colors at polyline vertices
ifnRadiusArray - table containing cone radii at polyline vertices
ifnContour - table containing 2D contour
ifnCont_normal - table containing 2D contour normals
ifnPointArray - table containing polyline vertices
ifnTwist_array - table containing contour twists (in degrees)
ifnXform_array - table containing 2D contour transformations
ifn_startXform - table containing starting contour affine transformation
ifn_dXformdTheta - table containing tangent change transformation per revolution
ifnOUT - table containing contour normals (it is filled by the opcode routine)
ifnIN - table containing contour (it must be filled with the 2D contour by the user)
ielements - num of elements of the 2D contour

FRAME-RATE PERFORMANCE

tnpoints - number of points in polyline
tradius - radius of polycylinder
tncp - number of contour points
tup0, tup1, tup2 -  coordinates of up vector for contour
tstartRadius - spiral starts in x-y plane
tdrdTheta - change in radius per revolution
tstartZ - starting z value
tdzdTheta - change in Z per revolution
tstartTheta - start angle in x-y plane
tsweepTheta - degrees to spiral around
trToroid - circle contour (torus) radius
tstartz, tendz - start and end of segment
twist - number of rotations
tstyle - join style flag mask. Mask can be any combination of the following bit flags separated by a bitwise-OR operator:

$TUBE_JN_RAW, $TUBE_JN_ANGLE, $TUBE_JN_CUT, $TUBE_JN_ROUND, $TUBE_JN_MASK , $TUBE_JN_CAP, $TUBE_NORM_FACET, $TUBE_NORM_EDGE, $TUBE_NORM_PATH_EDGE, $TUBE_NORM_MASK, $TUBE_CONTOUR_CLOSED


tslices - cylinder and cone roundness. The more slices, the more round they are. Default value is 20
tmode - set the type of automatic texture coordinate generation to be used
. The argument should be a bitwise-OR of any of the following flags:

$GLE_TEXTURE_ENABLE, $GLE_TEXTURE_STYLE_MASK, $GLE_TEXTURE_VERTEX_FLAT, $GLE_TEXTURE_NORMAL_FLAT, $GLE_TEXTURE_VERTEX_CYL,  $GLE_TEXTURE_NORMAL_CYL, $GLE_TEXTURE_VERTEX_SPH, $GLE_TEXTURE_NORMAL_SPH, $GLE_TEXTURE_VERTEX_MODEL_FLAT, $GLE_TEXTURE_NORMAL_MODEL_FLAT, $GLE_TEXTURE_VERTEX_MODEL_CYL, $GLE_TEXTURE_NORMAL_MODEL_CYL, $GLE_TEXTURE_VERTEX_MODEL_SPH, $GLE_TEXTURE_NORMAL_MODEL_SPH

These opcodes are a wrapping of GLE Tubing and Extrusion API by Linas Vepstas  http://www.linas.org/gle/

 

These opcodes are suited for drawing sweeps and extrusions. A "sweep" or "extrusion" is a 2D contour (polyline) that is swept or extruded along a 3D path (polyline). For example, sweeping a circle along a straight line will generate a cylinder. Sweeping a circle along a circular path will generate a doughnut (torus).

The library also includes a set of utility routines for drawing some of the more common extruded shapes: a polycylinder, a polycone, a generalized torus (circle swept along a helical path), a "helix" (arbitrary contour swept along a helical path) and a "lathe" (arbitrary contour swept along a helical path, with torsion used to keep the contour aligned).

The most general extrusion supported by this library allows an arbitrary 2D contour to be swept around an arbitrary 3D path. A set of normal vectors can be specified to go along with the contour; the normal vectors determine the appearance of the contour when lighting is turned on. A set of colors and affine matrices can be specified to go along with the 3D path. The colors are used to color along the path. The affine matrices are used to operate on the contour as it is swept along. If no affine matrices are specified, the contour is extruded using the mathematical concept of "parallel translation" or "Gaussian translation". That is, the contour is moved (and drawn) along the extrusion path in a "straight" manner. If there are affine matrices, they are applied to the contour at each extrusion segment before the segment is drawn.

The affine matrices allow work in a quasi-non-Euclidean space. They essentially allow the contour to be distorted as it is swept along. The allow the contour to be rotated, translated and rescaled as it is drawn. For example, a rescaling will turn a polycylinder into a poly-cone, since the circle that is being extruded is scaled to a different size at each extrusion vertex. A rotation allows the contour to be spun around while it is being extruded, thus for instance allowing drill-bit type shapes to be drawn. A translation allows the appearance of shearing in real space; that is, taking a contour and displacing it, without otherwise bending it. Note that the affines are 2x3 matrices, not 3x4 matrices, since they apply to the 2D contour as it is being extruded.

glePolyCylinder is the wrapping opcode of the following GLE API function:

void glePolyCylinder (int npoints,            /* num points in polyline */                   gleDouble point_array[][3],    /* polyline vertces */
                   float color_array[][3],    /* colors at polyline verts */
                   gleDouble radius);         /* radius of polycylinder */ 

glePolyCone is the wrapping opcode of the following GLE API function:

 void glePolyCone (int npoints,                      /* numpoints in poly-line */
                   gleDouble point_array[][3],       /* polyline vertices */
                   float color_array[][3],    /* colors at polyline verts */
                   gleDouble radius_array[]);        /* cone radii at polyline verts */

gleExtrusion is the wrapping opcode of the following GLE API function:

void gleExtrusion (int ncp,               /* number of contour points */
                gleDouble contour[][2],     /* 2D contour */
                gleDouble cont_normal[][2], /* 2D contour normals */
                gleDouble up[3],            /* up vector for contour */
                int npoints,                /* numpoints in poly-line */
                gleDouble point_array[][3], /* polyline vertices */
                float color_array[][3]);    /* colors at polyline verts */
 

gleSuperExtrusion is the wrapping opcode of the following GLE API function:

void gleSuperExtrusion (int ncp,         /* number of contour points */
                gleDouble contour[][2],    /* 2D contour */
                gleDouble cont_normal[][2],/* 2D contour normals */
                gleDouble up[3],           /* up vector for contour */
                int npoints,               /* numpoints in poly-line */
                gleDouble point_array[][3],/* polyline vertices */
                float color_array[][3],    /* color at polyline verts */
                gleDouble xform_array[][2][3]);   /* 2D contour xforms */

gleTwistExtrusion is the wrapping opcode of the following GLE API function:

 void gleTwistExtrusion (int ncp,         /* number of contour points */
                gleDouble contour[][2],    /* 2D contour */
                gleDouble cont_normal[][2], /* 2D contour normals */
                gleDouble up[3],           /* up vector for contour */
                int npoints,           /* numpoints in poly-line */
                gleDouble point_array[][3],        /* polyline vertices */
                float color_array[][3],        /* color at polyline verts */
                gleDouble twist_array[]);   /* contour twists (in degrees) */

gleTaper is the wrapping opcode of the following GLE API function:

void gleTaper (int ncp, 
               gleDouble contour[][2], 
               gleDouble cont_normal[][2], 
               gleDouble up[3],
               int npoints,
               gleDouble point_array[][3],
               float color_array[][3],
               gleDouble taper[],
               gleDouble twist[])
 

gleSpiral is the wrapping opcode of the following GLE API function:

 void gleSpiral (int ncp,        /* number of contour points */
             gleDouble contour[][2],    /* 2D contour */
             gleDouble cont_normal[][2], /* 2D contour normals */
             gleDouble up[3],           /* up vector for contour */
             gleDouble startRadius,   /* spiral starts in x-y plane */
             gleDouble drdTheta,        /* change in radius per revolution */
             gleDouble startZ,        /* starting z value */
             gleDouble dzdTheta,        /* change in Z per revolution */
             gleDouble startXform[2][3], /* starting contour affine xform */
             gleDouble dXformdTheta[2][3], /* tangent change xform per revoln */
             gleDouble startTheta,    /* start angle in x-y plane */
             gleDouble sweepTheta);   /* degrees to spiral around */

gleLathe is the wrapping opcode of the following GLE API function:

 void gleLathe (int ncp,        /* number of contour points */
             gleDouble contour[][2],    /* 2D contour */
             gleDouble cont_normal[][2], /* 2D contour normals */
             gleDouble up[3],           /* up vector for contour */
             gleDouble startRadius,   /* spiral starts in x-y plane */
             gleDouble drdTheta,        /* change in radius per revolution */
             gleDouble startZ,        /* starting z value */
             gleDouble dzdTheta,        /* change in Z per revolution */
             gleDouble startXform[2][3], /* starting contour affine xform */
             gleDouble dXformdTheta[2][3], /* tangent change xform per revoln */
             gleDouble startTheta,    /* start angle in x-y plane */
             gleDouble sweepTheta);   /* degrees to spiral around */

gleHelicoid is the wrapping opcode of the following GLE API function:

 void gleHelicoid (gleDouble rToroid, /* circle contour (torus) radius */
             gleDouble startRadius,   /* spiral starts in x-y plane */
             gleDouble drdTheta,        /* change in radius per revolution */
             gleDouble startZ,        /* starting z value */
             gleDouble dzdTheta,        /* change in Z per revolution */
             gleDouble startXform[2][3], /* starting contour affine xform */
             gleDouble dXformdTheta[2][3], /* tangent change xform per revoln */
             gleDouble startTheta,    /* start angle in x-y plane */
             gleDouble sweepTheta);   /* degrees to spiral around */

gleToroid is the wrapping opcode of the following GLE API function:

 void gleToroid (gleDouble rToroid, /* circle contour (torus) radius */
             gleDouble startRadius,   /* spiral starts in x-y plane */
             gleDouble drdTheta,        /* change in radius per revolution */
             gleDouble startZ,        /* starting z value */
             gleDouble dzdTheta,        /* change in Z per revolution */
             gleDouble startXform[2][3], /* starting contour affine xform */
             gleDouble dXformdTheta[2][3], /* tangent change xform per revoln */
             gleDouble startTheta,    /* start angle in x-y plane */
             gleDouble sweepTheta);   /* degrees to spiral around */

gleScrew is the wrapping opcode of the following GLE API function:

 void gleScrew (int ncp,          /* number of contour points */
             gleDouble contour[][2],    /* 2D contour */
             gleDouble cont_normal[][2], /* 2D contour normals */
             gleDouble up[3],           /* up vector for contour */
             gleDouble startz,          /* start of segment */
             gleDouble endz,            /* end of segment */
             gleDouble twist);          /* number of rotations */

gleBuildNormals  opcode builds the normals of a 2D contour stored in ifnIN table and puts the result into ifnOUT table.

gleSetJoinStyle  and gleGetJoinStyle are the wrapping opcodes of the following GLE API functions:

void gleSetJoinStyle (int style);  /* bitwise OR of flags */ 
int gleGetJoinStyle (void); 

gleGetNumSides  and gleSetNumSides are the wrapping opcodes of the following GLE API functions:

 int gleGetNumSides(void);
 void gleSetNumSides(int slices);
 
 

gleTextureMode is the wrapping opcode of the following GLE API function:

gleTextureMode(int mode);   /* bitwise OR of flags */
 

For more information, see the main documentation of GLE API at its web site:

 http://www.linas.org/gle/


Two-dimensional text fonts

GLUTprints "string", tfont, tvertical_spacing, tx, ty, tz

DESCRIPTION

Display text with bitmap/vectorial fonts.

INITIALIZATION

"string" - a double-quoted string. Can be multi-line by separating lines with a '@' character.

FRAME-RATE PERFORMANCE

tfont - font type. Can be one of the following:

$GLUT_STROKE_ROMAN  (vectorial)
$GLUT_STROKE_MONO_ROMAN (vectorial)
$GLUT_BITMAP_9_BY_15   (bitmapped)
$GLUT_BITMAP_8_BY_13   (bitmapped)
$G
LUT_BITMAP_TIMES_ROMAN_10   (bitmapped)
$GLUT_BITMAP_TIMES_ROMAN_24   (bitmapped)
$GLUT_BITMAP_HELVETICA_10   (bitmapped)
$GLUT_BITMAP_HELVETICA_12   (bitmapped)
$GLUT_BITMAP_HELVETICA_18   (bitmapped)

tvertical_spacing - vertical spacing between lines of text.Positive values put subsequent lines from bottom to top, negative values top to bottom

tx, ty, tz - coordinates of the bottom-right corner of the first line of text

It is possible to vary vectorial font aspect with glLineWidth opcode.


Mouse Opcodes

tX, tY GLmouseXY [inormalize, [iXmin, iXmax, iYmin, iYmax]]

tbutton GLmouseButton

tX, tY GLmouseScroll  ibutton [, istepX, istepY]

GLsetMouseCursor tcursor

DESCRIPTION

Return information about position and pressed buttons of the mouse.

INITIALIZATION

inormalize (optional) - set type of normalization:
       0 (or $GL_MOUSE_RAW) = unconverted pixel coordinates (default);
       1 (or $GL_MOUSE_NORM) = coordinates of the OpenGL window are converted to fit the 0 to 1 range, but the       output can still surpass these limits when the mouse goes outside the window area;
       2 (or $GL_MOUSE_RANGE) = the mouse coordinates are rescaled to fit the iXmin, iXmax, iYmin and iYmax range;
       3 (or $GL_MOUSE_LIMIT) similar to $GL_MOUSE_NORM, but the values outside the window are limited to fit in the 0 to 1 range

iXmin, iXmax, iYmin, iYmax (optional) - minimum and maximum ranges when using inormalize = $GL_MOUSE_RANGE

ibutton - mouse button to press to start scrolling:
       1 (or $GL_MOUSE_LEFT) = left button;
       2 (or $GL_MOUSE_CENTER) = center button;
       3 (or $GL_MOUSE_RIGHT) = right button

istepX, istepY (optional) - output steps for each mouse scroll event (default is 1)

tcursor - shape of mouse cursor to set. Can be one of the following:
       $FL_CURSOR_DEFAULT -> 0
       $FL_CURSOR_ARROW -> 1
       $FL_CURSOR_CROSS -> 2
       $FL_CURSOR_WAIT
-> 3
       $FL_CURSOR_INSERT -> 4
       $FL_CURSOR_HAND -> 5
       $FL_CURSOR_HELP  -> 6
       $FL_CURSOR_MOVE  -> 7
       $FL_CURSOR_NS -> 8
       $FL_CURSOR_WE -> 9
       $FL_CURSOR_NWSE -> 10
       $FL_CURSOR_NESW -> 11
       $FL_CURSOR_NONE -> 12
       $FL_CURSOR_N -> 13
       $FL_CURSOR_NE -> 14
       $FL_CURSOR_E -> 15
       $FL_CURSOR_SE -> 16
       $FL_CURSOR_S -> 17
       $FL_CURSOR_SW -> 18
       $FL_CURSOR_W -> 19
       $FL_CURSOR_NW -> 20

FRAME-RATE PERFORMANCE

tX, tY - output values (raw OpenGL window coordinates or rescaled values, depending on corresponding inormalize value)

tbutton - mouse button pressed:
       1 (or $GL_MOUSE_LEFT) = left button;
       2 (or $GL_MOUSE_CENTER) = center button;
       3 (or $GL_MOUSE_RIGHT) = right button

GLmouseXY returns the mouse position inside corresponding OpenGL window. Output values can be rescaled by means of inormalize flag.

GLmouseButton returns the button pressed or 0 if no button is currently pressed.

GLmouseScroll returns the current amount of scrolling, starting from a dragging operation inside the OpenGL window. Output values can be rescaled by means of istepX and istepY arguments

GLsetMouseCursor sets the shape of the mouse cursor when it is located inside the OpenGL window area. Useful especially to hide it in full-screen mode (by setting tcursor to $FL_CURSOR_NONE).


Viewport-related opcodes

GLsetViewport ix, iy, iwidth, iheight

twidth, theight, tx, ty GLgetScreenInfo

iwidth, iheight, ix, iy GLgetScreenInfo_i  

DESCRIPTION

Sets current viewport rectangle in OpenGL window, and retrieve information about it.

INITIALIZATION

ix, iy, iwidth, iheight - position and size of the viewport in pixels.

FRAME-RATE PERFORMANCE

tx, ty, twidth, theight - position and size of the viewport in pixels.

GLsetViewport sets the viewport size. It must be placed in GLinsert_i $GL_INIT or GLinsert_i $GL_NOT_VALID sections, i.e. it has to be called only when it is required, not for all frames.

GLgetScreenInfo gets current viewport size and position.

GLgetScreenInfo_i is identical to GLgetScreenInfo but works at init-rate only.


Macros

Several orchestra macros are provided in file OpenGL.h

They allow a simpler and more brief access to often-used functionalities.


$glFPS( fps )

sets the global variable giFPS = fps and calls GLfps with fps argument. Globab variable giFPS has a fixed meaning for all orchestra and could be sometimes useful to access it for read. Don't modify giFPS variable directly...


$glHEADER

sets the following orchestra header:

sr = 100
kr = 100
ksmps = 1
nchnls = 1

to be used without audio output.


$glPANEL(width' height)

Creates and runs an OpenGL panel with specified height and width in pixels.


$glSCREEN

(no arguments) Creates and runs an OpenGL full-screen panel. Never use it together with $glPANEL( ) macro


$glORTHO(size)

Sets current view to an orthographic projection having -size to size dimension on all the three axes.


$glCLEAR

(no arguments) Clears the screen with both color and depth buffer bits set. Current glClearColor determinates the background color to be used.


$glPERSPECTIVE(angle)

Sets current view to a prespective of angle width.


$glLIGHTING

(no arguments) Enables lighting and creates a light with arbitrary parameters.


$glSPHERE_MAP

(no arguments) Sets all parameters to enable automatic sphere-map texture mapping generation


$glSURFACE_3D(S' outTable' formula' numX' xmin' xmax' numY' ymin' ymax )

Fills a Csound table with an array of vertices of a three-dimensional surface, created by a user formula. It can then be used, for example, with GLhf opcode.

ARGUMENTS:

S - a unique suffix identifier for internal variables (when having multiple instances, this argument should be provided by the user differently for each macro instance, in order to avoid conflicts).

outTable - output table identifier (must be an i-rate variable)

formula - an function formula with two variables. User must use ix and iy as the names of such formula, for example: sin(ix)+cos(iy). The implicit dependent variable is iz (but it must not appear in the formula).

xmin, xmax, ymin, ymax -  minimum and maximum bounds in x-y plane. Obviously min values must be less than max ones.

numX, numY - number of grid points in the x and y dimensions.


Converting k to t-rate

t(kvar)

set_t_del idelay

tabk2t  itab_out, itab_in, ielem, istart_ndx

DESCRIPTION

Allow to convert k-rate signals to t-rate signals. These opcodes are very useful when using audio and OpenGL graphics at the same time, since in this case you cannot use k-variables as arguents of the OpenGL opcodes, but they must prior be converted to t-rate.

INITIALIZATION

idelay – delay, in frames of the ///////////////////////////////

itab_out – number of output table (that will be accessed at t-rate)

itab_in – number of input table (that is accessed at k-rate)

ielem – number of elements of the input and output table (must be the same)

istart_ndx – start index, i.e. an offset where the conversion has to begin. The conversion ends at index ielem-1.