Skip to content

Commit cac7811

Browse files
committed
Adjust readme
1 parent f84b375 commit cac7811

File tree

1 file changed

+46
-42
lines changed

1 file changed

+46
-42
lines changed

README.md

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,37 @@ npm i -s webgl-raub
1313

1414
![Example](examples/screenshot.jpg)
1515

16-
**WebGL**/**OpenGL** bindings. The addon **does not provide** a window control system, and it
17-
**can not set up an OpenGL context** on its own. This API simply maps the
18-
native OpenGL function calls to their JS counterparts.
19-
2016
**TL;DR**: For a quick start, use [3d-core-raub](https://github.com/node-3d/3d-core-raub)
21-
or try the [Examples](/examples) (and note [package.json](/examples/package.json)).
22-
23-
> Note: this **addon uses N-API**, and therefore is ABI-compatible across different
24-
Node.js versions. Addon binaries are precompiled and **there is no compilation**
25-
step during the `npm i` command.
26-
27-
28-
## Details
17+
or look at [Examples](/examples).
2918

3019
```js
31-
const webgl = require('webgl-raub');
20+
import webgl from 'webgl-raub';
3221
```
3322

34-
Here `webgl` contains the **WebGL** API, like a `WebGLRenderingContext` instance would. See
35-
[WebGLRenderingContext docs](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext)
36-
for reference, and [TypeScript definitions](/index.d.ts) for the full list of exports.
37-
There are also numerous non-WebGL methods exported in case you want to use advanced OpenGL functions.
23+
Here `webgl` contains the **WebGL/OpenGL** API, like a `WebGLRenderingContext` instance would.
24+
* See [WebGLRenderingContext docs](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext)
25+
for reference.
26+
* See [TS declarations](/index.d.ts) for the full list of exports.
27+
* There are also non-WebGL methods exported in case you want to use advanced OpenGL functions.
28+
* The addon **does not provide** a window control system, you can use
29+
[glfw-raub](https://github.com/node-3d/glfw-raub) (or anything else!) to create a window.
30+
31+
> This addon is ABI-compatible across Node.js versions. **There is no compilation** during the `npm install`.
32+
33+
The JS API mostly maps the native OpenGL function calls to their JS counterparts. E.g.:
34+
35+
```cpp
36+
// gl.clear(target)
37+
DBG_EXPORT JS_METHOD(clear) { NAPI_ENV;
38+
REQ_INT32_ARG(0, target);
39+
glClear(target);
40+
RET_WEBGL_VOID;
41+
}
42+
```
43+
44+
You can optionally call `webgl.init()` after the GL context becomes available - this translates
45+
into a `glewInit()` call. See [GLEW docs](https://glew.sourceforge.net/basic.html) for what
46+
it does and if you need it (probably "yes"?).
3847
3948
To use browser **WebGL** libs, like [three.js](https://threejs.org/),
4049
several additional interfaces must also be provided to mimic the browser.
@@ -44,39 +53,26 @@ and additional browser-like interfaces.
4453
* Package [image-raub](https://github.com/node-3d/glfw-raub) loads and serves the image data as web
4554
[Image](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement#example) would.
4655
47-
Those two are bundled into
48-
the [3d-core-raub](https://github.com/node-3d/3d-core-raub) in a following manner:
56+
See [this example](/examples/textured.mjs) using both **GLFW** and **Image**.
57+
The main idea being as follows:
4958
50-
```js
59+
```
5160
import Image from 'image-raub';
5261
import webgl from 'webgl-raub';
5362
import glfw from 'glfw-raub';
5463
const { Document } = glfw;
5564

56-
Document.setImage(image); // plug this Image impl into the Document
57-
Document.setWebgl(webgl); // plug this WebGL impl into the Document
58-
59-
const doc = new Document();
60-
global.document = global.window = doc;
65+
Document.setImage(image); // plug Image impl into the Document
66+
Document.setWebgl(webgl); // plug WebGL impl into the Document
6167

62-
const canvas = document.createElement('canvas'); // === doc
63-
const gl = canvas.getContext('webgl'); // === webgl
68+
const doc = new Document({ width: 1600, height: 900, vsync: true });
69+
...
6470
```
6571
66-
You can optionally call `webgl.init()` after the GL context becomes available - this translates
67-
into a `glewInit()` call. See [GLEW docs](https://glew.sourceforge.net/basic.html) for what
68-
it does and if you need it (probably "yes"?).
69-
70-
> OSX Note: some features may depend on OpenGL profile being used. Core profile
71-
is necessary for VAO and other OpenGL 3.2+ features. Depending on your windowing
72-
backend, set the OpenGL profile of your preference.
73-
In case [glfw-raub](https://github.com/node-3d/glfw-raub) is used,
74-
the profile can be set through the `Window`/`Document`
75-
[constructor](https://github.com/node-3d/glfw-raub#class-window) or with
76-
`glfw.windowHint` calls.
77-
72+
Similarly, these modules are utilized in [3d-core-raub](https://github.com/node-3d/3d-core-raub).
73+
Using [3d-core-raub](https://github.com/node-3d/3d-core-raub), you can skip setting up
74+
most environment features for those libs.
7875
79-
---
8076
8177
## WebGL Libs
8278
@@ -85,5 +81,13 @@ implementation of **WebGL**.
8581
* [PixiJS](https://pixijs.com/) - seems to work with some minor hacks, as proven by this
8682
[example](https://github.com/node-3d/3d-core-raub/blob/master/examples/pixi/index.js).
8783
88-
Using [node-3d-core](https://github.com/node-3d/3d-core-raub), you can skip setting up
89-
most environment features for those libs.
84+
85+
## MacOS Note
86+
87+
Some features may depend on OpenGL profile being used. Core profile
88+
is necessary for VAO and other OpenGL 3.2+ features. Depending on your windowing
89+
backend, set the OpenGL profile of your preference.
90+
In case [glfw-raub](https://github.com/node-3d/glfw-raub) is used,
91+
the profile can be set through the `Window`/`Document`
92+
[constructor](https://github.com/node-3d/glfw-raub#class-window) or with
93+
`glfw.windowHint` calls.

0 commit comments

Comments
 (0)