Version 2.0.2, 2020-03-07
Boron-GL extends the Boron scripting language with datatypes and functions for working with OpenGL 3.3 & ES 3.1.
Features include:
This manual is largely incomplete.
There is a separate function reference available online at http://urlan.sourceforge.net/boron.
The first line of a script may be a UNIX shell sha-bang (#!
) command.
#!/usr/bin/boron-gl
Usage:
boron-gl [options] [script] [arguments]
-a | Disable audio |
-e “exp” | Evaluate expression |
-h | Show help and exit |
-p | Disable prompt and exit on exception |
-s | Disable security |
If the interpreter is invoked with a script then the args word will be set to either a block of strings, or none if no script arguments were given.
So this command:
boron-gl -e "probe args" file1 -p 2
Will print this:
["file1" "-p" "2"]
Type Name | Description |
---|---|
draw-prog! | Compiled draw program |
raster! | Pixel image in main memory |
texture! | OpenGL texture |
font! | Texture-based font |
shader! | OpenGL shader |
fbo! | OpenGL frame buffer object |
vbo! | OpenGL vertex buffer object |
quat! | Quaternion |
widget! | Widget |
A draw program is a list of display operations compiled to byte-code. It is reminiscent of the OpenGL 1.0 display list (now deprecated in OpenGL 3.0) but operates on modern elements such as shaders and vertex buffers.
NOTE: The terms draw program and draw list are used interchangeably.
The simplest way to make textures is to use the load-texture function.
load-texture %skin.png
Full specification:
make texture! [
raster!/coord!/int!
binary!
'mipmap 'nearest 'linear 'repeat 'clamp
'gray 'rgb' 'rgba
'depth
]
A texture-based font.
make font! [%font-file.ttf 20]
make font! [%font-file.ttf face 1 20 "characters" 256,128]
make font! [raster! binary!]
make font! [texture! binary!]
make shader! [
vertex {...}
fragment {...}
default []
]
A framebuffer object is a render target.
Vertex buffers hold arrays of geometry vertex attributes.
A unit-length quaternion.
Multiply a quat! by -1.0 to conjugate (invert) it. Multiplying a quat! by a vec3! will return a transformed vec3!.
Examples quaternions::
to-quat none ; Identity
to-quat 10,0,240 ; From euler x,y,z angles
In addition to the following instructions, any paren! value will be evaluated as Boron code at that point in the draw list.
Some instructions accept a get-word! argument. When this is used, the word value is read each time program is run rather than using a fixed value.
Draws a box given minimum and maximum extents. Internally, a vertex buffer with normals & texture coordinates is created.
box
min int!/decimal!/vec3!
max int!/decimal!/vec3!
Sets the blending mode using glBlendFunc.
blend
mode on/off/add/burn/trans
Mode | Function |
---|---|
on | glEnable( GL_BLEND ) |
off | glDisable( GL_BLEND ) |
add | glBlendFunc( GL_SRC_ALPHA, GL_ONE ) |
burn | glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) |
trans | glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) |
Calls glBindBuffer and sets pointer offsets using glVertexAttribPointer.
Currently only a single buffer command can be used between one or more primitive draw commands (tris, points, etc.).
Binds an array buffer like buffer, but also sets the glVertexAttribDivisor to 1 for use in instanced draws.
Currently buffer-inst must follow a buffer command.
Sets the camera context. glViewport is called and the GL_PROJECTION
and GL_MODELVIEW
matrices are set.
camera
which context!
Runs another draw program.
Calling a none! value does nothing and can be used to disable the display of an item.
call
list none!/draw-prog!/widget!/get-word!
Calls glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ).
Sets a shader vec4 uniform at layout(location = 1).
color
value int!/double!/coord!/vec3!/get-word!
The following all set the color to red (with alpha 1.0)::
color 0xff0000
color 255,0,0
color 1.0,0.0,0.0
It is recommended to use vec3!.
Grey values (with alpha 1.0) can be set using int!/double!.
Calls glColorMask with all GL_TRUE or GL_FALSE arguments.
color-mask on/off
Calls glEnable/glDisable with GL_CULL_FACE.
cull on/off
Calls glDepthMask with GL_TRUE/GL_FALSE.
depth-mask on/off
Sets the font for text instructions. This only provides the glyph metrics needed to generate quads; it does not actually emit any data into the compiled draw-prog. The shader instruction must be used to specify the texture.
font
which font!
Calls glBindFramebuffer with target GL_FRAMEBUFFER. Pass zero to restore rendering to the display.
framebuffer
which fbo! or 0
Display image at 1:1 texel to pixel scale. An optional X,Y position can be specified.
image [x,y] texture!
image x,y,w,h
image/horiz xmin,xmax,ycenter texture!
image/vert ymin,ymax,xcenter texture!
Controls lights.
Draw line primitives using glDrawElements with GL_LINES.
lines
elements int!/vector!
Draw line primitives using glDrawElements with GL_LINES.
line-strip
elements int!/vector!
Calls the equivalent of glPopMatrix.
Draw point primitives using glDrawArrays or glDrawElements with GL_POINTS.
points
elements int!/vector!
point-size on/off
point-sprite on/off
Calls the equivalent of glPushMatrix on the modelview stack.
Push (and multiply) a matrix onto the modelview stack and also copy the original matrix into a shader uniform.
Calls the equivalent of glPushMatrix, glMultMatrix & glUniformMatrix4fv.
push-model uniform-name :matrix-variable
Calls the equivalent of glPushMatrix followed by glMultMatrix on the modelview stack.
push-mul :matrix
Rotate around axis or by quaternion.
rotate x/y/z decimal!
rotate x/y/z get-word!
rotate get-word!
scale
value decimal!/get-word!
Calls glUseProgram, binds and enables any textures used, and calls glUniform for any variables.
shader
which shader!
Draws a sphere. Internally, a vertex buffer with normals & texture coordinates is created.
sphere
radius int!/decimal!
slices,stacks coord!
Draws quads for each character.
text x,y string!
text/center/right rect [x,y] string!
Using the center option centers the string horizontally and vertically within the rect argument. To center only horizontally use a width (fourth value) of zero.
Translate the model view matrix.
translate
distance vec3!/get-word!
Draw triangles primitives using glDrawElements with GL_TRIANGLES.
tris
elements int!/vector!
Draw triangles primitives using glDrawElements with GL_TRIANGLE_FAN.
tri-fan
elements int!/vector!
Draw triangles primitives using glDrawElements with GL_TRIANGLE_STRIP.
tri-strip
elements int!/vector!
Draw triangles primitives using glDrawElementsInstanced.
tris-inst
elements int!/vector!
count
Draw a single textured rectangle.
quad
tex-size int!/vector!
uvs coord!
area coord!
Draw quadrangle primitives (each as two triangles).
quads
elements int!/vector!
Set a shader uniform variable using glUniform or glBindTexture (for textures).
uniform
uniform-name word!
value logic!/int!/double!/vec3!/texture!
Transform a point into view space and assign this to a uniform using glUniform3fv.
view-uniform
uniform-name word!
point get-word! that references a vec3!.
/dir Treat point as a directional vector.
Using the dir option will only transform the point by the upper 3x3 portion of the view matrix.
expand | [minimum] |
---|---|
int! |
Fills as much space as possible to push other widgets against parent edges.
space | [weight minimum maximum] |
---|---|
int!/coord! |
Fill some space to leave a gap.
hbox | [margins] | [/center] | children |
---|---|---|---|
coord! | option! | block! |
vbox | [margins] | [/center] | children |
---|---|---|---|
coord! | option! | block! |
grid | size | [margins] | children |
---|---|---|---|
coord! | coord! | block! |
Size is colums,rows.
window | [name] | event-handler | children |
---|---|---|---|
string! | none!/block! | block! |
Free-floating movable window.
viewport | event-handler |
---|---|
block! |
overlay | layout | [margins] | [/center] | children |
---|---|---|---|---|
word! | coord! | option! | block! |
Place widgets over the parent area.
Layout is ’hbox or ’vbox.
button | label | action |
---|---|---|
string! | block! |
checkbox | label | action |
---|---|---|
string! | block! |
choice | options | [action] |
---|---|---|
block! | block! |
label | text |
---|---|
string! |
line-edit | text | [max-length] |
---|---|---|
string! | int! |
list | headers | items | [char-size] | [action] |
---|---|---|---|---|
int!/block! | block! | coord! | block! |
slider | [orient] | range | initial-value | [action] |
---|---|---|---|---|
word! | coord!/vec3! | int!/double! | block! |
Range is minimum,maximum.