Skip to content

Commit f585a74

Browse files
committed
Indices vbo added
1 parent bebf61d commit f585a74

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,16 @@ async function loop() {
1414
new Vector3(-0.5, 0.5, 0),
1515
new Vector3(-0.5, -0.5, 0),
1616
new Vector3(0.5, 0.5, 0),
17-
new Vector3(0.5, 0.5, 0),
18-
new Vector3(-0.5, -0.5, 0),
1917
new Vector3(0.5, -0.5, 0),
2018
], [
2119
new Color(1, 0, 0),
2220
new Color(0, 1, 0),
2321
new Color(0, 0, 1),
24-
new Color(0, 0, 1),
25-
new Color(0, 1, 0),
2622
new Color(0, 0, 0),
2723
], [
28-
24+
0, 1, 2, 2, 1, 3
2925
])
3026

31-
Shader.transformationMatrix = new Matrix4();
3227
Shader.projectionMatrix = Matrix4.createProjectionMatrix(
3328
canvas.width / canvas.height,
3429
70,

renderer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ class Renderer {
5454
static draw(model) {
5555
let positions = model.positions;
5656
let colors = model.colors;
57-
for (let i = 0; i < positions.length; i += 3) {
58-
let v1 = Shader.vertex(positions[i], colors[i]);
59-
let v2 = Shader.vertex(positions[i + 1], colors[i + 1]);
60-
let v3 = Shader.vertex(positions[i + 2], colors[i + 2]);
57+
let indices = model.indices;
58+
for (let i = 0; i < indices.length; i += 3) {
59+
let v1 = Shader.vertex(positions[indices[i]], colors[indices[i]]);
60+
let v2 = Shader.vertex(positions[indices[i + 1]], colors[indices[i + 1]]);
61+
let v3 = Shader.vertex(positions[indices[i + 2]], colors[indices[i + 2]]);
6162
this.drawTriangle([v1, v2, v3]);
6263
}
6364
}

0 commit comments

Comments
 (0)