| 2 | |
| 3 | export class HelloTriangleApp extends App { |
| 4 | constructor() { |
| 5 | super("Hello Triangle"); |
| 6 | |
| 7 | const vertices = [ |
| 8 | [ 0, 0.5, 0], |
| 9 | [ 0.5, -0.5, 0], |
| 10 | [-0.5, -0.5, 0], |
| 11 | ]; |
| 12 | |
| 13 | const colors = [ |
| 14 | [1, 0, 0, 1], |
| 15 | [0, 1, 0, 1], |
| 16 | [0, 0, 1, 1], |
| 17 | ]; |
| 18 | |
| 19 | const indices = [ |
| 20 | 0, 1, 2, |
| 21 | ]; |
| 22 | |
| 23 | this.vertices = new Float32Array(vertices.length * 3 + colors.length * 4); |
| 24 | for (let i = 0; i < vertices.length; i++) { |
| 25 | const vertex = vertices[i], color = colors[i]; |
| 26 | const offset = i * vertex.length + i * color.length; |
| 27 | this.vertices.set(vertex, offset); |
| 28 | this.vertices.set(color, offset + vertex.length); |
| 29 | } |
| 30 | |
| 31 | this.indices = new Uint16Array(indices); |
| 32 | } |
| 33 | |
| 34 | async init() { |
| 35 | const shaderModule = await this.loadShader("hello_triangle"); |