node-gl-bindings

0.0.3 • Public • Published

node-gl-bindings

A simple GLFW and OpenGL binding package for NodeJS.
It is missing alot of functions and constants, if you would like to contribute create a pull request.

[!WARNING] This will only work on Windows.

npm install node-gl-bindings
import {gl, glfw, constants} from 'node-gl-bindings';
const width = 600;
const height = 600;

if (glfw.init() === 0) {console.log(new Error('Failed to init')); process.exit(1)};
const window = glfw.createWindow(width, height, 'window', null as any, null as any);

if (window.isNull()) {
    console.log(new Error('Failed to create GLFW window'));
    glfw.terminate();
    process.exit(1);
}
glfw.makeContextCurrent(window);
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.viewport(0, 0, width, height);

while (!glfw.windowShouldClose(window)) {
    glfw.pollEvents();
    gl.clear(constants.COLOR_BUFFER_BIT | constants.DEPTH_BUFFER_BIT);
    
    gl.matrixMode(constants.GL_MODELVIEW);
    gl.loadIdentity();

    gl.begin(constants.QUADS);
    gl.color3f(1.0, 0.0, 0.0);

    gl.vertex2f(-0.5, 0.5);
    gl.vertex2f(0.5, 0.5);
    gl.vertex2f(0.5, -0.5);
    gl.vertex2f(-0.5, -0.5);

    gl.end()
    glfw.swapBuffers(window);
}

glfw.destroyWindow(window);
glfw.terminate();

Readme

Keywords

none

Package Sidebar

Install

npm i node-gl-bindings

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

2.74 MB

Total Files

17

Last publish

Collaborators

  • koloja