Skip to content

Commit 27ceca3

Browse files
committed
apply all changes to examples as well
1 parent 433973e commit 27ceca3

File tree

8 files changed

+46
-242
lines changed

8 files changed

+46
-242
lines changed

example01/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
var gl;
8888
function initGL(canvas) {
8989
try {
90-
gl = canvas.getContext("experimental-webgl");
90+
gl = canvas.getContext("webgl");
9191
gl.viewportWidth = canvas.width;
9292
gl.viewportHeight = canvas.height;
9393
} catch(e) {
@@ -175,7 +175,7 @@
175175
1.0, 1.0,
176176
-1.0, 1.0,
177177
1.0, -1.0,
178-
-1.0, -1.0,
178+
-1.0, -1.0
179179
];
180180
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
181181
vertexPositionBuffer.itemSize = 2;
@@ -188,7 +188,7 @@
188188
[ 0.7, 1.2],
189189
[-2.2, 1.2],
190190
[ 0.7, -1.2],
191-
[-2.2, -1.2],
191+
[-2.2, -1.2]
192192
];
193193
function drawScene() {
194194
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
@@ -214,7 +214,7 @@
214214

215215
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
216216

217-
gl.deleteBuffer(plotPositionBuffer)
217+
gl.deleteBuffer(plotPositionBuffer);
218218

219219
zoom *= 1.02;
220220
document.getElementById("zoomOutput").value = zoom;
@@ -243,7 +243,7 @@
243243

244244
var canvas = document.getElementById("example01-canvas");
245245
initGL(canvas);
246-
initShaders()
246+
initShaders();
247247
initBuffers();
248248

249249
gl.clearColor(0.0, 0.0, 0.0, 1.0);

example02/glMatrix-0.9.5.min.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

example02/index.html

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<title>Learning WebGL &mdash; Mandelbrot shader on a spinning cube</title>
55
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
66

7-
<script type="text/javascript" src="glMatrix-0.9.5.min.js"></script>
8-
<script type="text/javascript" src="webgl-utils.js"></script>
7+
<script type="text/javascript" src="../js/gl-matrix-2.2.1.js"></script>
8+
<script type="text/javascript" src="../js/webgl-utils.js"></script>
99

1010

1111
<script id="color-shader-fs" type="x-shader/x-fragment">
@@ -125,7 +125,7 @@
125125
var gl;
126126
function initGL(canvas) {
127127
try {
128-
gl = canvas.getContext("experimental-webgl");
128+
gl = canvas.getContext("webgl");
129129
gl.viewportWidth = canvas.width;
130130
gl.viewportHeight = canvas.height;
131131
} catch(e) {
@@ -221,7 +221,8 @@
221221

222222
function mvPushMatrix() {
223223
var copy = mat4.create();
224-
mat4.set(mvMatrix, copy);
224+
// Update: mat4.set(mvMatrix, copy); mat4.set() was removed from gl-matrix, use mat4.copy().
225+
mat4.copy(copy, mvMatrix);
225226
mvMatrixStack.push(copy);
226227
}
227228

@@ -244,7 +245,7 @@
244245
}
245246

246247

247-
var cubes = Array();
248+
var cubes = [];
248249
function MandelbrotCube(xPos, yPos, zPos, xVel, yVel, zVel, xRot, yRot, zRot) {
249250
this.xPos = xPos;
250251
this.yPos = yPos;
@@ -307,19 +308,19 @@
307308
}
308309
}
309310
}
310-
}
311+
};
311312

312313

