Mercurial > hg > Members > e085737 > sample
view Reserve/resources/render/init.js @ 26:943490f525c5
latest
author | <e085737> |
---|---|
date | Wed, 16 Feb 2011 22:01:34 +0900 |
parents | |
children |
line wrap: on
line source
function init(w, h) { var gl = initWebGL("screen", "vshader", "fshader", [ "vNormal", "vTexCoord", "vPosition"], [ 0, 0, 0, 1 ], 10000); if(!gl){ return; } gl.uniform3f(gl.getUniformLocation(gl.program, "lightDir"), 0, -1, 0); gl.uniform1i(gl.getUniformLocation(gl.program, "sampler2d"), 0); gl.enable(gl.TEXTURE_2D); gl.sgroot = new SceneGraphRoot(); if(!gl.sgroot){ return; } main(gl, gl.sgroot, w, h); return gl; } width = 1; height = -1; function reshape(ctx, sgroot) { var canvas = document.getElementById('screen'); if (canvas.width == width && canvas.width == height){ return; } width = canvas.width; height = canvas.height; // 画面の調節はいまだ手作業 ctx.viewport(0, 0, width, height); } function drawPicture(ctx,sgroot,w,h) { reshape(ctx, sgroot); ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT); //sgroot.getCamera(ctx) MainLoop(ctx,sgroot,w,h); ctx.flush(); framerate.snapshot(); currentAngle += incAngle; if (currentAngle > 360){ currentAngle -= 360; } } function start(){ var c = document.getElementById("screen"); var w = Math.floor(window.innerWidth * 0.9); var h = Math.floor(window.innerHeight * 0.9); c.width = w; c.height = h; theta_xz = 90; theta_yz = 0; cameraAngle_xyz = new Array(0,0,0); var ctx = init(w, h); if(!ctx){ return; } document.onkeydown = HandleKeyDown; document.onkeyup = HandleKeyUp; currentAngle = 0; incAngle = 2.0; var f = function() { drawPicture(ctx,ctx.sgroot,w,h) }; setInterval(f, 10); framerate = new Framerate("framerate"); }