blob: a8c5be1a8b21ce0aa4f24cced22c11b6064bab03 [file] [log] [blame]
function main(p){
var log = p.log.bind(p);
log("script randomness: " + Math.random());
var gl;
var v = 0;
function drawFrame() {
v++;
var b = (1 + Math.sin(v / Math.PI / 7)) / 2;
gl.clearColor(0, 0, b, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.swapBuffers(drawFrame);
}
p.onchangeview = function(view) {
log("-- in p.onchangeview()");
log("--- isFullscreen: " + view.isFullscreen);
log("--- isVisible: " + view.isVisible);
log("--- isPageVisible: " + view.isPageVisible);
log("--- deviceScale: " + view.deviceScale);
log("--- cssScale: " + view.cssScale);
log("--- rect.x: " + view.rect.x);
log("--- rect.y: " + view.rect.y);
log("--- rect.width: " + view.rect.width);
log("--- rect.height: " + view.rect.height);
log("--- clipRect.x: " + view.clipRect.x);
log("--- clipRect.y: " + view.clipRect.y);
log("--- clipRect.width: " + view.clipRect.width);
log("--- clipRect.height: " + view.clipRect.height);
var rect = view.rect;
if (!gl) {
gl = new p.Graphics3D(rect);
var b = gl.createBuffer();
log("--- buffer: " + b);
gl.bindBuffer(gl.ARRAY_BUFFER, b);
var vertices = [
// Front face
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
// Back face
-1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
1.0, -1.0, -1.0,
// Top face
-1.0, 1.0, -1.0,
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
1.0, 1.0, -1.0,
// Bottom face
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
1.0, -1.0, 1.0,
-1.0, -1.0, 1.0,
// Right face
1.0, -1.0, -1.0,
1.0, 1.0, -1.0,
1.0, 1.0, 1.0,
1.0, -1.0, 1.0,
// Left face
-1.0, -1.0, -1.0,
-1.0, -1.0, 1.0,
-1.0, 1.0, 1.0,
-1.0, 1.0, -1.0
];
gl.bufferData(gl.ARRAY_BUFFER,
new Float32Array(vertices),
gl.STATIC_DRAW);
// gl.deleteBuffer(b);
drawFrame();
} else {
gl.resizeBuffers(rect);
}
// log("-- end p.onchangeview()");
};
}