diff resources/render/init.js @ 0:0b8d8ce99f46 default tip

commit
author Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp>
date Mon, 14 Feb 2011 17:06:56 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/render/init.js	Mon Feb 14 17:06:56 2011 +0900
@@ -0,0 +1,74 @@
+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(gl,w,h);
+	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");
+}
+