First, any prerequisite for v8 experiments requires an ability to build v8 from source. Have a look at these guides:
http://code.google.com/apis/v8/build.html
And see if you can build v8 on your machine.
If successful, investigate the following github project:
https://github.com/philogb/v8-gl
The build instructions are for mac - but it may be possible to also build on other platforms
On Windows in particular, the bindings may be the trickiest part to get right. You will have to bind to "freeglut" instead of glut.
If windows is proving particularly difficult, consider installing
https://www.virtualbox.org/
and then
http://www.ubuntu.com/
For OpenGL, you may need to install the Mesa3D OpenGL implementation:
http://www.mesa3d.org/
Then proceed through the v8 and v8-gl installations on that virtual machine.
sudo apt-get update
sudo aptitude install build-essential
sudo apt-get install git-core
sudo apt-get install subversion
sudo apt-get install scons
sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev
In Lab 01, you kicked off with this c program:
[[helloopengl.cpp]]
Here is a Javascript version of the same application:
function renderScene()
{
Gl.clear( Gl.COLOR_BUFFER_BIT);
Gl.color3f(1.0, 0.0, 0.0);
Gl.rectf(-25.0, 25.0, 25.0, -25.0);
Gl.flush();
}
function setupRC()
{
Gl.clearColor(0, 0, 1, 1);
Glu.ortho2D(-100.0, 100.0, -100, 100.0);
}
function main()
{
Glut.init();
Glut.initDisplayMode(Glut.SINGLE | Glut.RGB);
Glut.createWindow("Lab 01 js");
setupRC();
Glut.displayFunc(renderScene);
Glut.mainLoop();
}
main();
This was Lab03 in c++
[[reshape.cpp]]
Reworked as javascript:
function renderScene()
{
Gl.clear( Gl.COLOR_BUFFER_BIT);
Gl.color3f(1.0, 0.0, 0.0);
Gl.rectf(-25.0, 25.0, 25.0, -25.0);
Gl.flush();
}
function setupRC()
{
Gl.clearColor(0, 0, 1, 1);
Glu.ortho2D(-100.0, 100.0, -100, 100.0);
}
function changeSize(w, h)
{
Gl.viewport(0,0, w, h);
Gl.matrixMode( Gl.PROJECTION);
Gl.loadIdentity();
var aspectRatio = w / h;
if (w <= h)
{
Glu.ortho2D(-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio);
}
else
{
Glu.ortho2D(-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0);
}
Gl.matrixMode(Gl.MODELVIEW);
Gl.loadIdentity();
}
function main()
{
Glut.init();
Glut.initDisplayMode(Glut.SINGLE | Glut.RGB);
Glut.createWindow("Lab 03 js");
setupRC();
Glut.displayFunc(renderScene);
Glut.reshapeFunc(changeSize);
Glut.mainLoop();
}
main();
Lab04:
[[bounce.cpp]]
and the Javascript version:
var windowWidth;
var windowHeight;
var x = -25;
var y = 25;
function renderScene()
{
Gl.clear( Gl.COLOR_BUFFER_BIT);
Gl.color3f(1.0, 0.0, 0.0);
Gl.rectf(x, y, x+50, y-50);
Gl.flush();
}
function setupRC()
{
Gl.clearColor(0, 0, 1, 1);
Glu.ortho2D(-100.0, 100.0, -100, 100.0);
}
function changeSize(w, h)
{
Gl.viewport(0,0, w, h);
Gl.matrixMode( Gl.PROJECTION);
Gl.loadIdentity();
var aspectRatio = w / h;
if (w <= h)
{
windowWidth = 100;
windowHeight = 100 / aspectRatio;
Glu.ortho2D(-100.0, 100.0, -windowHeight, windowHeight, 1.0, -1.0);
}
else
{
windowWidth = 100 * aspectRatio;
windowHeight = 100;
Glu.ortho2D(-windowWidth, windowWidth, -100.0, 100.0, 1.0, -1.0);
}
Gl.matrixMode(Gl.MODELVIEW);
Gl.loadIdentity();
}
var xstep = 1;
var ystep = 1;
function update()
{
if (x > windowWidth - 50 || x < -windowWidth)
xstep = -xstep;
if (y > windowHeight || y < -windowHeight + 50)
ystep = -ystep;
x += xstep;
y += ystep;
}
function timerFunction(value)
{
update();
Glut.postRedisplay();
Glut.timerFunc(25, timerFunction, 1);
}
var lastTime = 0;
function idleFunction()
{
var currentTime = new Date();
//print(currentTime.getUTCMilliseconds());
if (lastTime == 0)
lastTime = currentTime.getMilliseconds();
var currTime = currentTime.getMilliseconds();
var deltaTime = currTime - lastTime;
// print(deltaTime);
if (deltaTime > 100)
{
update();
lastTime = currTime;
Glut.postRedisplay();
}
}
function main()
{
Glut.init();
Glut.initDisplayMode(Glut.SINGLE | Glut.RGB);
Glut.createWindow("Lab 04 js");
setupRC();
Glut.displayFunc(renderScene);
Glut.reshapeFunc(changeSize);
//Glut.timerFunc(33, timerFunction, 1);
Glut.idleFunc(idleFunction);
Glut.mainLoop();
}
main();
V8 does not include any standard io functions, so debugging/testing this toolkit could be quite a challenge.
However, it does provide sophisticated Javascript based debugging, discussed here:
http://code.google.com/p/v8/wiki/AddDebuggerSupport
Additionally, we could attempt to introduce some simple print functions into the v8-gl bindings. I.e. would could introduce a simple function:
void print (char * s)
{
pringf (s);
}
How would you approach this?
Some sample extensions form the main project:
http://code.google.com/p/v8/source/browse/trunk/src/extensions/?r=8431
and is discussed here:
http://code.google.com/apis/v8/embed.html