-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.ts
More file actions
72 lines (63 loc) · 1.96 KB
/
dev.ts
File metadata and controls
72 lines (63 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import Attribute from './src/core/Attribute';
import Drawable from './src/core/Drawable';
import Stage from './src/core/Stage';
import Uniform from './src/core/Uniform';
import Vector2 from './src/math/Vector2';
import Texture from './src/core/Texture';
import Font from './src/core/Font';
import ImageUtil from './src/utils/ImageUtil';
import Color from './src/core/Color';
const canvas = document.createElement('canvas');
canvas.width = 1000;
canvas.height = 1000;
const gl = canvas.getContext('webgl');
gl.clearColor(0, 0, 0, 0);
document.body.appendChild(canvas);
const stage = new Stage(gl, 1000, 1000);
class Triangle extends Drawable {
constructor() {
super(
`
attribute vec2 a_position;
attribute vec4 a_color;
varying vec4 v_color;
void main() {
v_color = a_color;
gl_Position = projection(a_position);
}
`,
`
varying vec4 v_color;
void main() {
gl_FragColor = v_color;
}
`
);
this._endIndex = 3;
}
}
const vertices = new Attribute(new Float32Array(6), Attribute.FLOAT, 2);
vertices.set(0, 0, 0);
vertices.set(1, 0, 100);
vertices.set(2, 100, 100);
const colors = new Attribute(new Float32Array(12), Attribute.FLOAT, 4);
colors.set(0, 1, 0, 0, 1);
colors.set(1, 0, 1, 0, 1);
colors.set(2, 0, 0, 1, 1);
const triangle = new Triangle();
triangle.position.x = 100;
triangle.position.y = 100;
//triangle.rotation = Math.PI / 2;
triangle.attachAttribute('a_position', vertices);
triangle.attachAttribute('a_color', colors);
stage.add(triangle);
function render() {
stage.clear();
stage.render();
triangle.rotation = (triangle.rotation + 0.01) % (Math.PI * 2);
requestAnimationFrame(render);
}
render();
document.onmousedown = e => {
console.log(`click: ${stage.clickTest(e.clientX, e.clientY)}`);
}