annotate webGL/test2.html @ 0:9285dae61395 draft

1st commit,just play sounds.
author e105711 <yomitan.ie.u-ryukyu.ac.jp>
date Wed, 25 Apr 2012 23:45:59 +0900
parents
children 4fd71be3fb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 <!DOCTYPE html>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 <html>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 <head>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 <title>WebGL test2</title>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 <script src="src/keybord.js"></script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 <script src="src/sound.js"></script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 <script src="src/J3DI.js"></script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 <script src="src/J3DIMath.js"></script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 <script src="src/f4xml.js"></script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 <script src="src/const.js"></script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 <script src="src/mainfunc.js"></script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 <script src="src/jkl-parsexml.js"></script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 </head>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 <script id="vshader" type="x-shader/x-vertex">
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 uniform mat4 u_modelViewProjMatrix;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 uniform mat4 u_normalMatrix;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 uniform vec3 lightDir;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 attribute vec3 vNormal;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 attribute vec4 vTexCoord;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 attribute vec4 vPosition;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 varying float v_Dot;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 varying vec2 v_texCoord;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 void main()
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 {
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 gl_Position = u_modelViewProjMatrix * vPosition;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 v_texCoord = vTexCoord.st;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 vec4 transNormal = u_normalMatrix * vec4(vNormal,1);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 v_Dot = max(dot(transNormal.xyz, lightDir), 0.0);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 </script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 <script id="fshader" type="x-shader/x-fragment">
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 #ifdef GL_ES
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 precision mediump float;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 #endif
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 uniform sampler2D sampler2d;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 varying float v_Dot;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 varying vec2 v_texCoord;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 void main()
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 {
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 vec4 color = texture2D(sampler2d,v_texCoord);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 color += vec4(0.1,0.1,0.1,1);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 // if(color.a == 1.0)color=vec4(1,0,0,1);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 // else color=vec4(0,1,1,1);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 gl_FragColor = vec4(color.xyz * v_Dot, color.a);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 // gl_FragColor = vec4(color.xyz * v_Dot, 0.5);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 }
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 </script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 <script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 var WIDTH = 1024;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 var HEIGHT = 640;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 var MODE = TITLE;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 function start(){
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 var c = document.getElementById("example");
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 c.width = WIDTH;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 c.height = HEIGHT;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 var ctx = init();
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 l = function(){loop(ctx)};
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 setInterval(l,10);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 }
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 function init(){
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 var gl = initWebGL("example","vshader","fshader",["vNormal","vTexCoord","vPosition"],[0,0,0,1],10000);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 gl.uniform3f(gl.getUniformLocation(gl.program,"lightDir"),0,0,1);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 gl.uniform1i(gl.getUniformLocation(gl.program,"sampler2d"),0);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 gl.enable(gl.TEXTURE_2D);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 parseXml(gl);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 return gl;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 }
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 function loop(ctx){ //main loop
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 gameRender(ctx,MODE);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 }
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 width = -1;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 height = -1;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 function reshape(ctx)
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 {
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 var canvas = document.getElementById('example');
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 if (canvas.width == width && canvas.width == height)
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 return;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 width = canvas.width;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 height = canvas.height;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 ctx.viewport(0, 0, width, height);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 ctx.perspectiveMatrix = new J3DIMatrix4();
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 ctx.perspectiveMatrix.ortho(0, -200, 0, -140, 0, 10000);
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 }
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 </script>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 <style type="text/css">
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 canvas {
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 border: 2px solid black;
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 }
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 </style>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 <body onload="start()" onkeydown="keybordDown()" onkeypress="keybordPress()" onkeyup="keybordUp()" style='overflow:scroll'>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 <font size="4">
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 TITLE) SPACE:Go to MAIN MODE<br>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 MAIN MODE)S:High-hat &nbsp;&nbsp; D:Snare &nbsp;&nbsp; F:Kick &nbsp;&nbsp; J:Tom &nbsp;&nbsp; K:Cymbal &nbsp;&nbsp; SPACE:Play/Stop &nbsp;&nbsp; <!--A:AUTO PLAY<br>-->
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 <!-- AUTO PLAY)Q:Quit(Back to MAIN MODE)-->
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 </font>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 <canvas id="example">
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 There is supposed to be an example drawing here, but it's not important.
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 </canvas>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 <div id="framerate"></div>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 <div id="console"></div>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 </body>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 </html>
9285dae61395 1st commit,just play sounds.
e105711 <yomitan.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125