Skip to content

Commit 63e3bde

Browse files
committed
Update examples and readme
1 parent 2b2c239 commit 63e3bde

File tree

9 files changed

+36
-46
lines changed

9 files changed

+36
-46
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ npm i -s glfw-raub
2222
* Has `Window` class, simplifying low-level interactions.
2323
* Has `Document` class, capable of tricking other libs, as if we are in a browser.
2424

25+
```js
26+
import glfw from 'glfw-raub';
27+
const { Window } = glfw;
28+
29+
const wnd = new Window({ title: 'GLFW Test', vsync: true });
30+
31+
wnd.loop(() => {
32+
if (wnd.shouldClose || wnd.getKey(glfw.KEY_ESCAPE)) {
33+
process.exit(0);
34+
return;
35+
}
36+
37+
glfw.testScene(wnd.width, wnd.height);
38+
});
39+
```
40+
2541
> Note: this **addon uses N-API**, and therefore is ABI-compatible across different
2642
Node.js versions. Addon binaries are precompiled and **there is no compilation**
2743
step during the `npm i` command.
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
'use strict';
2-
3-
const glfw = require('../');
1+
import glfw from '../index.js';
42
const { Window } = glfw;
53

64

75
const w1 = new Window({ title: 'GLFW Events', vsync: true });
86

9-
107
const makeEventLogger = (name) => (e) => { e.target = null; console.log(`[${name}]`, e); };
118
const eventList = [
129
'blur', 'click', 'drop', 'focus', 'focusin', 'focusout', 'resize', 'iconifiy',
1310
'keydown', 'keyup', 'mousedown', 'mouseenter', 'mouseleave', 'mouseup',
1411
'quit', 'refresh', 'wresize', 'wheel', 'move',
15-
// 'mousemove', // too much logging
12+
// 'mousemove', // too many events
1613
];
1714

1815
eventList.forEach((name) => w1.on(name, makeEventLogger(name)));
1916

20-
const loopFunc = () => {
17+
w1.loop(() => {
2118
if (w1.shouldClose || w1.getKey(glfw.KEY_ESCAPE)) {
2219
process.exit(0);
2320
return;
2421
}
2522

2623
glfw.testScene(w1.width, w1.height);
27-
w1.requestAnimationFrame(loopFunc);
28-
};
29-
w1.requestAnimationFrame(loopFunc);
24+
});

examples/icon.js renamed to examples/icon.mjs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const glfw = require('../');
1+
import glfw from '../index.js';
42
const { Window } = glfw;
53

64

@@ -28,13 +26,11 @@ const icon = {
2826
w1.icon = icon;
2927

3028

31-
const loopFunc = () => {
29+
w1.loop(() => {
3230
if (w1.shouldClose || w1.getKey(glfw.KEY_ESCAPE)) {
3331
process.exit(0);
3432
return;
3533
}
3634

3735
glfw.testScene(w1.width, w1.height);
38-
w1.requestAnimationFrame(loopFunc);
39-
};
40-
w1.requestAnimationFrame(loopFunc);
36+
});
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const glfw = require('../');
1+
import glfw from '../index.js';
42
const { Window } = glfw;
53

64
let mode = 'windowed';
@@ -31,13 +29,11 @@ w1.on('keydown', (e) => {
3129
});
3230

3331

34-
const loopFunc = () => {
32+
w1.loop(() => {
3533
if (w1.shouldClose || w1.getKey(glfw.KEY_ESCAPE)) {
3634
process.exit(0);
3735
return;
3836
}
3937

4038
glfw.testScene(w1.width, w1.height);
41-
w1.requestAnimationFrame(loopFunc);
42-
};
43-
w1.requestAnimationFrame(loopFunc);
39+
});
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
'use strict';
2-
3-
const glfw = require('../');
1+
import glfw from '../index.js';
42
const { Window } = glfw;
53

64

75
// Default MSAA is 0
8-
const w1 = new Window({ title: 'GLFW MSAA x0', msaa: 0, vsync: true });
9-
const w2 = new Window({ title: 'GLFW MSAA x4', msaa: 4, vsync: true });
6+
const w1 = new Window({ title: 'GLFW MSAA x0', msaa: 0, vsync: true, width: 640, height: 480 });
7+
const w2 = new Window({ title: 'GLFW MSAA x4', msaa: 4, vsync: true, width: 640, height: 480 });
108

119

1210
const draw = () => {
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const glfw = require('../');
1+
import glfw from '../index.js';
42
const { Window } = glfw;
53

64

examples/perf.js renamed to examples/perf.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const glfw = require('../');
1+
import glfw from '../index.js';
42
const { Window } = glfw;
53

64

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const glfw = require('../');
1+
import glfw from '../index.js';
42
const { Window } = glfw;
53

64

@@ -17,13 +15,11 @@ w1.on(
1715
);
1816

1917

20-
const loopFunc = () => {
18+
w1.loop(() => {
2119
if (w1.shouldClose || w1.getKey(glfw.KEY_ESCAPE)) {
2220
process.exit(0);
2321
return;
2422
}
2523

2624
glfw.testScene(w1.width, w1.height);
27-
w1.requestAnimationFrame(loopFunc);
28-
};
29-
w1.requestAnimationFrame(loopFunc);
25+
});
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
'use strict';
2-
3-
const EventEmitter = require('events');
4-
5-
const glfw = require('../');
1+
import glfw from '../index.js';
2+
import EventEmitter from 'node:events';
63

74

85
const isVulkanSupported = glfw.vulkanSupported();

0 commit comments

Comments
 (0)