GLScript

GLScript is a simple, easy-to-use, scripting language that allows users to develop 3D games and animations.
GLScript is completely open-source and is released under the GPL (General Public License)
GLScript can be used to create 3D games, animations, images/graphics etc.
It is regularly released with sample scripts for first time users to help understand it's inner workings.
Amongst these samples is the 'Eye' script which loads when GLScript launches.
thumb
GLScript uses the OpenGL API and gets its name from it.
In it's simplest form it is higher level interface for the OpenGL API.
Fundamentals in GLScript
Here are the very basic starting points for understanding GLScript
Variables
Defining Variables
Defining a variable is simple.
A variable is defined using the desired name for the variable, preceeded by a $ symbol,
This is followd by a colon and variable type (this is either a floating point value or a String)
For example, to define the variable 'X' of type float, you would use the following:
$X:float
Variable names are case-sensitive.
Errors like: "Error: Variable must have a valid type (Variable definition at line: 4)" may appear if the variable type is in an incorrect case.

Setting Variables
To set a variable you need the variable name and it's new value to be either side of the '=' operator.
So to set '$X' to 3 we would use this line:
$X = 3

You can also use many complex operations like:

$X = Sin($Y)*(5div$Z)^10

If you do this you must not leave spaces on the right side of the equals, if you dont you will get an error.
Testing/Comparing Variables
To compare two variables or one varable and a value you must use IF, THEN and ENDIF
So to check if the value of $X is 3 you would use something like this:
If $X = 3 Then
//This line will execute if $X = 3
EndIf
To avoid errors you must leave spaces after variable names in an if statement.
Commenting
To 'comment out' a line of script you can simply put two forward slashes before it.
Or if you want to just add a comment to your script to make it easier to understand latter you can do the same thing.
Clear //this line clears the screen
Markers and Event Markers

A marker can be defined using "Placemarker" like in:
PlaceMarker(Start)
Later it can be used to jump to this section of the script using "Goto".
For example:
Placemarker(RefreshLoop)
Swapbuffers
Placemarker(Refreshloop2)
Goto(Refreshloop2)
The technique above is used to 'Pause' the execution of a script, usually before jumping to an event marker.
An event marker is like a marker but is jumped to by presing a key on the keyboard, the following demonstrates how a variable can be increased every time the up arrow key is pressed.

$X:float
$X = 0
Placemarker(start)
Placemarker(RefreshLoop)
TextOut(0,0,0,$X)
Swapbuffers
Placemarker(RefreshLoop2)
Goto(RefreshLoop2)
Placemarker(KeyEvent_Up)
$X = $X+1<
Goto(RefreshLoop)
This script increases a number and places it on the screen whenever the up arrow key is pressed.
Supported commands
note: a more detailed look at GLScript's commands and functions can be found at:
The simplest commands are commands that draw complete objects for you and commands that are needed for basic functionality.
These include:
Clear - Clears the screen
Swapbuffers - Refreshes the screen
Sphere or WireSphere
Cylinder or WireCylinder
TextOut
These are just a few basic functions.
Many functions need parameters to be passed to them, For example the "Colour3F" and "WireSphere" functions.
If you wanted a green sphere like GLScript's logo, you would use the following:
Clear
Colour3F(0,1,0)
WireSphere(0.5,20,20)
Clear clears the screen.
Then colour3F changes the current colour; it wants to know the RGB values for the colour these are: 0,1,0 green is set to one red is 0 and blue is 0 so the colour will be green.
Wiresphere then needs to know it's parameters (Radius, Slices and Stacks).
You can also use variables and equations as parameters, here is an example.
$R:float
$G:float
$B:float
Colour3F($R/255,$G/255,$B/255)
 
< Prev   Next >