313314
MandelbrotCube.prototype.draw = function() {
314315
setCurrentProgram(mandelbrotProgram);
315316

316317
mat4.identity(mvMatrix);
317318

318-
mat4.translate(mvMatrix, [this.xPos, this.yPos, this.zPos]);
319+
mat4.translate(mvMatrix, mvMatrix, [this.xPos, this.yPos, this.zPos]);
319320

320-
mat4.rotate(mvMatrix, degToRad(this.xRot), [1, 0, 0]);
321-
mat4.rotate(mvMatrix, degToRad(this.yRot), [0, 1, 0]);
322-
mat4.rotate(mvMatrix, degToRad(this.zRot), [0, 0, 1]);
321+
mat4.rotate(mvMatrix, mvMatrix, degToRad(this.xRot), [1, 0, 0]);
322+
mat4.rotate(mvMatrix, mvMatrix, degToRad(this.yRot), [0, 1, 0]);
323+
mat4.rotate(mvMatrix, mvMatrix, degToRad(this.zRot), [0, 0, 1]);
323324

324325
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
325326
gl.vertexAttribPointer(mandelbrotProgram.vertexPositionAttribute, cubeVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0);
@@ -328,9 +329,9 @@
328329
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
329330
var positions = [];
330331
for (var i = 0; i < 6; i++) {
331-
positions.push(-2.2 / this.zooms[i] + this.centerOffsetsX[i], -1.2 / this.zooms[i] + this.centerOffsetsY[i]);;
332+
positions.push(-2.2 / this.zooms[i] + this.centerOffsetsX[i], -1.2 / this.zooms[i] + this.centerOffsetsY[i]);
332333
positions.push( 0.7 / this.zooms[i] + this.centerOffsetsX[i], -1.2 / this.zooms[i] + this.centerOffsetsY[i]);
333-
positions.push( 0.7 / this.zooms[i] + this.centerOffsetsX[i], 1.2 / this.zooms[i] + this.centerOffsetsY[i])
334+
positions.push( 0.7 / this.zooms[i] + this.centerOffsetsX[i], 1.2 / this.zooms[i] + this.centerOffsetsY[i]);
334335
positions.push(-2.2 / this.zooms[i] + this.centerOffsetsX[i], 1.2 / this.zooms[i] + this.centerOffsetsY[i])
335336
}
336337
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);
@@ -341,7 +342,7 @@
341342
gl.drawElements(gl.TRIANGLES, cubeVertexIndexBuffer.numItems, gl.UNSIGNED_SHORT, 0);
342343

343344
gl.deleteBuffer(positionBuffer);
344-
}
345+
};
345346

346347

347348
var boundingBoxVertexPositionBuffer;
@@ -376,7 +377,7 @@
376377
-5, 5, -10,
377378
-5, 5, -25,
378379
5, 5, -25,
379-
5, 5, -10,
380+
5, 5, -10
380381
];
381382
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
382383
boundingBoxVertexPositionBuffer.itemSize = 3;
@@ -408,7 +409,7 @@
408409
0.3, 0.3, 0.3, 1,
409410
0.3, 0.3, 0.3, 1,
410411
0.3, 0.3, 0.3, 1,
411-
0.3, 0.3, 0.3, 1,
412+
0.3, 0.3, 0.3, 1
412413
];
413414
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.STATIC_DRAW);
414415
boundingBoxVertexColorBuffer.itemSize = 4;
@@ -464,7 +465,7 @@
464465
-1.0, -1.0, -1.0,
465466
-1.0, -1.0, 1.0,
466467
-1.0, 1.0, 1.0,
467-
-1.0, 1.0, -1.0,
468+
-1.0, 1.0, -1.0
468469
];
469470
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertexPositions), gl.STATIC_DRAW);
470471
cubeVertexPositionBuffer.itemSize = 3;
@@ -479,7 +480,7 @@
479480
12, 13, 14, 12, 14, 15, // Bottom face
480481
16, 17, 18, 16, 18, 19, // Right face
481482
20, 21, 22, 20, 22, 23 // Left face
482-
]
483+
];
483484
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(vertexIndices), gl.STATIC_DRAW);
484485
cubeVertexIndexBuffer.itemSize = 1;
485486
cubeVertexIndexBuffer.numItems = 36;
@@ -490,7 +491,13 @@
490491
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
491492
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
492493

493-
mat4.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0, pMatrix);
494+
// Update: mat4.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0, pMatrix); mat4.perspective() API has changed.
495+
mat4.perspective (pMatrix, 45.0, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0);
496+
497+
// Update: mat4.translate(mvMatrix, [0, 0, -6]); mat4.translate() API has changed to mat4.translate(out, a, v)
498+
// where out is the receiving matrix, a is the matrix to translate, and v is the vector to translate by. z altered to
499+
// approximate original scene.
500+
mat4.translate(mvMatrix, mvMatrix, [0, 0, -4.7]);
494501

495502
for (var i in cubes) {
496503
cubes[i].draw();
@@ -500,6 +507,10 @@
500507
mat4.identity(mvMatrix);
501508

502509
gl.bindBuffer(gl.ARRAY_BUFFER, boundingBoxVertexPositionBuffer);
510+
511+
// Update: mat4.translate(mvMatrix, mvMatrix, [0, 0, 6]); added to more closely approximate original scene.
512+
mat4.translate(mvMatrix, mvMatrix, [0, 0, 6]);
513+
503514
gl.vertexAttribPointer(colorProgram.vertexPositionAttribute, boundingBoxVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0);
504515

505516
gl.bindBuffer(gl.ARRAY_BUFFER, boundingBoxVertexColorBuffer);

0 commit comments

Comments
 (0)