I hope many of you have seen the excellent and fun WebGL GLSL sandbox at http://glsl.heroku.com/. This live editing of shaders is an excellent learning tool, as it allows you to watch the consequences of any changes you make.
I am constructing some simple OpenGL ES scripts as a learning resource for anyone new to it, in part as a way to help me learn it too. As part of this, I’ve written a little script that gives a similar kind of experience, but on the commandline, with a Raspberry Pi. It overlays the render display over the top of the framebuffer window, and reloads the shader any time you save the script.
You can run this from the terminal (as I do in the video later on) or from within LXDE (X11). (You may wish to replace ‘nano’ with ‘leafpad’ in glsl_sandbox.sh if you are running it in LXDE)
* Install pyinotify
$ sudo apt-get install python-pyinotify
* Get the repository:
$ wget https://github.com/benosteen/pyopengles/zipball/master -O pyopengles.zip $ unzip pyopengles.zip Inflating benosteen-pyopen.... ...
cd into the repository and you are ready to go!
Usage of ‘glsl_sandbox.sh’:
$ bash glsl_sandbox.sh [NAME_OF_SHADER_FILE]
The repository has a few demo shaders that are known to work included for you to try – they are copied from the WebGL sandbox site (http://glsl.heroku.com/)
‘basic.glsl’ – From http://glsl.heroku.com/e#2423.0
‘leds.glsl’ – From http://glsl.heroku.com/e#2450.0
‘raymarch.glsl’ – From http://glsl.heroku.com/e#2171.0
Pass the script any new filename, and it will create a new shader from the template and save it to that location.
This uses the “nano” text editor by default, as that is installed on the reference debian image, but if you look in the script, it is not hard to change to your preference 🙂
(NB Ctrl-O, followed by enter to save the file, and Ctrl-X to quit nano.)
Here is a video of it in action, as it is quite hard to describe in words.