Pixilang is a pixel-oriented programming language for small graphics/sound applications and experiments: demos, games, synths, etc.
Pixilang programs are stored in text files (UTF-8 encoding) with extensions .txt or .pixi. So you can use your favorite text editor to create/edit these files. Pixilang has no built-in editor.
A program can be a simple list of instructions with conditional jumps, without declaring entry points and functions. A blank area (screen) inside the Pixilang window is provided for any program. The screen can be accessed as an array of pixels.
pixilang [options] [filename] [arg]
Options:
-? show help
clearall reset all settings
-cfg <config> apply additional configuration in the following format:
"OPTION1=VALUE|OPTION2=VALUE|..."
-c generate bytecode; filename.pixicode file will be produced
Filename: source (UTF-8 text file) or bytecode (*.pixicode).
Additional arguments (arg): some options for the Pixilang program.
The basis of the Pixilang - containers and variables.
Container is a two-dimensional array of elements (numbers) of the same data type. Different containers may have different data types. Each container has its own unique ID number. ID is always a positive integer or zero: 0,1,2,3,4... Zero ID is ok, but it's the screen container number by default.
Container structure:
Maximum number of containers is 8192. But you can increase it using the parameter pixi_containers_num in pixilang_config.ini. Also you can change this number in the app_info.cpp (if you compile Pixilang from source) through the following code:app_option g_app_options[] = { { "pixi_containers_num", 16384 }, { NULL } };
Variable can contain 32-bit signed integer or 32-bit floating point number.
Numbers can be described in different formats. Examples:
x = new( 4 ) //Create a new container with 4 pixels. Store its ID into the variable x.
/*
Container elements are addressed from zero:
first element - x[ 0 ];
second element - x[ 1 ];
...
last element - x[ container_size - 1 ]
*/
x[ 0 ] = #0000FF //Assign blue color to the first pixel of container x.
x[ 2 ] = WHITE //Assign white color to pixel 2.
x[ 3 ] = RED //Assign red color to pixel 3 (last element).
x[ 4 ] = BLUE //Nothing will happen here because index 4 is out of range.
b = x[ 2 ] //Read an element with index 2.
//Here b contains the number corresponding to the white color.
c = x[ 8 ] //Try to read an element with index 8
//Here c contains a null value because index 8 is not available.
remove( x ) //Remove the container
c = new( 4, 4 ) //Create a new 2D 4x4 pixel container. Store its ID into the variable x.
c[ 2, 2 ] = WHITE //Assign the white color to a pixel with coordinates x=2 y=2.
remove( c ) //Remove this container
str = "Hello" //"Hello" is the string container with five 8-bit characters (UTF-8 encoding).
//This container is automatically created during the bytecode generation.
//You don't need to delete it manually.
str[ 0 ] = 'h' //Change the first character from 'H' to 'h'.
print( str, 0, 0 ) //will print the word "hello" on the screen
//The string can be terminated with a null character or the end of a container.
str[ 2 ] = 0 //Replace the char 'l' with a zero
print( str, 0, 8 ) //will print the word "he" on the screen
a = 4 //Global variable
fn function()
{
$k = 2 //Local variable
function2 = {
//Body of another function
$x = 899.334 //Local variable
//$k is not accessible here
}
//$x is not accessible here
}
//$k and $x are not accessible here
Coordinate system of the Pixilang is described on the following image:
//File is in the same folder with the pixi-program:
"filename"
//File is in the current working directory:
// Linux/Windows/OSX: in the same folder with Pixilang;
// iOS: documents;
// WinCE: root of local filesystem (/);
"1:/filename"
//File is in the user directory for configs and caches :
// Linux: /home/username/.config/Pixilang;
// iOS: directory with application support files (NSApplicationSupportDirectory);
// Android: internal files directory;
"2:/filename"
//File is in the temporary directory:
"3:/filename"
//if, else
if a == b
{ /*This code is executed if a equals b*/ }
else
{ /*This code is executed otherwise*/ }
if x == 4 && y == 2
{ /*This code is executed if x equals 4 and y equals 2*/ }
//while
a = 0
while( a < 3 )
{
//This code is executed while a less than 3
a + 3
}
//while + break
a = 0
while( a < 100 )
{
if a == 10 { break } //If a = 10, break the loop
//Use breakX operator to break X nested loops. Example: break2
//Use breakall operator to break all current active loops
a + 1
}
//while + continue
a = 0
b = 0
while( a < 100 )
{
if a == 10 { a + 1 continue } //If a = 10, go to the next loop iteration
// (ignore the next two lines of code)
a + 1
b + 1
}
//for( initialization ; condition ; increment ) { loop body }
for( i = 0; i < 4; i + 1 )
{
printf( "i=%d\n", i )
}
//go, goto
m1:
a + 1
goto m1 //Go to the m1 label
//halt, stop
halt //Stop the program here
//include
include "prog2.txt" //Include code from prog2.txt
//fn
fn fff( $x, $y ) //Declare function fff with parameters $x and $y
{
//Function fff body
ret //Simple return from the function
ret( 4 ) //Return with value 4
}
The following table lists the mathematical operators. Priority 0 - the highest, such operations will be executed first.
Priority | Operator | Description | Result | Example |
---|---|---|---|---|
0 | % | Modulo (remainder) | Integer | a = b % 4 |
0 | / | Division | Floating point | a = b / 4 |
0 | div | Integer division | Integer | a = b div 4 |
0 | * | Multiplication | Depends on the operands | a = b * 4 |
0 | ! | Logical NOT | Integer 1 or 0 | if !condition { ... } |
0 | ~ | Bitwise NOT (inversion) | Integer | a = ~b |
1 | + | Addition | Depends on the operands | a = b + 4 |
1 | - | Subtraction | Depends on the operands | a = b - 4 |
2 | >> | Bitwise right shift | Integer | a = b >> 4 |
2 | << | Bitwise left shift | Integer | a = b << 4 |
3 | == | Equal to | Integer 1 or 0 | if a == b {} |
3 | != | Not equal to | Integer 1 or 0 | if a != b {} |
3 | < | Less than | Integer 1 or 0 | if a < b {} |
3 | > | Greater than | Integer 1 or 0 | if a > b {} |
3 | <= | Less than or equal to | Integer 1 or 0 | if a <= b {} |
3 | >= | Greater than or equal to | Integer 1 or 0 | if a >= b {} |
4 | | | Bitwise OR | Integer | a = b | 4 |
4 | ^ | Bitwise XOR | Integer | a = b ^ 4 |
4 | & | Bitwise AND | Integer | a = b & 4 |
5 | || | Logical OR | Integer 1 or 0 | if a || b {} |
5 | && | Logical AND | Integer 1 or 0 | if a && b {} |
64-bit types are not supported by default. But they can be enabled in pixilang.h for the custom build of Pixilang.
Compression levels:
R - reading is supported; W - writing is supported.
Effect types for effector() function:
gl_draw_arrays() (analog of the glDrawArrays()) modes:
Flags for set_audio_callback() function:
Flags for midi_get_device(), midi_open_port() functions:
Flags for thread_create():
For op_cn() function:
These properties can be used during playback, saving and loading of the containers:
Create a new data container.
Note: immediately after its creation, the container may contain some random values. You should clean it up or fill it with useful data.
Parameters ( xsize, ysize, type )
Examplesp = new() //Create 1x1 container. Element type = pixel.
p = new( 4 ) //Create 4x1 container. Element type = pixel.
p = new( 4, 4 ) //Create 4x4 container. Element type = pixel.
p = new( 4, 4, INT32 ) //Create 4x4 container. Element type = INT32.
Remove a container.
Parameters ( pixi )
p = new() //Create new container
remove( p ) //Remove it
Remove the container and its alpha channel (linked container).
Parameters ( pixi )
Resize a container.
Parameters ( pixi, xsize, ysize, type, flags )
Examplesp = new( 4, 4 ) //Create new container
resize( p, 32, 32 ) //Resize it from 4x4 to 32x1
resize( p, -1, 64 ) //Resize it from 32x32 to 32x64
remove( p ) //Remove
Rotate the container by angle*90 degrees (clockwise).
Параметры ( pixi, angle )
Convert the type of a container.
Parameters ( pixi, new_type )
Clean a container (fill with zeroes or with selected values).
Parameters ( dest_cont, v, offset, count )
p = new() //Create new container
clean( p ) //Clean with zero
clean( p, 3 )
clean( p, 3, 0, 24 ) //Fill 24 elements with value 3
remove( p ) //Remove
Make a duplicate of the container.
Parameters ( pixi )
Copy container elements from src to dest.
Parameters ( dest, src, dest_offset, src_offset, count, dest_step, src_step, flags )
//Copy all elements from img1 to img2:
copy( img2, img1 )
//Copy elements 8...200 from img1 to img2:
copy( img2, img1, 8, 8, 200 )
//Copy elements 8...400 from img1 to img2 with step 2:
copy( img2, img1, 8, 8, 200, 2, 2 )
Return value: number of copied elements.
Get size of a container (number of elements).
Parameters ( pixi )
p = new( 8, 8 ) //Create a new container 8x8
size = get_size( p ) //Save its size to the "size" variable
remove( p )
Get width of a container.
Parameters ( pixi )
p = new( 8, 8 ) //Create a new container 8x8
xsize = get_xsize( p ) //Save its width to the "xsize" variable
remove( p )
Get height of a container.
Parameters ( pixi )
p = new( 8, 8 ) //Create a new container 8x8
ysize = get_xsize( p ) //Save its height to the "ysize" variable
remove( p )
Get the size of the element of a container (in bytes).
Parameters ( pixi )
p = new( 8, 8, INT32 ) //Create a new container 8x8; element type = INT32
esize = get_esize( p ) //Save its element's size to the "esize" variable
//Now esize = 4.
remove( p )
Get the type of the element of a container
Parameters ( pixi )
p = new( 8, 8, FLOAT32 ) //Create a new container 8x8; element type = FLOAT32
type = get_type( p ) //Save its element's type to the "type" variable
//Now type = FLOAT32.
remove( p )
Get container flags.
Parameters ( pixi )
Return value: container flags.
Set container flags.
Parameters ( pixi, flags )
Examplesset_flags( img, GL_MIN_LINEAR | GL_MAG_LINEAR )
Reset container flags.
Parameters ( pixi, flags )
Get property value of the container. Each container can have unlimited number of properties.
Another way to get a property - use a . (dot) operator. Example: value = image.fps
Parameters ( pixi, prop_name, def_value )
Set property value of the container.
Another way to set a property - use a . (dot) operator. Example: image.fps = 30
Parameters ( pixi, prop_name, value )
p = new( 8, 8, INT32 ) //Create a new container
set_prop( p, "speed", 777 ) //Add "speed" property to this container
v = get_prop( p, "speed" ) //Read the value of "speed" property
//Or more simple way:
p.speed = 777
v = p.speed
Remove the container property.
Parameters ( pixi, prop_name )
Remove all properties of the selected container.
Parameters ( pixi )
Get a list (array of strings) of properties for the specified container.
Parameters ( pixi )
Remove the list of properties.
Parameters ( list )
Parameters ( enable )
Parameters ( source, level )
Parameters ( source )
Aliases: num2str.
Convert number to string.
Parameters ( str, num, radix, str_offset, no_null_term )
v = 45.64
s = ""
num_to_str( s, v )
fputs( s ) fputs( "\n" )
Aliases: str2num.
Convert string to number.
Parameters ( str, str_offset, len )
Examplesa = str_to_num( "-55.44" )
b = a + 4
Appends a copy of the source string to the destination string. Both strings can be with terminating null character or without it (if the size of the container = number of characters in the string). Size of the source string can be changed after this function executes.
Parameters ( destination, source )
Parameters ( dest, dest_offset, source, source_offset )
Compares the string str1 to the string str2. Both strings can be with terminating null character or without it (if the size of the container = number of characters in the string).
Parameters ( str1, str2 )
Parameters ( str1, str1_offset, str2, str2_offset )
Return value: a zero value indicates that both strings are equal; a value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; and a value less than zero indicates the opposite.
Returns the length of string str. String can be with terminating null character or without it (if the size of the container = number of characters in the string).
Parameters ( str )
Parameters ( str, str_offset )
Return value: length of string str.
Returns the offset of the first occurrence of str2 in str1, or a -1 if str2 is not part of str1.
Parameters ( str1, str2 )
Parameters ( str1, str1_offset, str2, str2_offset )
Return value: offset of the first occurrence of str2 in str1, or a -1 if str2 is not part of str1.
Writes into the container str a string consisting on a sequence of data formatted as the format argument specifies. Detailed format description can be found here. The size of the str container will be increased automatically if there is not enough space.
Parameters ( str, format, ... )
Return value: on success, the total number of characters written is returned; on failure, a negative number is returned.
Examplessprintf( str, "Some text\n" ) //Just write some text to the str
sprintf( str, "Number: %d\n", 12 ) //Write signed decimal integer
Same as sprintf() but with additional parameters.
Parameters ( str, str_offset, no_null_term, format, ... )
str = "######"
val = 24
sprintf2( str, 2, 1, "%d", val )
//container str now contains the following:
//"##24##"
Return value: on success, the total number of characters written is returned; on failure, a negative number is returned.
Same as sprintf, but the destination is STDOUT.
Parameters ( format, ... )
Print formatted output to the stream (opened by fopen() or fopen_mem()).
Parameters ( stream, format, ... )
The same as printf, but the destination is the Pixilang log buffer.
Parameters ( format, ... )
Get the Pixilang log buffer.
Return value: the new container with the log buffer; (container must be removed manually).
Get the Pixilang system log buffer.
Return value: the new container with the system log buffer; (container must be removed manually).
Load container from the file.
Parameters ( filename, options )
Examplesc = load( "smile.jpg" )
if c >= 0
{
file_format = c.file_format //FORMAT_RAW / FORMAT_JPEG / ...
if file_format == FORMAT_WAVE
{
printf( "This is audio file\n" )
}
}
Load container from the stream (opened by fopen() or fopen_mem()).
Parameters ( stream, options )
Save container to the file.
Parameters ( pixi, filename, format, options )
Examplesc = load( "smile.jpg" )
save( c, "smile.png", FORMAT_PNG )
save( c, "smile2.jpg", FORMAT_JPEG ) //Quality = 85 (default)
save( c, "smile3.jpg", FORMAT_JPEG, 100 ) //Quality = 100
Save container to the stream (opened by fopen() or fopen_mem()).
Parameters ( pixi, stream, format, options )
Return value: 0 on success.
Convert Pixilang-style path (e.g. 1:/img.png) to the real filesystem path.
Parameters ( path )
Return value: the container with real filesystem path; (container must be removed manually).
Examplesfilename = "1:/some_file"
realpath = get_real_path( filename )
printf( "File name: %s; Real path: %s\n", filename, realpath )
remove( realpath )
Functions for getting a list of files.
Examplespath = CURRENT_PATH
mask = -1 //Examples: "txt/doc", "avi"; or -1 for all files.
fl = new_flist( path, mask )
if fl >= 0
{
printf( "Some files found in %s\n", path )
while( 1 )
{
file_name = get_flist_name( fl )
file_type = get_flist_type( fl ) //0 - file; 1 - directory;
if file_type == 0
{
printf( "FILE %s%s\n", path, file_name )
}
else
{
printf( "DIR %s%s\n", path, file_name )
}
if flist_next( fl ) == 0 //Go to the next file
{
//No more files
break
}
}
remove_flist( fl )
}
Get the size of selected file.
Parameters ( filename )
Get file (or stream, if filename == -1) format (one of the FORMAT_* constants).
Parameters ( filename, stream )
Get MIME type (string) for specified file format.
Parameters ( fileformat )
Get the extension (string) for specified file format.
Parameters ( fileformat )
Parameters ( filename )
Parameters ( old_filename, new_filename )
Parameters ( source_filename, destination_filename )
Parameters ( directory_name, mode )
Use the _stream_ (opened by fopen() or fopen_mem()) as virtual disk 0:/ . _stream_ must point to the opened TAR archive.
Parameters ( stream )
The fopen() function shall open the file whose pathname is the string pointed to by _filename_, and associates a stream with it.
Parameters ( filename, mode )
Examplesf = fopen( "/tmp/data.txt", "rb" ) //Open file data.txt for reading
fclose( f ) //...and close it.
Open the _data_ container as file.
Parameters ( data )
Return value: upon successful completion, fopen_mem() shall return ID of the object controlling the stream; otherwise, 0 shall be returned.
The fclose() function shall cause the stream to be flushed and the associated file to be closed.
Parameters ( stream )
Return value: upon successful completion, fclose() shall return 0.
Examplesf = fopen( "/tmp/data.txt", "rb" ) //Open file data.txt for reading.
c = fgetc( f ) //Get a byte from this file.
fclose( f ) //Close the stream.
Put a byte on a stream.
Parameters ( c, stream )
Examplesf = fopen( "/tmp/data.txt", "wb" ) //Open file data.txt for writing.
fputc( 0x12, f ) //Put a byte 0x12 to this file.
fclose( f ) //Close the stream.
Put a string on a stream.
Parameters ( s, stream )
Examplesf = fopen( "/tmp/data.txt", "wb" ) //Open file data.txt for writing.
str = "Hello!"
fputc( str, f ) //Put a string "Hello!" to this file.
fclose( f ) //Close the stream.
The fwrite() function shall write, from the container data, up to size bytes, to the stream pointed to by stream.
Parameters ( data, size, stream, data_offset_optional )
Return value: the number of bytes successfully written, which may be less than size if a write error is encountered.
Examplesf = fopen( "/tmp/data.txt", "wb" ) //Open file data.txt for writing.
str = "Hello!"
fwrite( str, 2, f ) //Put first two bytes from the string "Hello!" to this file.
fclose( f ) //Close the stream.
Get a byte from a stream.
Parameters ( stream )
Return value: upon successful completion, fgetc() shall return the next byte from the input stream pointed to by stream.
Get a string from a stream. Reading occurs until one of the following conditions is met:
string = new( 256, 1, INT8 )
f = fopen( "/tmp/data.txt", "rb" ) //Open file data.txt for reading.
fgets( string, 256, f ) //Get a string from this file.
fclose( f ) //Close the stream.
The fread() function shall read into the container pointed to by data up to size bytes, from the stream pointed to by stream.
Parameters ( data, size, stream, data_offset_optional )
Return value: the number of bytes successfully read which is less than size only if a read error or end-of-file is encountered.
Test end-of-file indicator on a stream.
Parameters ( stream )
Return value: non-zero if the end-of-file indicator is set for stream.
Flush a stream.
Parameters ( stream )
Reposition a file-position indicator in a stream.
Parameters ( stream, offset, origin )
Return a file offset in a stream.
Parameters ( stream )
Return value: the current value of the file-position indicator for the stream measured in bytes from the beginning of the file.
Examples//One of the ways to get the file size:
f = fopen( "/tmp/data.txt", "rb" )
fseek( f, 0, SEEK_END )
size_of_file = ftell( f )
fclose( f )
Set an extended attribute value of the file.
Parameters ( path, attr_name, data, data_size_in_bytes, flags )
Return value: 0 on success, or -1 in case of error.
Examples//iOS: set "don't backup" file attribute:
if strstr( OS_NAME, "ios" ) >= 0
{
$val = new( 1, 1, INT8 )
$val[ 0 ] = 1
setxattr( "myfile.txt", "com.apple.MobileBackup", $val, 1, 0 )
remove( $val )
}
Draw the current screen on the display and sleep for selected number of milliseconds.
Parameters ( delay, x, y, xsize, ysize )
Enable/disable vertical synchronization (when possible). vsync(1) - enable. vsync(0) - disable.
Parameters ( enable )
Change the size of the screen pixels. Default size = 1.
Parameters ( size )
Get the size of the screen pixel.
Set current screen - destination container (with image) for all graphic commands.ID of the default screen container is 0.
Parameters ( pixi )
Get current screen.
Return value: screen container ID.
Parameters ( zbuf_container )
Set container (INT32 elements) with Z-buffer.
Get color by r,g,b (red,green,blue).
Parameters ( red, green, blue )
Get red component intensity in a selected color.
Parameters ( color )
Return value: red component intensity; from 0 to 255.
Get green component intensity in a selected color.
Parameters ( color )
Return value: green component intensity; from 0 to 255.
Get blue component intensity in a selected color.
Parameters ( color )
Return value: blue component intensity; from 0 to 255.
Get an intermediate color value between two selected colors.
Parameters ( c1, c2, v )
Set transparency.
Parameters ( t )
Clear current screen.
Parameters ( color )
Draw a dot.
Parameters ( x, y, color )
Draw a dot in 3D.
Parameters ( x, y, z, color )
Get a dot's color.
Parameters ( x, y )
Return value: color value.
Get a dot's color in 3D.
Parameters ( x, y, z )
Return value: color value.
Draw a line.
Parameters ( x1, y1, x2, y2, color )
Draw a line in 3D.
Parameters ( x1, y1, z1, x2, y2, z2, color )
Draw a rectangle.
Parameters ( x, y, xsize, ysize, color )
Draw a filled rectangle.
Parameters ( x, y, xsize, ysize, color )
Display the container with image.
Parameters ( pixi_cont, x, y, color, xscale, yscale, src_x, src_y, src_xsize, src_ysize )
pixi( image )
pixi( image, 10, 20 )
pixi( image, 30, 40, GREEN )
pixi( image, 90, 20, GREEN, 0.5, 0.5 )
Draw array of triangles.
Parameters ( vertices, triangles, tnum )
Sort triangles by Z value.
Parameters ( vertices, triangles, tnum )
Set / reset the color of transparency in the container.
Parameters ( pixi, color )
Attach a container with alpha channel to another container. Alpha channel should be of type INT8.
Parameters ( pixi, alpha )
Get linked container with the alpha channel.
Parameters ( cont )
Return value: container ID or -1 (if no alpha channel).
Show text on the screen.
Parameters ( text, x, y, color, align, max_xsize, str_offset, str_size )
print( "Hello Pixi!", 0, 0 ) //color = WHITE; centered;
print( "line1\nline2", 50, 50, RED ) //centered;
print( "line1\nline2", -50, 50, RED, TOP | LEFT ) //alignment = top left;
Parameters ( text, align, max_xsize, str_offset, str_size )
Parameters ( first_char_utf32, font_image, xchars, ychars, last_char, char_xsize, char_ysize, char_xsize2, char_ysize2, grid_xoffset, grid_yoffset, grid_cell_xsize, grid_cell_ysize )
Parameters ( char_utf32 )
Return value: the font container font for the specified character.
Apply an effect to selected screen area. Coordinates of this function can't be changed by t_* transformation functions.
Parameters ( type, power, color, x, y, xsize, ysize, x_step, y_step )
Draw a smooth transition between the colors of 4 key points in the specified rectangle. Bilinear interpolation algorithm is used.
The coordinates of this function are not affected by the transformation.
Parameters ( color1, opacity1, color2, opacity2, color3, opacity3, color4, opacity4, x, y, xsize, ysize, x_step, y_step )
Split a container (with pixels) by color channels (red, green, blue) and vice versa.
Parameters ( direction, image, red_channel, green_channel, blue_channel, image_offset, channel_offset, size )
img = load( "some_image.jpg" )
xsize = get_xsize( img )
ysize = get_ysize( img )
r = new( xsize, ysize, INT16 )
g = new( xsize, ysize, INT16 )
b = new( xsize, ysize, INT16 )
split_rgb( 0, img, r, g, b ) //Convert image to RGB
//Get red value (from 0 to 255) of the first pixel:
value = r[ 0 ]
Same as split_rgb() but for YCbCr conversion.
OpenGL-version of Pixilang is based on the OpenGL ES 2.0 with OpenGL ES Shading Language 1.0 (GLSL ES).
Here is very good OpenGL ES 2.0 Quick Reference Card.
Set OpenGL frame drawing callback.
Parameters ( gl_callback, user_data )
fn gl_callback( $user_data )
{
set_screen( GL_SCREEN ) //Enable OpenGL drawing mode
clear( YELLOW )
set_screen( 0 ) //Back to the default screen
}
set_gl_callback(
gl_callback, //OpenGL frame drawing function
0 ) //Some user-defined data
while( 1 )
{
while( get_event() ) { if EVT[ EVT_TYPE ] == EVT_QUIT { break2 } }
frame()
}
set_gl_callback( -1 ) //Remove OpenGL callback
Remove all GL-specific data from the container. This data will be created again inside the OpenGL drawing callback.
Parameters ( container )
Sends a request to update the OpenGL texture associated with container. Use this function if the contents (pixels) of the container have changed, but the size remains the same.
Parameters ( container )
Hybrid of the OpenGL functions glColor4ub(), glBindTexture(), glVertexPointer(), glColorPointer(), glTexCoordPointer(), glDrawArrays().
Can only be used inside the OpenGL drawing callback.
Parameters ( mode, first, count, color_r, color_g, color_b, color_a, texture, vertex_array, color_array, texcoord_array )
Full analog of the OpenGL function glBlendFunc() (specify pixel arithmetic) or glBlendFuncSeparate (if sfactor_alpha and dfactor_alpha are specified).
Can only be used inside the OpenGL drawing callback.
Call this function without parameters, if you want to reset pixel arithmetic to the default values.
Parameters ( sfactor, dfactor, sfactor_alpha, dfactor_alpha )
Convert specified pixel container (cnum) to the OpenGL framebuffer (with attached texture) and bind it. All rendering operations will be redirected to this framebuffer. To unbind - just call this function without parameters.
Pixel size does not affect the framebuffer.
The framebuffer is flipped along the Y-axis when shown with pixi(). (native OpenGL framebuffer coordinates are using)
Can only be used inside the OpenGL drawing callback.
Parameters ( cnum, flags, x, y, width, height )
Bind selected pixel container (cnum) to the specified texture image unit.
Can only be used inside the OpenGL drawing callback.
Parameters ( cnum, texture_unit )
fn gl_callback( $userdata )
{
set_screen( GL_SCREEN )
gl_bind_texture( some_image2, 1 ) //bind some_image2 to texture unit 1
gl_bind_texture( some_image3, 2 ) //bind some_image3 to texture unit 2
gl_use_prog( gl_prog ) //Use user-defined GLSL program
gl_uniform( gl_prog.g_texture2, 1 ) //set shader variable: g_texture2 = texture image unit 1
gl_uniform( gl_prog.g_texture3, 2 ) //set shader variable: g_texture3 = texture image unit 2
pixi( some_image )
gl_use_prog() //Back to default GLSL program
set_screen( 0 ) //Back to the default screen
}
gl_vshader = GL_SHADER_TEX_RGB_SOLID //Vertex shader = default shader for solid primitives drawing
gl_fshader = //Fragment shader
"uniform sampler2D g_texture; //main texture image unit 0 (set by pixi())
uniform sampler2D g_texture2; //texture image unit 1
uniform sampler2D g_texture3; //texture image unit 2
uniform vec4 g_color;
IN vec2 tex_coord_var;
void main()
{
vec4 c1 = texture2D( g_texture, tex_coord_var );
vec4 c2 = texture2D( g_texture2, tex_coord_var );
vec4 c3 = texture2D( g_texture3, tex_coord_var );
gl_FragColor = ( c1 + c2 + c3 ) * g_color;
}
"
gl_prog = gl_new_prog( gl_vshader, gl_fshader )
Get the value of the simple GL state variable. Full analog of the OpenGL function glGetIntegerv().
Can only be used inside the OpenGL drawing callback.
Parameters ( pname )
Get the value of the simple GL state variable. Full analog of the OpenGL function glGetFloatv().
Can only be used inside the OpenGL drawing callback.
Parameters ( pname )
OpenGL-version of Pixilang uses OpenGL ES Shading Language 1.0 (GLSL ES) for the vertex and the fragment shaders.
Notes about the vertex shader syntax in Pixilang:
Create a new GLSL program - container with a vertex shader and a fragment shader. You can use this function anywhere in your code. Shader code will be compiled, and the program will be linked later - during the gl_use_prog() function call.
Parameters ( vertex_shader, fragment_shader )
Use the GLSL program previously created by the gl_new_prog() function.If you use this program first time - it will be compiled and linked.
Can only be used inside the OpenGL drawing callback.
Parameters ( prog )
Change the value of the uniform variable within the GLSL program.
Can only be used inside the OpenGL drawing callback.
gl_uniform() can also change the contents of arrays if you use this function as follows:
gl_uniform( var_location, src_container, vector_size, first_vector, count ), where count is the number of vectors to write to the array.
Parameters ( var_location, v0, v1, v2, v3 )
gl_use_prog( gl_prog ) //Use GLSL program gl_prog (vertex shader + fragment shader)
gl_uniform( gl_prog.g_time, get_timer( 0 ) ) //Set value of uniform variable g_time
Change the value of the uniform matrix within the GLSL program.
Can only be used inside the OpenGL drawing callback.
Parameters ( size, matrix_location, transpose, matrix )
gl_use_prog( gl_prog ) //Use GLSL program gl_prog (vertex shader + fragment shader)
gl_uniform( 4, gl_prog.g_mat, 0, source_matrix ) //Set value of uniform matrix g_mat
Pack current frame (from container data to hidden storage with frames). Frame number must be stored in the "frame" container property.
Parameters ( pixi )
Unpack current frame (from hidden storage with frames to container data). Frame number must be stored in the "frame" container property.
Parameters ( pixi )
Create the hidden storage with frames (animation) in the selected container.
Parameters ( pixi )
Remove the hidden storage with frames (animation) from the selected container.
Parameters ( pixi )
Clone current frame. Frame number must be stored in the "frame" container property.
Parameters ( pixi )
Remove current frame. Frame number must be stored in the "frame" container property.
Parameters ( pixi )
Enable auto-play mode. Frame will be changed automatically during the pixi() function call.
Parameters ( pixi )
Disable auto-play mode.
Parameters ( pixi )
Coordinate transformation in Pixilang works similarly to other graphics APIs. It is based on a transformation matrix that affects the coordinates of the drawn objects. The matrix is a 4x4 array inside the Pixilang VM. It can be changed with t_* commands, and reset with t_reset(). Every time Pixilang draws something (including pixi()), it multiplies the object's vertex coordinates by the transformation matrix. The resulting coordinates are used for the final drawing of the figure.
The t_* commands do not affect any particular object, but the entire coordinate system, relative to previous transformations. The result (including both new and old changes) is stored in the matrix. This is convenient, because one small array can store an infinite number of t_* operations. Usually direct access to this array is not required.
The order of the values inside the matrix is as follows (different from the usual order in 2D containers):
0 | 4 | 8 | 12 |
1 | 5 | 9 | 13 |
2 | 6 | 10 | 14 |
3 | 7 | 11 | 15 |
Example:
(draw a picture moved relative to the center of the screen, magnified by 2 times and rotated 45 degrees)t_reset() //reset transformation
t_translate( 32, 0, 0 ) //#1: move 32 pixels horizontally
t_scale( 2, 2, 2 ) //#2: increase the size by 2 times
t_rotate( 45, 0, 0, 1 ) //#3: rotate 45 degrees around vector 0,0,1 (x,y,z)
pixi( img ) //draw the final picture with offset, scale and rotation
frame() //show it
Simplified, this example will result in the following transformation (for each vertex of the object being drawn):
v2 = wm * #1 * #2 * #3 * v;
wm - additional transformation for correct display in the window; not required in software rendering mode (non-OpenGL);
#1 - translation matrix;
#2 - scaling matrix;
#3 - rotation matrix;
v - initial vertex coordinates;
v2 - modified vertex coordinates;
The matrices and the final vertex v2 are 4D. Without going into details, this is required for translation and perspective projection (see Clip coordinates и Homogeneous coordinates). Before drawing, a perspective division operation is performed: v2 is converted from 4D to 3D.
In OpenGL mode, the coordinate transformation is performed by the following vertex shader:// Window manager transformation matrix:
// (converts Pixilang coordinates
// (X:-WINDOW_XSIZE/2...WINDOW_XSIZE/2; Y:-WINDOW_YSIZE/2...WINDOW_YSIZE/2; Z:-WINDOW_ZSIZE/2...WINDOW_ZSIZE/2)
// to normalized device coordinates
// (NDC; X:-1...1; Y:-1...1; Z:1...-1))
uniform mat4 g_wm_transform;
// Pixilang transformation matrix (with all t_* operations inside):
uniform mat4 g_pixi_transform;
// Initial vertex coordinates:
IN vec4 position;.
void main()
{
gl_Position = g_wm_transform * g_pixi_transform * position;
gl_PointSize = 1.0;
}
// After the shader finishes, perspective division is performed to obtain 3D coordinates in NDC
Reset transformation (set equal to identity matrix).
Parameters ( angle, x, y, z )
Parameters ( x, y, z )
Parameters ( x, y, z )
Save current transformation matrix to the stack.
Restore previous saved transformation matrix from the stack.
Get transformation matrix (4x4 FLOAT).
Parameters ( matrix_container )
Set transformation matrix (4x4 FLOAT).
Parameters ( matrix_container )
Multiply transformation matrix (4x4 FLOAT). Current matrix = current matrix * matrix_container.
Parameters ( matrix_container )
Transform point (container with 3 elements of type FLOAT).
Parameters ( point_coordinates )
Parameters ( callback, userdata, sample_rate, format, channels, flags )
fn audio_callback( $stream, $userdata, $channels, $frames, $time )
{
generator( OP_SIN, $channels[ 0 ], 0, 32767 / 2, 0.1, 0 ) //Left channel
generator( OP_SIN, $channels[ 1 ], 0, 32767 / 2, 0.1, 0 ) //Right channel
ret(1)
//return values:
// 0 - silence, output channels are not filled;
// 1 - output channels are filled;
// 2 - silence, output channels are filled with zeros (or values close to zero).
}
//Start audio:
set_audio_callback( audio_callback, 0, 22050, INT16, 2, AUDIO_FLAG_INTERP2 )
//Stop audio:
set_audio_callback( -1 )
Parameters ( source )
Parameters ( disable_enable )
Get the frequency of the specified note (using a fast, not very accurate algorithm).
Frequency of MIDI note = get_note_freq( midi_note, 0 ) / 64; (5 octaves lower)
Parameters ( note, finetune )
Parameters ( client_name )
Return value: client ID or negative value in case of some error.
Parameters ( client_id )
Parameters ( client_id, device_num, flags )
Return value: selected device name, or -1 if not exists.
Parameters ( client_id, port_name, device_name, flags )
Return value: port ID or negative value in case of some error.
Parameters ( client_id, port_id )
Parameters ( client_id, port_id )
Parameters ( client_id, port_id, data_cont )
Return value: size of the current MIDI event (in bytes).
Parameters ( client_id, port_id )
Return value: time of the current event (in system ticks).
Go to the next event.
Parameters ( client_id, port_id )
Parameters ( client_id, port_id, data_cont, data_size, t )
SunVox modular synth engine is now part of Pixilang since v3.8.
See the SunVox Library Documentation for a detailed description of all functions.
Start selected timer.
Parameters ( timer_num )
Get value (in milliseconds) of selected timer.
Parameters ( timer_num )
Return value: 32bit value of selected timer (in milliseconds).
Get current system tick counter (32bit).
Get number of system ticks per second.
Parameters ( delay )
Get a new event from the system.
Return value: 0 - no events; 1 - event is received and placed into the container EVT.
Set the program's behavior when receiving event EVT_QUIT.
Parameters ( action )
Parameters ( thread_function, user_data, flags_optional )
Return value: thread ID or -1 if error occurred.
Examplesfn thread_body( $thread_id, $user_data )
{
printf( "Thread code\n" )
}
thread_id = thread_create( thread_body, 0 )
err = thread_destroy( thread_id, 1000 ) //Wait for the thread to terminate
if err == 0 { printf( "Thread closed successful\n" ) }
if err == 1 { printf( "Time-out. Thread is not closed\n" ) }
if err == 2 { printf( "Some error occurred in thread_destroy() function\n" ) }
Parameters ( thread_id, timeout_ms )
Examplesnew_mutex = mutex_create()
mutex_lock( new_mutex )
mutex_unlock( new_mutex )
mutex_destroy( new_mutex )
Parameters ( value, mode, intermediate_value_bits )
Execute data processing operation.Operands:
for each element of C1: C1[ i ] = C1[ i ] OP N,
Where i - element number; OP - selected operation.
Parameters ( opcode, C1, N ) - for whole container C1
Parameters ( opcode, C1, N, x, xsize ) - for 1D region
Parameters ( opcode, C1, N, x, y, xsize, ysize ) - for 2D region
//Add 32 to the whole container img:
op_cn( OP_ADD, img, 32 )
//Add 32 to 128..256th elements of the container img:
op_cn( OP_ADD, img, 32, 128, 128 )
//Add 32 to two-dimensional region (8,8,32,32) of elements:
op_cn( OP_ADD, img, 32, 8, 8, 32, 32 )
Execute data processing operation.Operands:
for each element of C1: C1[ i ] = C1[ i ] OP C2[ i ],
Where i - element number; OP - selected operation.
Parameters ( opcode, C1, C2 ) - for whole container C1
Parameters ( opcode, C1, C2, dest_x, src_x, xsize ) - for 1D region
Parameters ( opcode, C1, C2, dest_x, dest_y, src_x, src_y, xsize, ysize ) - for 2D region
Execute data processing operation.Operands:
for each element of C1: C1[ i ] = C1[ i ] OP C2[ i ] OP2 N,
Where i - element number; OP - selected operation; OP2 - additional operation associated with OP.
Parameters ( opcode, C1, C2, N ) - for whole container C1
Parameters ( opcode, C1, C2, N, dest_x, src_x, xsize ) - for 1D region
Parameters ( opcode, C1, C2, N, dest_x, dest_y, src_x, src_y, xsize, ysize ) - for 2D region
Generate a signal.
Parameters ( opcode, pixi, phase, amplitude, delta_x, delta_y, x, y, xsize, ysize )
//Generate a sine wave to the whole container img:
generator( OP_SIN, img, 0, 1, 0.1, 0.1 )
//Generate a rough sine wave to the whole container img:
generator( OP_SIN8, img, 0, 1, 0.1, 0.1 )
//Generate a sine wave to 8...128 elements of the container img:
generator( OP_SIN, img, 0, 1, 0.1, 0.1, 8, 120 )
//Generate a sine wave to region (8,8,32,32) of the container img:
generator( OP_SIN, img, 0, 1, 0.1, 0.1, 8, 8, 32, 32 )
Very fast multichannel sampler, where the sample (table) is always looped and has a fixed size (32768).
Parameters ( dest, dest_offset, dest_length, table, amp, amp_delta, pos, pos_delta, gen_offset, gen_step, gen_count )
Parameters ( sample_info )
Examplessample_data = new( 256, 1, INT16 ) //16bit sample
sample_info = new( SMP_INFO_SIZE, 1, INT32 )
clean( sample_info )
sample_info[ SMP_DEST ] = buffer //Destination container
sample_info[ SMP_DEST_OFF ] = 0 //Destination offset
sample_info[ SMP_DEST_LEN ] = 256 //Destination length
sample_info[ SMP_SRC ] = sample_data
sample_info[ SMP_SRC_OFF_H ] = 0 //Sample offset (left part of fixed point value)
sample_info[ SMP_SRC_OFF_L ] = 0 //Sample offset (right part of fixed point value from 0 to 65535)
sample_info[ SMP_SRC_SIZE ] = 0 //Sample size (0 - whole sample)
sample_info[ SMP_LOOP ] = 0 //Loop start
sample_info[ SMP_LOOP_LEN ] = 128 //Loop length (or 0, if no loop)
sample_info[ SMP_VOL1 ] = 0 //Start volume
sample_info[ SMP_VOL2 ] = 32768 //End volume (32768 = 1.0)
sample_info[ SMP_DELTA ] = ( 1 << 16 ) //Delta; fixed point (real_value * 65536)
sample_info[ SMP_FLAGS ] = SMP_FLAG_INTERP4 | SMP_FLAG_PINGPONG //Cubic spline interpolation and ping-pong loop
sampler( sample_info ) //Go!
Apply gain and DC-offset two-points envelope to selected container area. Without clipping.
Parameters ( data_cont, v1, v2, offset, size, dc_offset1, dc_offset2 )
Fill intermediate values between the key points of the rectangle in the specified container. The bilinear interpolation algorithm is used.
Parameters ( container, val1, val2, val3, val4, x, y, xsize, ysize, x_step, y_step )
Perform a fast fourier transform.
Parameters ( inverse, im, re, size )
Create a new filter with the following function:output[ n ] = ( a[ 0 ] * input[ n ] + a[ 1 ] * input[ n - 1 ] + ... + a[ a_count - 1 ] * input[ n - a_count - 1 ]
+ b[ 0 ] * output[ n - 1 ] + ... + b[ b_count - 1 ] * output[ n - b_count - 1 ] ) >> rshift;
Parameters ( flags_for_future_use )
Return value: ID of the new container with the filter.
Parameters ( filter )
Parameters ( filter )
Parameters ( filter, a, b, rshift, flags )
Parameters ( filter, output, input, flags, offset, size )
For each element of dest container: dest[ i ] = values[ (unsigned)src[ i ] ].The dest container must have the same type as the values.
Parameters ( dest, src, values, dest_offset, src_offset, size )
//Convert 8-bit image with palette to the screen pixel format:
replace_values( scr, img8, palette )
Parameters ( dest, src, flags, dest_x, dest_y, dest_rect_xsize, dest_rect_ysize, src_x, src_y, src_rect_xsize, src_rect_ysize )
Apply the convolution filter (convolution matrix).
Parameters ( dest, src, kernel, div, offset, flags, kernel_xcenter, kernel_ycenter, dest_x, dest_y, src_x, src_y, xsize, ysize, xstep, ystep )
Open file dialog.
Parameters ( dialog_name, mask, id, default_name, flags )
Open window with global Pixilang preferences.
Open SunDog-based text input dialog and return the entered string. Only Latin letters are supported now.
Parameters ( default_text, dialog_name )
Open web browser window with selected URL.
Parameters ( url_string )
Open dynamic library (for example - .DLL file in Windows, or .SO file in Linux).
Parameters ( lib_file_name )
Return value: library ID or -1 if error occured.
Examples//For example we have some C function int show_info( int x, int y, void* data )
//in mylib.dll library.
//Let's call it from Pixilang:
dl = dlopen( "mylib.dll" ) //Open the library
if dl >= 0
{
f = dlsym( dl, "show_info", "iip" ) //Get the function show_info() from dynamic library
// "iip" - int int pointer
if f >= 0
{
retval = dlcall( dl, f, 1, 2, "blahblah" ) //Call the function show_info() with parameters 1, 2, "blahblah"
}
dlclose( dl ) //Close the library
}
Close dynamic library.
Parameters ( lib_id )
Get symbol (function or variable) from dynamic library.
Parameters ( lib_id, symbol_name, format, calling_convention )
Call the function from dynamic library.
Parameters ( lib_id, symbol_id, optional_function_parameters )
Issue a OS command.
Parameters ( command )
Return value: termination status of the command.
Examples//Remove some file:
system( "rm /tmp/data.txt" )
Returns the number of arguments.
Returns the container with selected argument.
Parameters ( n )
Examplesif argc() >= 4
{
a = argv( 3 )
remove( a )
}
Quit from Pixilang.
Parameters ( exit_code )
Examplesexit( 4 ) //Exit with code 4