Mercurial > hg > Members > e085737 > sample
view map/resources/render/init.js~ @ 20:d322eed6e1c7
add
author | <e085737> |
---|---|
date | Thu, 13 Jan 2011 21:37:23 +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){ alert("gl miss"); 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; } walk_init(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){ alert("aaaa") 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"); }