Pixilang is a cross-platform programming language for graphics/sound applications. Originally created by Alexander Zolotov (NightRadio) and Mik Razuvaev (Goglus) for non-programmers, demosceners and designers.
Pixilang programs are stored in text files (UTF8) with extensions .txt or .pixi. So you can use your favorite text editor to create/edit these files. Pixilang has no built-in editor.
pixilang [options] [source_file_name] [options] -c generate bytecode; source_file_name.pixicode file will be produced. Note: *.pixicode files are architecture-dependent.
The basis of the Pixilang - are 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:
The new container can be created with the new() function or returned by some other function. There are two ways to remove the container:
There is no automatic garbage collector.
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 user_code_info.cpp (if you compile Pixilang from source) through the following code: const char* g_app_options[] = { "pixi_containers_num", 0 }; int g_app_options_val[] = { 16384 };
Variable can contain 32-bit signed integer or 32-bit floating point number.
Numbers can be described in different formats. Examples:
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 } //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 |
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.
For OpenGL acceleration:
Compression levels:
GIF saving:
JPEG saving:
Effect types for effector() function:
gl_draw_arrays() (analog of the glDrawArrays()) modes:
gl_blend_func() (analog of the glBlendFunc()) operations:
State variables (for gl_get_int() and gl_get_float()):
Default shader names for the gl_new_prog():
Global OpenGL containers:
Flags for set_audio_callback() function:
Flags for midi_get_device(), midi_open_port() functions:
EVT field numbers:
Event types (for the EVT_TYPE field):
Event flags (for the EVT_FLAGS field):
Event key codes (for the EVT_KEY field):
Constants for the set_quit_action() function:
Flags for thread_create():
For op_cn() function:
For op_cn(), op_cc() function:
For op_cc() function:
For op_ccn() function:
For generator() function:
Sample info field numbers:
Sample info flags:
These properties can be used during playback, saving and loading of the containers:
Create 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 )
Return value: ID of the container, or -1 (error).
Examples
p = 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 )
Examples
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 )
Return value: 0 - successful; 1 - error.
Examples
p = 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 )
Examples
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 )
Return value: ID of the new container, or -1 (error).
Copy container elements from src to dest.
Parameters ( dest, src, dest_offset, src_offset, count, dest_step, src_step, flags )
Examples
//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 )
Examples
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 )
Examples
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 )
Examples
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 )
Examples
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 )
Examples
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. List of supported flags is here.
Parameters ( pixi )
Return value: container flags.
Set container flags. List of supported flags is here.
Parameters ( pixi, flags )
Examples
set_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 )
Return value: value of selected property.
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 )
Examples
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 all properties of the selected container.
Parameters ( pixi )
Parameters ( enable )
Parameters ( source, level )
Return value: ID of the new compressed container (created from the source) or -1 in case of error.
Parameters ( source )
Return value: ID of the new decompressed container (created from the source) or -1 in case of error.
Aliases: num2str.
Convert number to string.
Parameters ( str, num )
Examples
v = 45.64 s = "" num_to_str( s, v ) fputs( s ) fputs( "\n" )
Aliases: str2num.
Convert string to number.
Parameters ( str )
Return value: numeric value.
Examples
a = 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: https://en.wikipedia.org/wiki/Printf_format_string
Parameters ( str, format, … )
Return value: on success, the total number of characters written is returned; on failure, a negative number is returned.
Examples
sprintf( 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 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 )
Return value: ID of the new loaded container, or -1 in case of error.
Examples
c = 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 )
Return value: ID of the new loaded container, or -1 in case of error.
Save container to the file.
Parameters ( pixi, filename, format, options )
Return value: 0 on success.
Examples
c = 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: ID of the container with real filesystem path; (container must be removed manually).
Examples
filename = "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.
Examples
path = 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 )
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 )
Return value: upon successful completion, fopen() shall return ID of the object controlling the stream; otherwise, 0 shall be returned.
Examples
f = 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.
Examples
f = 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 )
Examples
f = 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 )
Examples
f = 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.
Examples
f = 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.
Parameters ( s, n, stream, offset )
Return value: length of the string.
Examples
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.
Draw the current screen on the display and sleep for selected number of milliseconds.
Parameters ( delay, x, y, xsize, ysize )
Return value:
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. 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 )
Return value: color value.
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 )
Return value: intermediate color value.
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 )
Examples
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 )
Examples
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 )
Return value: text width in pixels.
Parameters ( text, align, max_xsize )
Return value: text height in pixels.
Parameters ( first_char_utf32, font_image, xchars, ychars )
Parameters ( char_utf32 )
Return value: container ID with font for selected character.
Apply an effect to selected screen area. Coordinates of this function can't be changed by t_xxx transformation functions.
Parameters ( type, power, color, x, y, xsize, ysize, x_step, y_step )
Draw a color gradient.
Parameters ( color1, transp1, color2, transp2, color3, transp3, color4, transp4, 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 )
Examples
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 )
Examples
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 )
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 the 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 bound framebuffer.
Can only be used inside the OpenGL drawing callback.
Parameters ( cnum )
Bind selected pixel container (cnum) to the specified texture image unit.
Can only be used inside the OpenGL drawing callback.
Parameters ( cnum, texture_unit )
Example
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:
Notes about the fragment 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 )
Return value: ID of the new container with GLSL program, or negative value in case of some error; (container must be removed manually).
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 )
Examples
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 )
Examples
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 system transformation.
Reset transformation.
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 (4×4 FLOAT).
Parameters ( matrix_container )
Set transformation matrix (4×4 FLOAT).
Parameters ( matrix_container )
Multiply transformation matrix (4×4 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 )
Examples
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 )
Return value: sample rate in Hz.
Parameters ( disable_enable )
Parameters ( note, finetune )
Return value: note frequency in Hz.
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 )
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 )
Possible values for the action parameter:
Parameters ( thread_function, user_data, flags_optional )
Return value: thread ID or -1 if error occurred.
Examples
fn 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 )
Return value:
Examples
new_mutex = mutex_create() mutex_lock( new_mutex ) mutex_unlock( new_mutex ) mutex_destroy( new_mutex )
acos( x ); acosh( x ); asin( x ); asinh( x ); atan( x ); atanh( x ); ceil( x ); cos( x ); cosh( x ); exp( x ); exp2( x ); expm1( x ); abs( x ); floor( x ); mod( x, y ); log( x ); log2( x ); log10( x ); pow( base, exp ); sin( x ); sinh( x ); sqrt( x ); tan( x ); tanh( x );
rand() - get random number from 0 to 32767; rand_seed( seed ) - set random seed.
Execute data processing operation. Operands:
Operation expression:
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
Examples
//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:
Operation expression:
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:
Operation expression:
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 )
Examples
//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 )
Return value: 0 if success.
Parameters ( sample_info )
Examples
sample_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 )
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 )
Return value: 0 if success.
Parameters ( filter, output, input, flags, offset, size )
Return value: 0 if success.
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 )
Examples
//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 )
Open file dialog.
Parameters ( dialog_name, mask, id, default_name )
Return value: ID of the container with selected file name; or -1 if file not selected; (container must be removed manually).
Open window with global Pixilang preferences.
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 )
Return value: symbol ID or -1 if error occured.
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 )
Examples
if argc() >= 4 { a = argv( 3 ) remove( a ) }
Quit from Pixilang.
Parameters ( exit_code )
Examples
exit( 4 ) //Exit with code 4