comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:0b8d8ce99f46
1 function init(w, h)
2 {
3 var gl = initWebGL("screen", "vshader", "fshader",
4 [ "vNormal", "vTexCoord", "vPosition"],
5 [ 0, 0, 0, 1 ], 10000);
6
7 if(!gl){
8 return;
9 }
10 gl.uniform3f(gl.getUniformLocation(gl.program, "lightDir"), 0, -1, 0);
11 gl.uniform1i(gl.getUniformLocation(gl.program, "sampler2d"), 0);
12 gl.enable(gl.TEXTURE_2D);
13 gl.sgroot = new SceneGraphRoot(gl,w,h);
14 if(!gl.sgroot){
15 return;
16 }
17 main(gl,gl.sgroot, w, h);
18 return gl;
19 }
20
21
22
23
24 width = 1;
25 height = -1;
26
27 function reshape(ctx, sgroot)
28 {
29 var canvas = document.getElementById('screen');
30 if (canvas.width == width && canvas.width == height){
31 return;
32 }
33 width = canvas.width;
34 height = canvas.height;
35 // 画面の調節はいまだ手作業
36 ctx.viewport(0, 0, width, height);
37 }
38
39 function drawPicture(ctx,sgroot,w,h)
40 {
41 reshape(ctx, sgroot);
42 ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT);
43 //sgroot.getCamera(ctx)
44 MainLoop(ctx,sgroot,w,h);
45 ctx.flush();
46 framerate.snapshot();
47 currentAngle += incAngle;
48 if (currentAngle > 360){
49 currentAngle -= 360;
50 }
51 }
52
53 function start(){
54 var c = document.getElementById("screen");
55 var w = Math.floor(window.innerWidth * 0.9);
56 var h = Math.floor(window.innerHeight * 0.9);
57 c.width = w;
58 c.height = h;
59 theta_xz = 90;
60 theta_yz = 0;
61 cameraAngle_xyz = new Array(0,0,0);
62 var ctx = init(w, h);
63 if(!ctx){
64 return;
65 }
66 document.onkeydown = HandleKeyDown;
67 document.onkeyup = HandleKeyUp;
68 currentAngle = 0;
69 incAngle = 2.0;
70 var f = function() { drawPicture(ctx,ctx.sgroot,w,h) };
71 setInterval(f, 10);
72 framerate = new Framerate("framerate");
73 }
74