[Top] | [Contents] | [Index] | [ ? ] |
This is a reference manual of Gauche-gl, an OpenGL binding for the Gauche Scheme implementation. This manual is for version 0.6.
1. Introduction | ||
2. Installation | ||
3. Getting Started | ||
4. OpenGL API | ||
5. GLUT API | ||
6. Vectors and matrices | ||
7. Simple utilities | ||
A. Indices |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Gauche-gl is an extension module of Gauche Scheme implementation. It provides the following modules:
gl
This module provides bindings to OpenGL API. It covers most functions in OpenGL 1.0 through 2.0, and GLU. The functions are described in OpenGL API.
gl.glut
This module provides bindings to most functions in GLUT. The functions are described in GLUT API.
gl.math3d
This module provides vector and matrix calculations optimized for 3D homogeneous coordinates. The vector and matrix objects here can be directly passed to Gauche-gl functions. The functions are descrbied in Vectors and matrices.
gl.simple.*
These modules provide simple APIs for programmers to hack up a very simple OpenGL application. They are by no means intended for general application development, but would be handy for throwaway script. See Simple utilities for the details.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Installing Gauche-gl is usually straightforward on Unix variants.
You have to have the following programs installed on your machine.
The standard way to compile and install Gauche-gl is as follows:
% gzcat Gauche-gl-0.6.tgz | tar xf - % cd Gauche-gl-0.6 % ./configure % make % make test % make install |
Or you can use ‘gauche-package’ command:
% gauche-package install -C=<configure-option> Gauche-gl-0.6.tgz |
The confiugre script figures out the location Gauche is installed, and install Gauche-gl in the same place.
If you have GLUT installed in non-standard place, you have to tell the configure script where it is.
% ./configure --with-glut=DIR |
Since version 0.4, Gauche-gl can be configured to include bindings
to NVidia’s Cg Toolkit. The binding code is contributed by Issac Trotts.
To enable Cg binding, give --enable-cg
option to the configure
script.
% ./configure --enable-cg |
It is reported that Mesa in FreeBSD ports is compiled with pthreads enabled, and Gauche-gl can’t be linked unless Gauche itself is compiled with pthreads. The configure script of Gauche prints warning if you specify pthreads, but it is safe as far as you don’t call make-thread in your program.
There are various examples under ‘examples/’ directory.
If you want to run the examples before installing Gauche-gl,
you have to tell the location of the library to gosh
command, e.g. gosh -I../src -I../lib gears.scm
.
Some demos under subdirectories have a shell script that invokes
gosh
with proper command-line options.
Brian Paul’s 3D gear wheels.
Simple calculated texture.
This subdirectory contains examples found in "OpenGL Programming Guide", a.k.a. Redbook.
This subdirectory contains examples found in "OpenGL Shading Language". Each demo is under its own subdirectories. You need to have proper driver/hardware that supports GLSL to run these demos.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
3.1 GL calls in Scheme | ||
3.2 Advanced GL features | ||
3.3 Using GLUT | ||
3.4 Performance tips |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
I assume you have basic knowledge of OpenGL API. Gauche-gl maps OpenGL calls to Scheme procedures pretty straightforwardly. For example, the very first example of "OpenGL Programming Guide", the pseudo code of OpenGL application, can be written in Gauche-gl like this:
(use gl) (define (main args) (initialize-a-window-please) (gl-clear-color 0.0 0.0 0.0 0.0) (gl-clear GL_COLOR_BUFFER_BIT) (gl-color 1.0 1.0 1.0) (gl-ortho 0.0 1.0 0.0 1.0 -1.0 1.0) (gl-begin* GL_POLYGON (gl-vertex 0.25 0.25 0.0) (gl-vertex 0.75 0.25 0.0) (gl-vertex 0.75 0.75 0.0) (gl-vertex 0.25 0.75 0.0) ) (gl-flush) (update-the-window-and-check-for-events) 0) |
Note that initialize-a-window-please and update-the-window-and-check-for-events are function calls dependent on the windowing system. Gauche-gl comes with GLUT binding and you can use it to do basic stuff. In the separate package Gauche-gtk, a binding to GtkGLExt is provided, which allows you to do GL rendering inside Gtk widgets.
For the time being, let’s focus on the pure GL part.
The mapping of GL call name is straightforward.
The mixed case names in OpenGL C API is expanded to hyphenated name,
e.g. glClearColor
⇒ gl-clear-color
.
OpenGL enums are mapped as is, e.g.
GL_POLYGON
. (Note that Gauche is case-sensitive by default.
Also note the underscore, not hyphen, in constants).
A few convenience macros, such as gl-begin*
, is defined.
There are straight bindings of gl-begin
and gl-end
,
so you can write the drawing part in the same way as in C:
(gl-begin GL_POLYGON) (gl-vertex 0.25 0.25 0.0) (gl-vertex 0.75 0.25 0.0) (gl-vertex 0.75 0.75 0.0) (gl-vertex 0.25 0.75 0.0) (gl-end) |
Actually gl-begin*
macro expands into the above calls.
It’s a matter of taste, but the macro version guarantees
begin and end match, and the syntax-aware editor can indent
internal calls accordingly.
You might have noticed that the type suffix in C API is not in Gauche binding. The Scheme function figures out the type of passed arguments and calls appropriate C API. SRFI-4 uniform numeric vectors are used to represent arrays of numbers.
(gl-vertex 1.0 2.0 3.0) ⇒ glVertex3d (gl-vertex '#f32(1.0 2.0)) ⇒ glVertex2fv (gl-vertex '#s32(3 2 5)) ⇒ glVertex3iv |
Generally, passing uniform vectors is much more efficient than giving individual numbers, for the former can eliminate the cost of type checking and unboxing.
Some GL calls can also take gl.math3d
primitive objects
such as vector4f
, point4f
or matrix4f
(See section Vectors and matrices). For example, you can pass
point4f
object to gl-vertex
, vector4f
to
gl-normal
, and matrix4f
to gl-mult-matrix
.
They are efficient since calculations on those types are
defined natively in gl.math3d
, and passing it to GL call
doesn’t cost unboxing.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Although Gauche-gl supports up to OpenGL 2.0, all functionalities may not be available on the target machine’s driver/hardware. The application needs to check the availability of the extension and/or GL version before using the features that are only supported by the extension/version.
Gauche-gl provides a couple of utility procedures to check the feature sets at runtime. For example, you can switch behavior depending on OpenGL 1.3 feature availability:
(if (gl-version>=? "1.3") (code-using-features-available-in-OpenGL-1.3-and-later ...) (alternative-code ...)) |
Or you can check the availability of extensions:
(unless (gl-extension-supported? 'GL_ARB_shader_objects 'GL_ARB_fragment_shader 'GL_ARB_vertex_shader 'GL_ARB_shading_language_100) (error "OpenGL Shading Language extensions not available")) |
See GL feature checking for the details.
If the client program calls a GL API that are not supported on the platform, an error is signalled.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In order to make a runnable script, you need to use some windowing system interface. GLUT binding provides a simple way for it.
Here is a complete runnable Scheme script, ported from Example 1-2 in "OpenGL Programming Guide":
(use gl) (use gl.glut) (define (disp) (gl-clear GL_COLOR_BUFFER_BIT) (gl-color '#f32(1.0 1.0 1.0)) (gl-begin* GL_POLYGON (gl-vertex '#f32(0.25 0.25 0.0)) (gl-vertex '#f32(0.75 0.25 0.0)) (gl-vertex '#f32(0.75 0.75 0.0)) (gl-vertex '#f32(0.25 0.75 0.0)) ) (gl-flush) ) (define (init) (gl-clear-color 0.0 0.0 0.0 0.0) (gl-matrix-mode GL_PROJECTION) (gl-load-identity) (gl-ortho 0.0 1.0 0.0 1.0 -1.0 1.0) ) (define (keyboard key x y) (cond ((= key 27) (exit 0)) )) (define (main args) (glut-init args) (glut-init-display-mode (logior GLUT_SINGLE GLUT_RGB)) (glut-init-window-size 250 250) (glut-init-window-position 100 100) (glut-create-window "hello") (init) (glut-display-func disp) (glut-keyboard-func keyboard) (glut-main-loop) 0) |
The (use gl.glut)
form loads GLUT binding.
The name mapping is the same as GL’s: mixed case names to
hyphenated names.
In order to handle various events, you can pass a closure
to glut-display-func
etc. In the keyboard and mouse
event callback, all arguments are integers.
There are more examples under the ‘examples/’ directory which uses GLUT.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you want to display millions of polygons in 30 fps, Gauche-gl is not for you. Consider using implementations that compiles into native code. The purpose of Gauche-gl is to provide reasonable performance for interactive development and experiment.
However, if you know some tips, actually you can go quite far, especially with recent processors and graphics chips.
The functional (non-destructive) operations tend to return
newly-allocated objects.
Use linear-update (destructive) versions instead,
such as matrix-mul!
, u8vector-add!
, etc,
whenever possible.
Pre-allocating temporary vectors is also effective.
Vertex arrays are much better than calling gl-vertex
over and over. Also consider using display lists if
you’re displaying rigid objects.
Every time you take a number out of a uniform vector
(or <vector4f>
etc.), Gauche has to wrap the
number by a tag (boxing). Also when you store a number
into a uniform vector, Gauche has to check the type
of the object, then strip a tag (unboxing).
Those are all overhead you wouldn’t have if
you operate directly on uniform vectors (or <vector4f>
etc).
If the above strategies are not enough, consider writing computation-intensive part in C as an extension. The easier way is to make C routines operate on uniform vectors, which is essentially a pointer to an array of numbers from C, and let Scheme handle higher-level data structures. (It could be viewed like relations between a coprocessor and a processor; the former does simple, iterative calculations fast, and the latter handles complicated logic).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In this chapter we list a GL and GLU procedures accessible from Gauche-gl, with brief descriptions to help programmers to remind what the functions are. We don’t intend to make this an OpenGL reference, though; you should look at the OpenGL book for the details of what each API do.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GL doesn’t define many data structures: some scalar primitives (e.g.
GLint
) and arrays of them.
For scalar values, Gauche-gl has natural mappings:
GLboolean
Scheme booleans.
GLbyte, GLubyte, GLshort, GLushort, GLint, GLuint, GLenum, GLbitfield
Scheme exact integers.
GLfloat, GLdouble, GLclampf, GLclampd
Scheme real numbers.
For arrays, Gauche-gl uses uniform (srfi-4) vector whenever possible.
For float arrays, however, Gauche-gl allows more structured types,
such as points or matrices, when they are relevant. Such types are provided
in gl.math3d
module (see Vectors and matrices),
which also provides common arithmetics between those types.
Another exception is an array of GLboolean—it doesn’t have corresponding
uniform vector representation. Gauche-gl defines a new type,
<gl-boolean-vector>
, to represent an array of GLboolean.
See below for operations provided on it.
GLbyte[]
<s8vector>
GLubyte[]
<u8vector>
GLshort[]
<s16vector>
GLushort[]
<u16vector>
GLint[]
<s32vector>
GLuint[]
<u32vector>
GLfloat[], GLclampf[]
<f32vector>
, <point4f>
, <vector-4f>
,
<point4f-array>
, <vector4f-array>
,
<matrix4f>
, <quatf>
.
GLdouble[], GLclampd[]
<f64vector>
GLboolean[]
<gl-boolean-vector>
A class for an array of boolean values. You can pass its instance to the GL APIs that expect an array of GLbooleans. Its internal representation is bitwise compatible to GLbooean array, so passing it is quite efficient.
This class inherits <sequence>
, so you can use generic
sequence operations on it.
The external representation of GL boolean vector uses srfi-10 notation, and can be read back. For example, a GL boolean vector of length 5 may be written something like this:
#,(gl-boolean-vector #t #f #t #f #t) |
Returns a GL boolean vector of size elements. Elements are
initialized by either #f
or #t
, according to init.
(make-gl-boolean-vector 3 #t) ⇒ #,(gl-boolean-vector #t #t #t) |
Returns a GL boolean vector, whose elements are bool ….
(gl-boolean-vector #f #t #t) ⇒ #,(gl-boolean-vector #f #t #t) |
Returns #t
if obj is a GL boolean vector, #f
otherwise.
Returns length of a GL boolean vector v.
You can also use the sequence generic function size-of
.
Fills a GL boolean vector v with a boolean value bool.
Coerce list of boolean values to a GL boolean vector.
You can also use the coerce-to
generic function to convert
between GL boolean vectors and other sequences.
Returns k-th element of a GL boolean vector v. If k is out of range and fallback is provided, it is returned. If k is out of range and fallback is omitted, an error is signalled.
You can also use generic function ref
to access a
GL boolean vector.
Sets k-th element of a GL boolean vector v by a boolean value bool.
You can also use generic function (setter ref)
to modify a
GL boolean vector.
Returns a copy of a GL boolean vector v.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you want to use a feature that are in OpenGL 1.2 or later, or in a GL extension, you have to check its availability before actually calling the API function. You can use the following utility procedures.
Note that those functions may return #f
if the connection
to the display subsystem isn’t established yet. Usually you have
to initialize and open an window before checking the features.
Returns #t
if GL extensions listed in extension-name …
are all available. Extension-name can be a symbol or
a string (e.g. GL_ARB_multisample
).
Returns #t
if the runtime OpenGL version is less than,
less thanor equal to, greater than, greater than or equal to,
and equal to, the given version, respectively.
Give version in a string, e.g. "1.3"
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Executes gl-commands between (gl-begin mode)
and
(gl-end)
. Mode can be one of the following constants.
GL_POINTS
Individual points.
GL_LINES
Pairs of vertices interpreted as individual line segments.
GL_LINE_STRIP
Series of connected line segments.
GL_LINE_LOOP
Same as above, with a segment added between last and first vertices.
GL_TRIANGLES
Triples of vertices interpreted as triangles.
GL_TRIANGLE_STRIP
Linked trip of triangles.
GL_TRIANGLE_FAN
Linked fan of triangles.
GL_QUADS
Quadruples of vertices interpreted as four-sided polygons.
GL_QUAD_STRIP
Linked strip of quadrilaterals.
GL_POLYGON
Boundary of a simple, convex polygon.
Corresponds to glBegin
and glEnd
.
Use of gl-begin*
macro is recommended, though.
Flush the GL command buffer.
Make sure all previously issued GL commands are completed.
Draws a rectangle. In the first form,
point1 and point2 can be either
<point4f>
, or f32, f64, s32, or s16vector of
length 2. Types of both args should match.
In the second form, all args should be a real numbers (glRectd
is used).
Specify vertices. In the first form, point can be
either <point4f>
, or f32, f64, s32 or s16vector
of length 2, 3 or 4.
In the second form, all args should be a real numbers.
Sets vertex normal vector. In the first form, vector can be
either <vector4f>
(the fourth element is ignored),
or f32, f64, s32 ro s16vector of length 3.
In the second form, all args should be a real numbers.
Sets the current color. In the first form, color can be either f32, f64, u8, u16, u32, s8, s16, or s32vector of length 3 or 4. In the second form, all args should be a real numbers.
Sets the current texture coordinates. In the first form, coord can be either f32, f64, s32 or s16vector of length 1, 2, 3, or 4. In the second form, all args should be a real numbers.
Sets the current raster position. In the first form, pos can be eitehr f32, f64, s32 or s16vector. In the second form, all args should be a real numbers.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Turns on and off a capability cap. Check out OpenGL reference for the list of capabilities.
Returns #t
of #f
depending on cap is enabled or not.
Enable/disable a client-side array (e.g. vertex array) specified by array. Array can be one of the following constants.
GL_VERTEX_ARRAY
GL_COLOR_ARRAY
GL_INDEX_ARRAY
GL_NORMAL_ARRAY
GL_TEXTURE_COORD_ARRAY
GL_EDGE_FLAG_ARRAY
Gauche has two variations for each type of OpenGL glGetTYPE
APIs;
nondestructive version and destructive versions. Nondestructive versions
such as gl-get-boolean
allocates and returns the vector of
appropriate type for the state. For destructive versions such as
gl-get-boolean!
, you need to pass a vector to be filled in.
The destructive version is non-allocating operation, so it is suitable if you call it within the drawing loop.
If the state has a scalar value, the non-destructive version of query function returns a scalar value, but you need to pass a (uniform) vector of length 1 for the destructive version.
[Gauche specific]
Returns the required size of the vector to retrieve GL state state.
It is useful to prepare the vector to pass to the destructive version
of glGetTYPE
API.
Get (a) boolean state value(s).
Get (an) integer state value(s).
Get (a) single-precision floating-point state value(s).
Get (a) double-precision floating-point state value(s).
Push/pop attributes indicated by mask.
Valid mask can be logior
of the following bits
(GLL_ALL_ATTRIB_BITS is logior
of all the bits).
GL_ACCUM_BUFFER_BIT
GL_COLOR_BUFFER_BIT
GL_CURRENT_BIT
GL_DEPTH_BUFFER_BIT
GL_ENABLE_BIT
GL_EVAL_BIT
GL_FOG_BIT
GL_HINT_BIT
GL_LIGHTING_BIT
GL_LINE_BIT
GL_LIST_BIT
GL_PIXEL_MODE_BIT
GL_POINT_BIT
GL_POLYGON_BIT
GL_POLYGON_STIPPLE_BIT
GL_SCISSOR_BIT
GL_STENCIL_BUFFER_BIT
GL_TEXTURE_BIT
GL_TRANSFORM_BIT
GL_VIEWPORT_BIT
GL_ALL_ATTRIB_BITS
All of the above.
Push/pop client attributes. Valid mask can be
logior
of the following
GL_CLIENT_PIXEL_STORE_BIT
GL_CLIENT_VERTEX_ARRAY_BIT
GL_ALL_CLIENT_ATTRIB_BITS
All of the above.
Returns the value of the error flag. Returned an integer value. Check out the OpenGL documentation for the possible error values.
This function resets the error flag to GL_NO_ERROR
.
Returns a descriptive string for error-code returned by
gl-get-error
.
Returns informative string about name of the GL library. Name can be one of the following.
GL_VENDOR
GL_RENDERER
GL_VERSION
GL_EXTENSIONS
To check a specific version or extension, you can also use
the utility procedure gl-version>?
etc. See
GL feature checking.
Returns informative string about name of the GLU library. Name can be one of the following.
GLU_VERSION
GLU_EXTENSIONS
Controls quality of target by hint. Target can be one of the following:
GL_POINT_SMOOTH_HINT
GL_LINE_SMOOTH_HINT
GL_POLYGON_SMOOTH_HINT
GL_FOG_HINT
GL_PERSPECTIVE_CORRECTION_HINT
And hint can be one of the following:
GL_FASTEST
GL_NICEST
GL_DONT_CARE
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Sets the width in pixels for rendered points.
The possible range of size on the running GL implementation
can be obtained by passing either GL_ALIASED_POINT_SIZE_RANGE
or
GL_SMOOTH_POINT_SIZE_RANGE
to gl-get-float
.
Sets the width in pixels for rendered lines.
The possible range of width on the running GL implementation
can be obtained by passing either GL_ALIASED_LINE_WIDTH_RANGE
or
GL_SMOOTH_LINE_WIDTH_RANGE
to gl-get-float
.
Sets the current stippling pattern for lines.
pat
must be an exact integer, and its lower 16 bits are used
to specify the stipple pattern. Factor is an integer factor
to specify how many pixels corresponds to one bit in pat.
You have to enable GL_LINE_STIPPLE to use face culling.
Specifies the drawing mode for a polygon’s front and back faces. Face can be one of the followings:
GL_FRONT_AND_BACK
GL_FRONT
GL_BACK
Mode can be one of the followings:
GL_POINT
GL_LINE
GL_FILL
Controls how OpenGL determine front face of a polygon Mode can be one of the followings:
GL_CCW
Front face is where ordered vertices appear in a counterclockwise orientation (default).
GL_CW
Front face is where ordered vertices appear in a clockwise orientation.
Indicates which face of polygons should be culled. Mode can be one of the followings:
GL_FRONT
GL_BACK
GL_FRONT_AND_BACK
You have to enable GL_CULL_FACE to use face culling.
Defines the current stipple pattern for filled polygons. Mask has to be a u8vector of length 128, specifying a 32x32 bitmap pattern. You have to enable GL_POLYGON_STIPPLE to use this feature.
Sets the edge flag(s) of vertices. When flag is
a GL boolean vector, glEdgeFlagv
is called.
Otherwise flag is used as a single boolean value
for glEdgeFlag
.
Controls how color values in the fragment being processed (the source) are combined with the ones in the framebuffer (the destination).
Possible values for the sfactor and dfactor arguments are as follows.
GL_ZERO
GL_ONE
GL_DST_COLOR
GL_SRC_COLOR
GL_ONE_MINUS_DST_COLOR
GL_ONE_MINUS_SRC_COLOR
GL_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA
GL_DST_ALPHA
GL_ONE_MINUS_DST_ALPHA
GL_SRC_ALPHA_SATURATE
GL_CONSTANT_COLOR
GL_ONE_MINUS_CONSTANT_COLOR
GL_CONSTANT_ALPHA
GL_ONE_MINUS_CONSTANT_ALPHA
[GL_ARB_imaging] By default, the source and destination colors are added after processed as specified by gl-blend-func. With this extension API you can change the function. Mode can be one of the following values:
GL_FUNC_ADD
GL_FUNC_SUBTRACT
GL_FUNC_REVERSE_SUBTRACT
GL_MIN
GL_MAX
[GL_ARB_imaging] Sets the constant color used in the blending function.
[GL1.1] Offset the depth value of each fragment. Useful to avoid artifacts when you draw polygon edges over its surfaces, for example.
Defines a clipping plane. Plane specifies which clipping
plane you’re defining. Use GL_MAX_CLIP_PLANES
to
gl-get-integer
to obtain the number of clipping planes
you can use. You have to enable the specific clipping plane
(e.g. (gl-enable GL_CLIP_PLANE0)
) to use the clipping plane.
Equation must be an f64vector of size 4, specifying four
coefficients of the plane equation, Ax + By + Cz + D = 0
.
Returns the four coefficients of the equation of clipping plane plane, in f64vector.
Sets the parameters and function for the fog effect. Possible values for pname and accepted param for each pname are shown below.
GL_FOG_MODE
Either GL_EXP
, GL_EXP2
, GL_LINEAR
to select
the fog factors.
GL_FOG_DENSITY
GL_FOG_START
GL_FO_END
A real number to specify those parametes.
GL_FOG_COLOR
An f32vector of size 4 to specify the color.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Speficies whether the modelview, projection, or texture matrix will be modified. Mode can be one of the followings:
GL_MODELVIEW
GL_PROJECTION
GL_TEXTURE
Loads an identity matrix to the current modifiable matrix.
Loads the matrix mat to the current modifiable matrix.
Mat can be a <matrix4f>
instance, or
f32 or f64vector of length 16.
Multiplies the matrix mat to the current modifiable matrix.
Mat can be a <matrix4f>
instance, or
f32 or f64vector of length 16.
Multiplies the current matrix by a matrix taht translates
an object by (x, y, z).
Internally, glTranslated
is called.
Multiplies the current matrix by a matrix that rotates
an object in a counterclockwise direction about the ray
from the origin through the point (x, y, z)
by angle degrees.
Internally, glRotated
is called.
Multiplies the current matrix by a matrix that scales
an object by (x, y, z).
Internally, glScaled
is called.
Defines a viewing matrix and multiplies it to the right of the current matrix.
Creates a matrix for a perspective-view frustum and multiplies the current matrix by it.
Creates a matrix for a symmetrix perspective-view frustum and multiplies the current matrix by it.
Creates a matrix for an orthographic parallel viewing volume nand multiplies the current matrix by it.
Convenience procedure for 2D drawing; it is the same as gl-ortho
except nearv and farv are fixed (along Z axis) to -1.0 and 1.0, respectively.
Defines a pixel rectangle in the window into which the final image is mapped.
Pushes/pops the current matrix.
A convenience macro. Pushes the current matrix, executes exprs, then pop the current matrix.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Allocates range number of contiguous display list indices. Returns an integer which is the smallest display list index you can use.
Starts a display list construction. Mode may be
one of the constants GL_COMPILE
or GL_COMPILE_AND_EXECUTE
.
Ends a display list construction.
Calls a display list.
Returns #t
if list-no is an already used display list number,
#f
otherwise.
Deletes range display list, beginning from list-no-start.
Specifies the offset that’s added to the display list indices in
gl-call-list
.
Executes size display list, whose indices are contained in lists. You can pass a u8, s8, u16, s16, u32, s32 or f32vector, or a string, as lists. If it is a string, each byte consists of the string is interpreted as an unsigned integer specifying a display list. It is useful for the technique to display character strings by creating display lists for each ASCII characters. But be aware that it doesn’t work for multibyte characters.
Usually you can use the simplest form (the third form) and Gauche-gl infers the size and type from the passed lists. You can explicitly specify size if you want to use just a beginning portion of lists. An error is signalled if you specify size that is larger than the size of lists.
Specifying type is useful only if lists is a u8vector,
and you want to use one of three special types allowed to glCallLists
,
namely GL_2_BYTES
, GL_3_BYTES
, and GL_4_BYTES
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Scheme version of APIs doesn’t have GLenum type argument in C API, since Gauche-gl can figure out the type by passed vectors.
Scheme API of gl-*-array
has offset optional argument,
by which you can pass the GL the values beginning from the offset-th
element of the passed uniform vector. This isn’t in GL C API,
since you can just offset the pointer in C.
NOTE: it is caller’s responsibility to guarantee the passed vector has enough length. GL doesn’t have an interface to specify the boundary, so Gauche can’t detect an invalid length vector.
Sets the vertex array. Size specifies the number of
scalar values per vertex (2, 3, or 4), and vec provides
the actual value in either f32, f64, s32 or s16vector.
Stride
and offset can be used to tell GL to
access vec sparsely.
Sets the normal array. Vec should be either
a f32, f64, s32 or s16vector, where each consecutive triplet
specifies a normal vector.
Stride
and offset can be used to tell GL to
access vec sparsely.
Sets the color array. Size specifies the number of
scalar values per color (3 or 4), and vec provides
the actual values in either f32, f64, u32, u16, u8, s32, s16, or s8vector.
Stride
and offset can be used to tell GL to
access vec sparsely.
Sets the index array. Vec can be either s32, s16, u8, f32, or
f64vector.
Stride
and offset can be used to tell GL to
access vec sparsely.
Sets the texture coordinate array. Size specifies the
number of scalar values per texture coordinate (1, 2, 3 or 4),
and vec provides the actual values in either f32, f64, s32 or
s16vector.
Stride
and offset can be used to tell GL to
access vec sparsely.
Sets the edge flag array. Vec must be a GL boolean vector.
Stride
and offset can be used to tell GL to
access vec sparsely.
Dereference ith vertex information of the currently enabled arrays.
Issues geometric primitive calls consists of the vertex information of the currently enabled arrays, each of which is specified by indices, which should be either a u8, u16 or u32vector.
Mode is the same as of gl-begin
.
[GL1.2] Like gl-draw-elements
, but limits the range of indices
between start and end, inclusive. GL driver may take
advantage of the information for better performance.
This is more straightforward. Starting from first index,
count vertices is wrtten in the drawing mode mode
(same as of gl-begin
), taken from the current enabled arrays.
Vec must be a f32vector. It contains various information (e.g. vertex position, color and texture coordinate) interleaved, in the way specified by format.
In Scheme API, we only allow uniform vector as vec, so
you can’t use the format that mixes float and integer, such as
GL_C4UB_V2F
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Sets the shading model, either GL_SMOOTH
or GL_FLAT
.
Creates a light specified by light, which is
one of GL_LIGHT0
, …, GL_LIGHT7
,
and sets a characteristics named by pname with the value param.
Possible values as pname and acceptable types of param are as follows.
GL_AMBIENT
, GL_DIFFUSE
, GL_SPECULAR
, GL_POSITION
Accepts an f32 or s32vector of size 4.
GL_SPOT_DIRECTION
Accepts an f32 or s32vector of size 3.
GL_SPOT_EXPONENT
, GL_SPOT_CUTOFF
, GL_CONSTNAT_ATTENUATION
, GL_LINEAR_ATTENUATION
, GL_QUADRATIC_ATTENUATION
Accepts a real number (glLightf
is used).
Returns the value of the property pname of the light light. Returned value can be f32vector or a real number.
Sets the value of the property pname of the lighting model. Possible pname and its allowed param is as follows.
GL_LIGHT_MODEL_AMBIENT
Accepts f32 or s32vector of size 4.
GL_LIGHT_MODEL_LOCAL_VIEWER
, GL_LIGHT_MODEL_TWO_SIDE
Accepts any Scheme value, which is interpreted as a boolean value.
(That is, you have to pass #f
to turn off these properties,
and any other value to turn on.
GL_LIGHT_MODEL_COLOR_CONTROL
Accepts an enum value either GL_SINGLE_COLOR
or
GL_SEPARATE_SPECULAR_COLOR
.
Sets the current material property. Face may be either
GL_FRONT
, GL_BACK
, or GL_FRONT_AND_BACK
.
Possible values of pname and acceptable param types are
as follows.
GL_AMBIENT
, GL_DIFFUSE
, GL_AMBIENT_AND_DIFFUSE
, GL_SPECULAR
, GL_EMISSION
Accepts f32 or s32vector of size 4.
GL_SHININESS
Accepts a single real number (glMaterialf
is called).
GL_COLOR_INDEXES
Accepts f32 or s32vector of size 3.
Returns the current material property of face and pname.
The type of returned value may be f32vector, s32vector (only for
GL_COLOR_INDEXES
), or a real number.
Makes the material property mode (e.g. GL_AMBIENT
etc.)
of the face face follow the current color set by gl-color
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Draws a bitmap. Width and height gives the dimension of the bitmap. Xbo, ybo, xbi, and ybi specifies the origin and increment of the current raster position. Bitmap is the actual bitmap data, packed in a u8vector.
Reads pixel data from the framebuffer. Returns the pixel data in a uniform vector of the type determined by format and type (check out OpenGL doc to find out the actual data format).
Draws a pixel data pixels at the current raster position. Pixels must be a uniform vector compatible to the specified format and type values.
Copies pixel data in a rectangle area of the framebuffer,
specified by lower-left corner (x, y) and dimensions
(width, height). Buffer specifies which buffer
is used, and should be one of GL_COLOR
, GL_STENCIL
or GL_DEPTH
.
Sets the pixel stroage models. Check out the OpenGL doc for the possible pname and param values.
Sets the pixel transfer modes. Check out the OpenGL doc for the possible pname and param values.
Sets the pixel map table map with values, which must be either u16, u32 or f32vecotor. Check out the OpenGL doc for the possible map values.
Sets the magnification/reduction factors for pixel-write operations.
Returns the current pixel map table as an uniform vector specified
by type, which must be either a class <u32vector>
(default),
<u16vector>
, or <f32vector>
.
Like gl-get-pixel-map
, but instead of allocating a new vector,
it stores the result to a uniform vector passed to values.
It is a caller’s responsibility to ensure values has enough size.
[GL_ARB_imaging] Specifies one of the color table target. Data should be a uniform vector compatible to the format and type parameters.
[GL_ARB_imaging]
Sets the color table parameter pname
(either GL_COLOR_TABLE_SCALE
or GL_COLOR_TABLE_BIAS
),
of the color table target. Param must be
an f32 or s32vector of size 4.
[GL_ARB_imaging]
Creates a color table target using framebuffer data.
The pixels are
read from the current buffer for read (specified by glReadBuffer
).
[GL_ARB_imaging] Replaces a part of color table target, starting start and count entries. Values are given in data as a uniform vector compatible to the format and type arguments.
[GL_ARB_imaging] Replaces a part of color table entries using framebuffer data.
[GL_ARB_imaging] Reads the color table target and store it in data, in the format specified by format and type. Data must be a uniform vector compatible to the format and type arguments. The caller must ensure that data has enough size to contain the result.
[GL_ARB_imaging]
Defines a 2D convolution filter. Target must be GL_CONVOLUTION_2D.
Data
must be a uniform vector
compatible to the format and type arguments, and must have
enough size.
[GL_ARB_imaging] Defines a 2D convolution filter, taking the convolution filter data from the current color buffer to read.
[GL_ARB_imaging] Defines a 2D convolution filter by a product of a 1D row vector and 1D column vector. Target must be GL_SEPARABLE_2D. Both row and column must be a uniform vector, compatible with the format and type arguments, and must have enough size.
[GL_ARB_imaging]
Defines 1D convolution filter. Target must be GL_CONVOLUTION_1D.
Data
must be a uniform vector
compatible to the format and type arguments, and must have
enough size.
[GL_ARB_imaging] Defines 1D convolution filter, taking the convolution filter data from the current color buffer to read.
[GL_ARB_imaging]
Sets a parameter for a convolution filter target, which can
be either GL_CONVOLUTION_2D
, GL_SEPARABLE_2D
,
or GL_CONVOLUTION_1D
. Possible values of pname and
their acceptable param are as follows.
GL_CONVOLUTION_BORDER_MODE
Either one of the constants: GL_REDUCE
, GL_CONSTNAT_BORDER
,
GL_REPLICATE_BORDER
GL_CONVOLUTION_FILTER_SCALE
, GL_CONVOLUTION_FILTER_BIAS
An s32 or f32vector of size 4, specifying color values.
[GL_ARB_imaging]
Specifies the way the histogram data is stored.
Target must be either GL_HISTOGRAM
or GL_PROXY_HISTOGRAM
.
Width is the number of entires of the histogram, and has to be
a power of 2.
Sink is a boolean value to indicate whether pixels should be
discarded or sent down further to the pipeline.
[GL_ARB_imaging]
Resets the histogram counters. Target must be GL_HISTOGRAM
.
[GL_ARB_imaging] Returns histogram data in a uniform vector, whose type and size are determined by format and type. A boolean value reset specifies whether the histogram should be reset or not.
[GL_ARB_imaging]
Returns the parameter value of the histogram.
Pname can be either one of GL_HISTOGRAM_WIDTH
,
GL_HISTOGRAM_FORMAT
, GL_HISTOGRAM_RED_SIZE
,
GL_HISTOGRAM_GREEN_SIZE
, GL_HISTOGRAM_BLUE_SIZE
,
GL_HISTOGRAM_ALPHA_SIZE
, GL_HISTOGRAM_LUMINANCE_SIZE
,
or GL_HISTOGRAM_SINK
. The returned value is an integer,
except the case of GL_HISTOGRAM_SINK
, which returns a boolean value.
[GL_ARB_imaging]
Computes the minimum and maximum pixel values for an image.
Target must be GL_MINMAX
.
Sink is a boolean value to indicate whether pixels should be
discarded or sent down further to the pipeline.
[GL_ARB_imaging] Returns the results of the minmax operation in a uniform vector, whose type and size are determined by the format and type arguments. A boolean value reset specifies whether the histogram should be reset or not.
[GL_ARB_imaging] Resets the minmax counter.
[GL_ARB_imaging]
Returns the parameter value of the histogram.
Pname can be either GL_MINMAX_SINK
(returns
a boolean value) or GL_MINMAX_FORMAT
(returns an integer).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Defines an 1D, 2D or 3D texture. 3D texture is available only
if the GL version is 1.2 or later.
The target parameter can be GL_TEXTURE_1D
or
GL_PROXY_TEXTURE_1D
for gl-tex-image-1d
, etc.
The level parameter can be used for multiresolution textures; if
this is a single resolution texture, pass 0.
Width, height, and depth specify the dimensions of the texture. Border can be 0 or 1, specifying the border.
The actual texture data is passed to the texels argument in a uniform vector, which should be compatible with the format and type parameters and match the size calculated by width, height and depth (and possibly the pixel store setting).
Cerates a 1D or 2D texture from the framebuffer data.
Replaces a part of the current 1D, 2D or 3D texture image by texels. 3D texture is available only if the GL version is 1.2 or later.
Replaces a part of the current 1D, 2D or 3D texture image by the data from the framebuffer. 3D texture is available only if the GL version is 1.2 or later.
Sets parameters for the current texture.
Target can be either GL_TEXTURE_1D, GL_TEXTURE_2D
or
GL_TEXTURE_3D. Possible values for pname, and accepted
type of param for each pname, are shown below.
GL_TEXTURE_WRAP_S
GL_TEXTURE_WRAP_T
GL_TEXTURE_WRAP_R
GL_TEXTURE_BASE_LEVEL
GL_TEXTURE_MAX_LEVEL
GL_TEXTURE_MAG_FILTER
GL_TEXTURE_MIN_FILTER
Param must be an integer.
GL_TEXTURE_PRIORITY
GL_TEXTURE_MIN_LOD
GL_TEXTURE_MAX_LOD
Param must be a real number.
GL_TEXTURE_BORDER_COLOR
Param must be an f32vector of size 4, representing a color.
Obtains the parameter of the current texture, set by gl-tex-parameter
.
Obtains the parameter of the level level
of the current texture specified by target,
which can be either GL_TEXTURE_1D
, GL_TEXTURE_2D
,
GL_TEXTURE_3D
, GL_PROXY_TEXTURE_1D
,
GL_PROXY_TEXTURE_2D
, or GL_PROXY_TEXTURE_3D
.
Possible values for pname is either one of the
following constants: GL_TEXTURE_WIDTH
, GL_TEXTURE_HEIGHT
,
GL_TEXTURE_DEPTH
, GL_TEXTURE_BORDER
,
GL_TEXTURE_INTERNAL_FORMAT
, GL_TEXTURE_RED_SIZE
,
GL_TEXTURE_GREEN_SIZE
, GL_TEXTURE_BLUE_SIZE
,
GL_TEXTURE_ALPHA_SIZE
, GL_TEXTURE_LUMINANCE_SIZE
, or
GL_TEXTURE_INTENSITY_SIZE
. This procedure returns an integer.
Constructs a serids of mipmaps and calls gl-tex-image-*d
to load
the images. Returns 0 on success, or a GLU error code on failure.
Texels is a uniform vector, that must be compatible with
format and type arguments, and must have the enough length
as specified by width, height and depth parameters.
Like glu-build-*d-mipmaps
, but you can specify the level of
texels, and the range of levels to be generated
by the base and max parameters. It is used to generate
a subset of mipmaps.
Returns 0 on success, or a GLU error code on failure. Texels is a uniform vector, that must be compatible with format and type arguments, and must have the enough length as specified by width, height and depth parameters.
Returns size new names for texture objects in a u32vector.
Returns #t
if an integer name is the name of a texture
that has been bound and not deleted yet, #f
otherwise.
Bind the current texture (specified by target,
e.g. GL_TEXTURE_2D
) to the integer name.
If there’s already a texture bound to name, it becomes current.
Otherwise a new texture object is created and made current.
Delets textures. Names must be a u32vector contains integer names of the texture objects to be deleted.
Names must be a u32vector contains integer names
of the texture objects, and residences must be a GL boolean vector
of the same length as names. If all textures named in names
are resident, #t
is returned and residences is not
modified. Othewise, #f
is returned and
residences is modified to contain #t
if the corresponding
texture in names is resident, #f
othewise.
Sets the prioridies of texture objects named by names to the corresponding entry of priorities Names must be a u32vectore and priorities must be an f32vector, and the lengths of both vectors must match.
Sets the current texturing function. Target must be
GL_TEXTURE_ENV
. Possible values of pname and accepted
param for each value is as follows.
GL_TEXTURE_ENV_MODE
One of GL_DECAL
, GL_REPLACE
, GL_MODULATE
or
GL_BLEND
.
GL_TEXTURE_ENV_COLOR
f32vector of size 4 to specify the color.
Specifies the functions for automatic texture coordinate generation.
Coord specifies the coordinates, either one of GL_S
,
GL_T
, GL_R
or GL_Q
.
Possible values of pname and accepted
param for each value is as follows.
GL_TEXTURE_GEN_MODE
Either GL_OBJECT_LINEAR
, GL_EYE_LINEAR
or
GL_SPHERE_MAP
.
GL_OBJECT_PLANE
GL_EYE_PLANE
An s32, f32 or f64vector of size 4 to specify the plane.
[GL_ARB_multitexture]
Selects the texture unit that is currently modified by
texturing routines. Texunit is a constant
GL_TEXTUREi_ARB
, where i is 0 to the maximum
number of the supported texture units.
[GL_ARB_multitexture] Specifies the texture coordinate of the texture unit texunit. In the first form, you can pass either an f32, f64, s32, or s16vector of length 1 to 4. In the second form, s, t, r and q must be real numbers.
Selects the current texture unit for specifying texutre-coordinate data with vertex arrays.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Sets the current clearing color.
Each color value sould be a real number, and is clamped to
[0.0,1.0]
.
Sets the current clearing color (in color index mode). c must be a real number.
Sets the current clearing depth value.
Depth must be a real number and clamped to [0.0,1.0]
.
Sets the current clearing value of the stencil buffer.
Sets the current clearing value of accumulation buffer.
Clears the specified buffer. Mask is a logical-or of the following constants.
GL_COLOR_BUFFER_BIT
GL_DEPTH_BUFFER_BIT
GL_ACCUM_BUFFER_BIT
GL_STENCIL_BUFFER_BIT
Selects (a) buffer(s) to which the image is rendered.
Possible mode values are: GL_FRONT
,
GL_FRONT_LEFT
, GL_FRONT_RIGHT
,
GL_BACK
, GL_BACK_LEFT, GL_BACK_RIGHT,
GL_LEFT
, GL_RIGHT
, GL_AUXi
,
GL_FRONT_AND_BACK
, and GL_NONE
.
Selects a color buffer as the source for reading pixels.
Possible mode values are the same as gl-draw-buffer
except GL_FRONT_AND_BACK
and GL_NONE
.
In color index mode, sets the mask of the color-index buffer. Mask is an exact integer.
R, g, b and a are boolean values to specify whether the corresponding color channel should be written to the color buffer or not.
Flag is a boolean value specifies whether depth buffer should be written or not.
Sets the mask bit pattern for the stencil buffer. Mask is an exact integer.
Sets the scissor rectangle. If the scissor test is enabled
(use (gl-enable GL_SCISSOR_TEST)
), only the pixels that lie inside
the rectangle are written.
Sets the reference value and comparison function for the alpha test.
Func may be either one of GL_NEVER
, GL_ALWAYS
,
GL_LESS
, GL_LEQUAL
, GL_EQUAL
, GL_GEQUAL
,
GL_GREATER
, or GL_NOTEQUAL
. Ref sets the reference
value, a real number clamped to be between 0.0 and 1.0.
Sets the comparison function, the reference value, and a mask for
stencil test. Func specifies the funciton, and its possible
value is the same as gl-alpha-func
’s. Ref is an integer
reference value, and mask is an integer specifying bitwise mask.
Before the comparison, the reference value and the fragment value are
taken bitwise AND by mask.
Speficies how the stencil buffer should be modified by the result of
the stencil test. Each three parameter can take one of the following
values independently: GL_KEEP
, GL_ZERO
, GL_REPLACE
,
GL_INCR
, GL_DECR
, or GL_INVERT
.
Sets the comparison function for the depth test. Func may
be one of the following constant value: GL_NEVER
,
GL_ALWAYS
, GL_LESS
, GL_LEQUAL
, GL_EQUAL
,
GL_GEQUAL
, GL_GREATER
, or GL_NOTEQUAL
.
Defines an encoding for z-coordinates. Nearv and farv define the minimum and maximum values that can be stored in the depth buffer. By default, they’re 0.0 and 1.0, respectively.
Selects the logical operation to be performed, given an incoming
(source) fragment and the pixel currently in the color buffer
(destination). Opcode may be one of the following values:
GL_CLEAR
, GL_COPY
, GL_NOOP
, GL_SET
,
GL_COPY_INVERTED
, GL_INVERT
, GL_AND_REVERSE
,
GL_OR_REVERSE
, GL_AND
, GL_OR
, GL_NAND
,
GL_NOR
, GL_XOR
, GL_EQUIV
, GL_AND_INVERTED
or GL_OR_INVERTED
.
Sets the accumulation buffer operation mode. Op may be one of the following values:
GL_ACCUM
Reads each pixel from the current selected buffer to read
(by gl-read-buffer
), multiplies its values by value,
and adds the result into the accumulation buffer.
GL_LOAD
Same as GL_ACCUM
but replacing the accumulation buffer by
the result of multiplication, instead of adding it.
GL_RETURN
Takes the values from accumulation buffer, multiplies them with value,
then write it to the current color buffer to write (by gl-draw-buffer
).
GL_ADD
Adds value to each pixel in the accumulation buffer and write it back.
GL_MULT
Multiplies value to each pixel in the accumulation buffer and write it back. The result value is clamped to [-1.0, 1.0].
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[GL_ARB_shader_objects]
Creates a new shader object and returns its handle.
Type can be either GL_VERTEX_SHADER_ARB
or
GL_FRAGMENT_SHADER_ARB
.
[GL_ARB_shader_objects] Sets the source code of the shader, whose handle is shader. You can give the source code as a list of strings to strings. All strings are concatenated internally in the OpenGL driver.
[GL_ARB_shader_objects]
Compile the source code attached to the shader, whose handle is shader.
You can query the result of the compilation by passing
GL_OBJECT_COMPILE_STATUS_ARB
to gl-get-object-parameter-arb
;
it returns #t
if the compilation succeeded, or #f
if failed.
The information about the compilation can be obtained by
gl-get-info-log-arb
.
[GL_ARB_shader_objects] Creates a new program object and returns its handle.
[GL_ARB_shader_objects] Attach a shader whose handle is shader to the program whose handle is program.
[GL_ARB_shader_objects] Detach a shader from a program.
[GL_ARB_shader_objects]
Link the program object. The result of linking can be queried
by passing GL_OBJECT_LINK_STATUS_ARB
to
gl-get-object-parameter-arb
.
[GL_ARB_shader_objects] Installs the program to the current rendering state.
[GL_ARB_shader_objects] Deletes either a shader object or a program object specified by handle.
[GL_ARB_shader_objects]
Queries the value of pname of the shader or the program
specified by object. The following values are accepted
as pname: GL_OBJECT_TYPE_ARB
,
GL_OBJECT_SUBTYPE_ARB
,
GL_OBJECT_DELETE_STATUS_ARB
,
GL_OBJECT_COMPILE_STATUS_ARB
,
GL_OBJECT_LINK_STATUS_ARB
,
GL_OBJECT_VALIDATE_STATUS_ARB
,
GL_OBJECT_INFO_LOG_LENGTH_ARB
,
GL_OBJECT_ATTACHED_OBJECTS_ARB
,
GL_OBJECT_ACTIVE_ATTRIBUTES_ARB
,
GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB
,
GL_OBJECT_ACTIVE_UNIFORMS_ARB
,
GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB
, and
GL_OBJECT_SHADER_SOURCE_LENGTH_ARB
.
The procedure returns an integer value.
[GL_ARB_shader_objects] Returns the shader source code of a shader object shader in a string.
[GL_ARB_shader_objects] Returns the information log of an object pointed by handle.
[GL_ARB_shader_objects]
Returns the handle to an object that is used in the current state.
The only argument accepted currently as pname is
GL_PROGRAM_OBJECT_ARB
, which returns the handle to the current
program object.
[GL_ARB_shader_objects] Rethrns a vector of GL object handles that are attached to the program.
[GL_ARB_shader_objects] Checks whether the program can execute in the current GL state. The result is stored in program’s log.
[GL_ARB_vertex_program]
Sets the generic vertex attribute specified by index.
In the first form, you can pass f32, f64, or s16vector of size
1 to 4, or u8, s8, u16, s32, or u32vector of size 4.
In the second form, you can pass 1 to 4 real numbers (they
are interpreted as C doubles and glVertexAttrib4dARB
is called).
[GL_ARB_vertex_program]
These variations can be used to pass normalized values.
The first form accepts s8, u8, s16, u16, s32, u32, f32 and f64vector
of size 4. The second value takes four integers, whose lower 8bits
are taken as unsigned byte and passed to glVertexAttrib4NubARB
.
[GL_ARB_vertex_program] This is the generic version of vertex arrays. Index names the attribute, size specifies the number of components (1, 2, 3 or 4), and vec is a uniform vector that contains the array of values.
The optional boolean normalized argument tells whether the
passed integer values should be mapped to normalized range (#t
or
taken as are #f
, default). The optional stride argument
specifies the gap between each set of values within vec.
The optional offset argument tells GL to take values beginning
from the offset-th element of vec.
[GL_ARB_vertex_program] Enable or disable a vertex attribute array specified by index.
[GL_ARB_vertex_shader] Associates a user-defined attribute variable in the program object program with an index-th generic vertex attribute. Name is a string of the name of user-defined attribute as appears in the shader program.
[GL_ARB_vertex_shader] Returns an integer index of the user-defined attribute name in the program. Must be called after program is linked.
[GL_ARB_vertex_shader] Obtains information about the index-th user-defined attribute in the program. Must be called after program is linked.
It returns three values: the size of the attribute (1, 2, 3 or 4),
the type of the attribute (an integer that matches one of the following
constants: GL_FLOAT
, GL_FLOAT_VEC2_ARB
,
GL_FLOAT_VEC3_ARB
, GL_FLOAT_VEC4_ARB
,
GL_FLOAT_MAT2_ARB
, GL_FLOAT_MAT3_ARB
, or
GL_FLOAT_MAT4_ARB
.), and
the name of the attribute.
[GL_ARB_shader_objects] Returns an integer location of the uniform variable name of the program program.
[GL_ARB_shader_objects]
Sets a value of the uniform variable specified by location.
gl-uniform1-arb sets a single component value (e.g. float
)
gl-uniform2-arb sets a double component value
(e.g. vec2
) etc.
The first form of each function takes either an s32vector or f32vector.
It can have a size multiple of the number of components to
set an array uniform variable (e.g. you can pass an f32vector of
size 8 to fill vec2[2]
).
The second form just sets the component(s) of a single uniform variable.
The arguments v0 to v3 must be real numbers, and
coerced to C float
(i.e. glUniform*fARB
is used).
[GL_ARB_shader_objects] Sets a matrix uniform variable (or an array of matrix uniform variables) specified by location. A boolean flag transpose specifies whether the matrix should be transposed. The v argument must be a f32vector of size multiple of 4, 9, or 16, respectively.
[GL_ARB_shader_objects] Returns informaton about the index-th uniform variable of program.
Returns three values. The first one is the size, either 1, 2, 3 or 4.
The second value is the type, which is an integer that matches
one of the following constants: GL_FLOAT
,
GL_FLOAT_VEC(1|2|3|4)_ARB
, GL_INT
,
GL_INT_VEC(1|2|3|4)_ARB
, GL_BOOL
,
GL_BOOL_VEC(1|2|3|4)_ARB
, GL_FLOAT_MAT(2|3|4)_ARB
.
And the third value is the name of the uniform variable.
These APIs are for low-level vertex/fragment pipeline programming.
[GL_ARB_vertex_program] Generates N names (integers) for the new programs and returns them in an s32vector.
[GL_ARB_vertex_program] Deletes programs whose names are specified by an s32vector programs.
[GL_ARB_vertex_program]
Returns #t
if an integer prog-id refers to a valid program.
[GL_ARB_vertex_program]
Binds a program specified by prog-id to a target,
which is either GL_VERTEX_PROGRAM_ARB
or
GL_FRAGMENT_PROGRAM_ARB.
[GL_ARB_vertex_program]
Sets the source code of the program currently bound to the
target (GL_VERTEX_PROGRAM_ARB
or
GL_FRAGMENT_PROGRAM_ARB).
Format must be GL_PROGRAM_FORMAT_ASCII_ARB
.
Text is a string for the program source.
[GL_ARB_vertex_program]
Sets the value of the environment and local parameter
specified by param-id of the program currently bount to the target.
In the first form of each, args must be either f32 or
f64vector of size 4 or <vector4f>
object.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
5.1 GLUT window manipulation | ||
5.2 GLUT overlay | ||
5.3 GLUT menu API | ||
5.4 GLUT callbacks | ||
5.5 GLUT colormap | ||
5.6 GLUT state retrieval | ||
5.7 GLUT font | ||
5.8 GLUT pre-built models |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The module provides vector and matrix operations useful for 3D computer graphics.
Actually this module itself doesn’t depend on GL; you can use this module alone to do matrix calculations. However, the structure of objects are designed so that they can be passed directly to Gauche-gl functions, reducing the overhead of type conversions.
The purpose of this module is to provide reasonable performance.
So the operations are fixed to 3D homogeneous coordinates,
i.e. a vector is 4-element column vector, and a matrix is 4x4
square matrix. If you want more flexibility, <array>
class in gauche.array
provides much more generic
structures, trading performance.
Elements of vectors and matrices are represented in float
internally. When you retrieve each element individually,
it is converted to double
, so you might see some precision
errors. There are lots of operations directly manipulate group of
elements without retrieving each element to Scheme world, avoiding
overhead of conversion.
6.1 Vectors and points | ||
6.2 Vector arrays and point arrays | ||
6.3 Matrices | ||
6.4 Quaternions |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4x1 column vectors. Vector4f
is intended to be used
to represent a vector, and point4f
is to a point,
but as far as OpenGL concerns, both are just an array of four floats,
x, y, z and w.
These classes inherit <sequence>
and <collection>
classes. So if you import gauche.sequence
module,
you can use generic function such as ref
and (setter ref)
to get/set individual elements. The generic version of
map
and for-each
can also be used on the vector4f and
point4f instances.
Aside from the type, the only difference is that the default value of w component— it’s 0.0 for vectors, and 1.0 for points. So usual transformation produces expected results; for example point plus vector becomes point, vector plus vector becomes vector, and translating point changes its coordinates but translating vectors doesn’t, and so on. However, you can set w component to other value to do nontrivial operations.
#,(vector4f x y z w)
#,(point4f x y z w)
These SRFI-10 syntax can be used to denote literal <vector4f>
and <point4f>
instance, respectively.
The write methods are defined so that the instance is written out in this form, and can be read back later.
Returns true iff obj is vector4f and point4f, respectively.
Creates a vector4f and point4f instance with given values, respectively.
Another way to create a vector4f and a point4f.
The first returns #,(vector4f 0.0 0.0 0.0 0.0)
,
and the latter returns #,(point4f 0.0 0.0 0.0 1.0)
.
Convert a list of three or four real numbers to a vector4f and a point4f, respectively. If l is not a list of three or four real numbers, an error is signalled.
(list->vector4f l) ≡ (apply vector4f l) ≡ (coerce-to <vector4f> l) |
Convert a vector4f and a point4f to a list of four real numbers, respectively.
(vector4f->list v) ≡ (coerce-to <list> v) ≡ (map (cut ref v <>) (iota 4)) |
Creates a vector4f or a point4f, initializing by the elements of f32vector v. V must be at least 4 elements long, and the first four elements are used to initialize the created vector or point.
If optional start argument is given, it specifies an index of v from which the initial values are taken; that is, start, start+1, start+2 and start+3-th elements are used to create a vector or a point. This allows to create vectors from plain float array:
(map (lambda (off) (f32vector->vector4f vec (* off 4))) (iota (/ (size-of vec) 4))) |
The conversion can be done using coerce-to
, as well.
(f32vector->vector4f vec) ≡ (coerce-to <vector4f> vec) |
Convert a vector4f v or a point4f p to four-element f32vector.
(vector4f->f32vector v) ≡ (coerce-to <f32vector> v) |
Returns a new copy of vector4f v or point4f p, respectively.
Destructively sets the content of srcv or srcp to dstv or dstp, respectively.
Sets a real number value to k-th element of a vector4f v or a point4f p.
(vector4f-set! v k value) ≡ (set! (ref v k) value) |
Gets a value of k-th element of a vector4f v or a point4f p. If k is out of range, an error is signalled, unless fallback is provided, in such a case fallback is returned.
(vector4f-ref v k) ≡ (ref v k) |
Returns a dot product of two vector4fs, x and y.
Returns a cross product of two vector4fs, x and y. (w element is ignored).
Returns the norm (length) of the vector v.
Returns a normalized vector of vector4f x.
Vector4f-normalize
allocates a new vector, while
vector4f-normalize!
modifies the original vector.
As a special case, if x is a vector of length 0, a vector of length 0 is returned.
Returns a sum of two vector4fs, x and y. The destructive version modifies x.
Adds a point4f x and a vector4f y, and returns a translated point. The destructive version modifies x.
Subtracts either a vector4f or a point4f y from a point4f x. If y is a vector4f, returns a translated point. If y is a point4f, returns a vector4f from point y to point x.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Represents an array of vector4fs and point4fs.
This is an efficient way to keep an array of vectors or points,
for the elements are packed in a simple float array.
They are especially useful to work with GL’s vertex array feature.
gl-vertex-pointer
can take <point4f-array>
,
and gl-normal-pointer
can take <vector4f-array>
.
It is also possible to "view" a plain f32vector as <vector4f-array>
or <point4f-array>
without copying its content, by
f32vector->vector4f-array/shared
and
f32vector->point4f-array/shared
. Combined to
read-block!
, you can do efficient binary I/O of
vertex arrays, for example.
Inherits <sequence>
and <collection>
.
When viewed as a sequence or a collection, they behaves like
sequence or collection of vector4f
and point4f
objects,
respectively.
Creates a vector4f-array or point4f-array with len elements. Each element is initialized by a vector4f init-vector or a point4f init-point if provided.
Returns true iff obj is a vector4f-array or a point4f-array, respectively.
Returns length (number of vectors/points) in array array.
#,(vector4f-array len elt …)
#,(point4f-array len elt …)
Vector4f-array and point4f-array have external representation using this SRFI-10 syntax. Len is a length of array, and each elt is a list of four floats representing each element of the array.
(f32vector->vector4f-array #f32(1 2 3 4 6 7 4 3)) ⇒ #,(vector4f-array 2 (1 2 3 4) (6 7 4 3) ) |
From given list of vector4fs or point4fs, creates and returns a vector4f-array or point4f-array, respectively.
Converts f32vector v to a vector4f-array or a point4f-array. The length of v must be multiple of four. The content of v is copied.
(f32vector->vector4f-array v) ≡ (coerce-to <vector4f-array> v) |
Like above, but the content of v is shared by the result array, instead of being copied. So the modification of result array will be visible from original f32vector v and vice versa. It will allow efficient handling of large vertex arrays.
Converts a vector4f-array or a point4f-array array to a f32vector.
(vector4f-array->f32vector array) ≡ (coerce-to <f32vector> array) |
Sets a vector4f vector or a point4f point to i-th element of vector4f-array or point4f-array array, respectively.
(vector4f-array-set! array i vector) ≡ (set! (ref array i) vector) |
Returns a vector4f or a point4f which is the i-th element of array array, respectively. If k is out of range, an error is signalled, unless fallback is provided, in such a case fallback is returned.
(vector4f-array-ref array i) ≡ (ref array i) (ref #,(vector4f-array 2 (1 2 3 4) (6 7 4 3)) 1) ⇒ #,(vector4f 6 7 4 3) |
Like above, but the returned vector4f or point4f shares the storage with the original array. Thus the modification of the result vector or point will be visible from array, and vice versa.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4x4 matrix. Internally it is represented as an array of 16 floats, stored in column-major order. (It is the same order OpenGL uses, so it can be passed to OpenGL calls without overhead).
Inherits <sequence>
and <collection>
.
When a matrix4f is treated as a sequence, it works as if it is
a single sequence of floats in column-major order.
Returns a new matrix4f instance. If init is omitted, the matrix is a unit matrix. Otherwise, init must be a f32vector of length 16, and the elements in the matrix is initialized by ones in f32vector.
;; Creates a matrix like this: ;; 1 2 3 4 ;; 0 1 0 5 ;; 0 0 1 6 ;; 0 0 0 1 (make-matrix4f '#f32vector(1 0 0 0 2 1 0 0 3 0 1 0 4 5 6 1)) |
Creates a new matrix4f instance with give values.
Returns true iff obj is a matrix4f.
#,(matrix4f elt …)
A matrix4f is represented extrenally using SRFI-10 syntax. The elements are listed in column-major order.
Converts between list of 16 real numbers and matrix4f.
Creates a new matrix4f and initializes it with 16 elements in f32vector v. If optional start is given, it specifies the start offset in vector v to be used as initial values. The f32vector v must have enough length.
Extract 16 flonums in the f32vector v starting from the index start, and fill the matrix4f m with them. The f32vector v must have enough length.
Returns a new f32vector that has elements from matrix4f m.
Returns a new copy of m.
Copies contents of srcm to dstm.
Sets a real number value to i-th element of matrix m.
Since the matrix is laid out in column-major order,
the one-dimensional index m{i}
and two-dimensional
index m(i,j)
corresponds as follows:
m(0,0) = m{0} m(0,1) = m{4} m(0,2) = m{8} m(0,3) = m{12} m(1,0) = m{1} m(1,1) = m{5} m(1,2) = m{9} m(1,3) = m{13} m(2,0) = m{2} m(2,1) = m{6} m(2,2) = m{10} m(2,3) = m{14} m(3,0) = m{3} m(3,1) = m{7} m(3,2) = m{11} m(3,3) = m{15} |
Returns the i-th element of matrix m. If i is out of range, an error is signalled, unless fallback is provided, in such a case fallback is returned.
Sets value to (i, j)
element of matrix m.
Returns the (i, j)
element of matrix m.
Returns i-th row vector or i-th column vector of matrix m, as a vector4f instance.
Furthermore, the returned vector from matrix4f-column/shared
shares the storage with m
.
Obj may be a scalar (real number), a vector4f, a point4f, or a matrix4f. Returns m x obj.
Obj may be a scalar or a matrix4f. Matrix m is multiplied by obj, and the result is set to m destructively.
Returns a transposed matrix of m. The destructive version modifies m.
Returns a determinant of m.
Returns a inverse matrix of m. The destructive version
modifies m. If given m is a singular matrix,
an error is signalled by default. However, if #f
is given
to the optional error-on-singular? argument,
#f
is returned in such a case.
Returns a matrix which represents a translation by translation-vector, which must be either a vector4f, a point4f, or a f32vector of length 3 or 4. Only the first three elements in translation-vector is used. The destructive version updates m.
Returns a matrix which represents a rotation around axis by angle radian. Axis must be a vector4f or a f32vector of length 3 or 4, and must be normalized. The result is undefined if anormalized vector is passed as axis. The destructive version updates m.
Returns a matrix which represents a scale by scale-vector, which must be either a vector4f, a point4f, or a f32vector of length 3 or 4. Only the first three elements in scale-vector is used. Each element of scale-vector represents the scale factor along x, y, and z axis. The destructive version updates m.
This combines above three procedure. Returns a matrix that represents translation, rotation and scale, specified by translation, rotation-axis, rotation-angle and scale. The destructive version updates m.
If T
, R
and S
, are
the matrices that represent translation, rotation and scale, respectively,
then these procedures effectively calculates
a matrix TRS
.
A variation of trs->matrix4f
. Instead of axis and angle,
rotation is represented by a quaternion rotation-quat.
See section Quaternions, for more details about quaternions.
Returns a matrix that represents rotation along x, y and z axis by xangle, yangle, and zangle, respectively.
The order of rotation can be specified by the optional argument
order, which may be one of the symbols xyz
, xzy
,
yzx
, yxz
, zxy
, or zyx
. For example,
symbol xyz
means rotation around x-axis, then y-axis, then
z-axis. Thus, if we write each rotation as Rx, Ry, and
Rz, the returned matrix is RzRyRx.
The default value of order is xyz
.
The desrtuctive version modifies m.
Matrix m is a composition of translation, rotation, shear and scale. Suppose transformation is applied in the reverse order. This procedure decompose m into each individual transformation.
Returns five values.
If m is singular, certain part of rotation matrix can’t be recovered. In such a case, r becomes also singular matrix.
If the original matrix has negative scale factor in any of x, y, or z scale, the decomposed scale factor will have all negative components. The signs of elements of r are adjusted accordingly.
Due to the precision errors, you will see small values appear in shear component even m is pure TRS matrix.
Linear update version of matrix4f-decompose
.
The result vectors and matrices are stored in t, r, h
and s. The return value is a boolean value indicates
m is non-singular or not.
Extract the translation component from the given TRS matrix m
and returns it as a <vector4f>
.
Extract the translation component from the given TRS matrix m
and stores the result into a <vector4f>
v.
Returns v.
From given orthogonal matrix m, extracts and returns and rotation axis and angle, as a vector4f and a real number.
Same as above, except the storage of vector4f v is reused to store the result axis.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Quaternions. Internally quaternions are represented as just an array of four floats; the first three are the vector component and the last is the scalar component.
Inherits <sequence>
and <collection>
. When viewed
as sequence, it is just like a vector of four floats.
Returns true iff obj is a quaternion.
#,(quatf x y z w)
External representation of quaternion xi+yj+zk+w.
Returns a new unit quaternion that represents a rotation around vector axis by angle radians. Axis can be a vector4f, a point4f or a f32vector (only first three component is used). Axis must be a unit vector; if axis is anormalized, the result is undefined.
If both axis and angle is omitted,
#,(quatf 0 0 0 1)
is returned.
Returns a new quaternion whose elements are initialized by x, y, z, w.
Converts between a list of four real numbers and a quaternion.
Returns a new quaternion whose elements are initialized by the first four elements of f32vector x. If start is given, the initial value is taken starting from start-th index in x.
Returns a new f32vector whose contents is the same as a quaternion q.
Returns a fresh copy of a quaternion q.
Copies contents of a quaternion srcq to a quaternion dstq.
Sets a quaternion quat so that it represents a rotation around a unit vector axis by angle angle radians. Axis can be a vector4f, a point4f or a f32vector (only first three component is used).
Given two unit vectors v and w, calculates and returns
a quaternion that represents a rotation from v to w.
The destructive version vectors->quatf!
modifies q.
The arguments must be all unit vectors, v1 and v2 must be perpendicular, and also w1 and w2 must be perpendicular.
Calculates and returns a quaternion that represents a rotation which transforms v1 to w1, and v2 to w2, respectively. The destructive version stores the result into q.
Addition and subtraction of quaternions. The destructive version modifies the first argument.
Multiplies a quaternion q by a scalar value s. The destructive version modifies q.
Multiply two quaternions p and q. The destructive version modifies p as well.
Returns a conjugate of a quaternion p. The destructive version modifies q as well.
Transforms a vector or a point p by quaternion q, that is, returns qpq*, where q* is a conjugate of q.
This procedure assumes q is normalized.
P can be a vector4f, a point4f or a f32vector (only first three elements are used). Returns the same type of object as p.
Returns norm of q.
Returns normalized quaternion of q. The destructive version modifies q.
Returns a matrix that represents a rotation specified by a unit quaternion q. The behavior is undefined if q is not normalized. The destructive version modifies m.
Extracts the rotation component of a matrix m and
returns a quaterion that represents the rotation.
Matrix4f->quatf!
also uses q as the storage
to store the result.
Returns a quaternion that interpolates between two unit quaternions p and q, by a scalar value t. The destructive version modifies r.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter covers gl.simple.*
modules. They are
provided for the convenience of those who wants quick experiment
with Gauche-gl alone, without a hassle to install a bunch of
other modules. Their features are pretty limited, but you
may find them handy when you need to hack up some throwaway
script that need to show some graphics on the screen.
7.1 Simple image handling | ||
7.2 Simple viewer |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
OpenGL doesn’t provide any means of reading/writing image data, and it should be covered by other Gauche extensions. However, it is sometimes handy to have simple means to handle external image data, so that you can do some experiment with Gauche-gl alone.
This module provides a minimal support to handle external image data, so that one can do some experiment in Gauche-gl alone.
The functionality might be extended over time, but this is never intended to be a full featured image library. A separate Gauche extension should be a better place to have it.
Currently, only reading from 8bit SGI image file is supported. It is written in pure Scheme, so don’t expect the performance.
Reads an image data in SGI format from the named file or the input port, respectively.
Only 8bit-per-channel, direct color mode is supported.
Returns four values: the image’s width in pixels, its height in pixels, number of channels (e.g. 1 for grayscale, 3 for RGB, 4 for RGBA), and the image data in u8vector. The pixel data is packed, i.e. there’s no padding between each pixel nor each scanline.
Warning: be careful to call this function interactively. The image data vector is usually huge, and you have to wait long for the REPL to display the entire result.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This module packages common operations to allow users to view 3D objects, controlling the camera by the mouse, and have some interactions with the keyboard.
A typical way of using the viewer is like the following:
(use gl) (use gl.glut) (use gl.simple.viewer) (define (main args) (glut-init args) (simple-viewer-display <your-display-thunk>) (simple-viewer-set-key! <key> <handler> ...) (simple-viewer-window <name> :title <title> ...) (simple-viewer-run) ; loop forever. type ESC to exit. 0) |
The viewer handles mouse drag (to move the camera), and also draws reference grid and axes by default for your convenience. You have to provide a thunk, which must draw your 3D object.
For the keyboard events, you can use a convenient API
to associate handler to the key (character for normal keys,
and constants like GL_LEFT_ARROW
for special keys).
The reshape event is handled implicitly, though you can override it.
If you call simple-viewer-run
, it enters the event
loop and never returns. If you wish to keep REPL and/or
other parts of your application run concurrently,
the convenient way is to run simple-viewer-run
in a separate thread.
(use gauche.threads) (define (run-viewer) (thread-start! (make-thread simple-viewer-run #f))) |
See also the code under ‘examples/simple’ directory of the source tree for more examples.
Creates a new GL window with name, which must be a symbol
to identify the window later in the simple viewer framework.
The window won’t be shown until simple-viewer-run
is called.
Each window
Gets/sets the display thunk, which is called every time the GL window is redrawn. You can change the display thunk any time, even while the viewer thread is running.
If no argument is given, returns the current display thunk.
It can be #f
if no display thunk is set.
When the display thunk is called, the matrix mode is
MODELVIEW
and the camera transformation is already applied.
The grid and axes are also drawn, unless you’ve customized them.
In the display thunk you can just write your model in the world coordinate system. It is guaranteed that the current color is white and line width is 1.0, but the states of other GL contexts are undefined, so you have to set them explicitly.
Gets/sets the reshape procedure which is called every time the GL window configuration is changed. (It is also called when the GL window is shown first time.) You can change the reshape procedure any time, even while the viewer thread is running.
If no argument is given, returns the current reshape proc.
A reshape procedure is called with two arguments,
the width and the height (in pixels) of the new GL
window configuration. By default, gl.simple.viewer
sets a procedure that changes viewport and
projection matrix apopropriately; you need to change
it only if you want a different behavior.
Gets/sets a procedure to draw a grid and axes. You can change these procedures any time, even while the viewer thread is running.
The grid-proc and axis-proc are called with no arguments
every time the GL window is redrawn, before the display thunk
is invoked.
The matrix mode is MODELVIEW
, the camera transformation
is already applied, and lighting is disabled.
The default grid proc draws 10x10 grid on X-Z plane centered at the origin. The default axis proc draws a red line from origin to +X, a green line from origin to +Y, and a blue line from origin to +Z.
You can pass #f
to disable grid and/or axis display.
If no argument is given, returns the current grid/axis proc, respectively.
Even number of arguments must be given; the first of every two specifies the key, and the next one specifies the action when the key is pressed.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A.1 Function and Syntax Index | ||
A.2 Module Index | ||
A.3 Class Index | ||
A.4 Variable Index |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Jump to: | A E F G L M P Q R S T V |
---|
Jump to: | A E F G L M P Q R S T V |
---|
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Jump to: | G |
---|
Index Entry | Section | |
---|---|---|
| ||
G | ||
gl.math3d | 6. Vectors and matrices | |
gl.simple.image | 7.1 Simple image handling | |
gl.simple.viewer | 7.2 Simple viewer | |
|
Jump to: | G |
---|
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
For readability, the surrounding <
and >
are stripped off.
Jump to: | G M P Q V |
---|
Jump to: | G M P Q V |
---|
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Jump to: | G |
---|
Jump to: | G |
---|
[Top] | [Contents] | [Index] | [ ? ] |
[Top] | [Contents] | [Index] | [ ? ] |
This document was generated on August 9, 2014 using texi2html 1.82.
The buttons in the navigation panels have the following meaning:
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ < ] | Back | Previous section in reading order | 1.2.2 |
[ > ] | Forward | Next section in reading order | 1.2.4 |
[ << ] | FastBack | Beginning of this chapter or previous chapter | 1 |
[ Up ] | Up | Up section | 1.2 |
[ >> ] | FastForward | Next chapter | 2 |
[Top] | Top | Cover (top) of document | |
[Contents] | Contents | Table of contents | |
[Index] | Index | Index | |
[ ? ] | About | About (help) |
where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:
This document was generated on August 9, 2014 using texi2html 1.82.