view paper_shooting/resources/render/init.js @ 25:158b846e3874

paper
author <e085737>
date Mon, 14 Feb 2011 16:37:16 +0900
parents
children 6468848f4d22
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 reshape2(ctx, sgroot)
{
	var canvas = document.getElementById('screen');
	if (canvas.width == width && canvas.width == height){
		return;
	}
	width = canvas.width;
	height = canvas.height;
	// 画面の調節はいまだ手作業
	ctx.viewport(width/4*3, height/4*3, width/4, height/4);
    ctx.perspectiveMatrix.lookat(6,0,0,0,0,0,0,1,0);
}

function drawPicture(ctx,sgroot,w,h)
{
	reshape(ctx, sgroot);
	ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT);
	MainLoop(ctx,sgroot,w,h);
/*
	reshape2(ctx, sgroot);
	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");
}