-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathicon.js
65 lines (43 loc) · 970 Bytes
/
icon.js
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
'use strict';
const glfw = require('../');
const { Window } = glfw;
const w1 = new Window({ title: 'GLFW Simple Test 1' });
const ICON_SIZE = 32;
const iconData = [];
for (let y = 0; y < ICON_SIZE; y++) {
for (let x = 0; x < ICON_SIZE; x++) {
const r = 255 * (x / (ICON_SIZE - 1));
const g = 255 * (y / (ICON_SIZE - 1));
const b = 255 * (1 - r * g);
iconData.push(r, g, b, 255);
}
}
const icon = {
width : ICON_SIZE,
height : ICON_SIZE,
data : Buffer.from(iconData),
noflip : true,
};
w1.icon = icon;
const draw = () => {
w1.makeCurrent();
const wsize1 = w1.framebufferSize;
glfw.testScene(wsize1.width, wsize1.height);
w1.swapBuffers();
glfw.pollEvents();
};
const animate = () => {
if ( ! (
w1.shouldClose ||
w1.getKey(glfw.KEY_ESCAPE)
) ) {
draw();
setTimeout(animate, 16);
} else {
// Close OpenGL window and terminate GLFW
w1.destroy();
glfw.terminate();
process.exit(0);
}
};
animate();