Commits

Diego Cantor  committed da4e5f4

ch3_Wall_Final updated: onkeydown instead of onkeypress

  • Participants
  • Parent commits 98a1382

Comments (0)

Files changed (1)

File 1727_03/ch3_Wall_Final.html

 <html>
-
 <head>
 <title>WebGL Beginner's Guide - Chapter 3 - The Wall</title>
 <meta http-equiv='content-type' content='text/html; charset=ISO-8859-1'>
-
 <!-- CSS Styles //-->
 <link href='css/style.css' 		type='text/css' rel='stylesheet'>
 <link href='css/desert.css' 	type='text/css' rel='stylesheet'/>
 <link href='css/smoothness/jquery-ui-1.8.13.custom.css' type='text/css' rel='stylesheet' />
 
+
 <!-- JavaScript Libraries //-->
 <script type='text/javascript' src='js/gl-matrix-min.js'></script>
 <script type='text/javascript' src='js/jquery-1.5.1.min.js'></script>
 <script id="shader-vs" type="x-shader/x-vertex">
 attribute vec3 aVertexPosition;
 attribute vec3 aVertexNormal;
-
 uniform mat4 uMVMatrix;
 uniform mat4 uPMatrix;
 uniform mat4 uNMatrix;
 var azimuth = 0; 
 var elevation = 0;
 
-document.onkeypress = processKey;
+document.onkeydown = processKey;
 function processKey(ev){
 
     var lightDirection = gl.getUniform(prg,prg.uLightDirection);
         2,7,6,
         3,7,2
     ];
-	
-    
-    
 	normals = utils.calculateNormals(vertices, indices);
-	 	
 	verticesBuffer = gl.createBuffer();
 	gl.bindBuffer(gl.ARRAY_BUFFER, verticesBuffer);
 	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
-	
 	normalsBuffer = gl.createBuffer();
 	gl.bindBuffer(gl.ARRAY_BUFFER, normalsBuffer);
 	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(normals), gl.STATIC_DRAW);
-	
 	indicesBuffer = gl.createBuffer();
 	gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indicesBuffer);
 	gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.STATIC_DRAW);
-	
 	gl.bindBuffer(gl.ARRAY_BUFFER, null);
     gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
-	
 }
 
 /**
 * Main rendering function. Called every 500ms according to WebGLStart function (see below)
 */
 function drawScene() {
-    
+
     gl.clearColor(0.12,0.12,0.12, 1.0);
     gl.clearDepth(100.0);
 	gl.enable(gl.DEPTH_TEST);
 	gl.depthFunc(gl.LEQUAL);
 	gl.viewport(0, 0, c_width, c_height);
 	gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
-    
-  
-        
+ 
 	mat4.perspective(45, c_width / c_height, 0.1, 10000.0, pMatrix);
     mat4.identity(mvMatrix);
-    
+
     //distance
     mat4.translate(mvMatrix, [0.0, 0.0, -40.0]); 
-
-    
     gl.uniformMatrix4fv(prg.uMVMatrix, false, mvMatrix);
 	gl.uniformMatrix4fv(prg.uPMatrix, false, pMatrix);
-	
     mat4.set(mvMatrix, nMatrix);
     mat4.inverse(nMatrix);
     mat4.transpose(nMatrix);
-    
     gl.uniformMatrix4fv(prg.uNMatrix, false, nMatrix);
     
     try{
     	//1. Enabling Vertex Attributes
         gl.enableVertexAttribArray(prg.aVertexPosition);
         gl.enableVertexAttribArray(prg.aVertexNormal);
-				
 		//2. Bind buffers 
 		gl.bindBuffer(gl.ARRAY_BUFFER, verticesBuffer);
-		gl.vertexAttribPointer(prg.aVertexPosition, 3, gl.FLOAT, false, 0, 0);
-		
+		gl.vertexAttribPointer(prg.aVertexPosition, 3, gl.FLOAT, false, 0, 0);		
 		gl.bindBuffer(gl.ARRAY_BUFFER, normalsBuffer);
 		gl.vertexAttribPointer(prg.aVertexNormal,3,gl.FLOAT, false, 0,0);
-		
 	    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,indicesBuffer);
-		gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_SHORT,0);
-        
+		gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_SHORT,0); 
 		gl.bindBuffer(gl.ARRAY_BUFFER, null);
 		gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
 	}
     drawScene();
 }
 
+
+
 /**
 * Entry point. This function is invoked when the page is loaded
 */
 </head>
 
 <body onLoad='runWebGLApp()'>
+
 <div id='top'>
 	<h1>WebGL Beginner's Guide - Chapter 3</h1>
 	<h2>The Wall</h2>
         
     </div>
 </div>
-
 <div id='bottom'>
 </div>
 <script>cview.run(cview.MODE_VIEW,true);</script>