allofw.node

Node.js bindings to liballofw.

Importing

var allofw = require("allofw");

class allofw.OpenGLWindow

allofw.OpenGLWindow is the class for OpenGL windows.

Create with liballofw config file allofw.yaml:

var window = new allofw.OpenGLWindow({
    config: "allofw.yaml"
});

Create with parameters:

var window = new allofw.OpenGLWindow({
    title: "Window Title",
    width: [width],
    height: [height],
    active_stereo: [true/false],
    hide_cursor: [true/false],
    fullscreen: [true/false]
});

Note: Fullscreen will use the current display resolution, regardless of the width and height.

Window Manager Events

User Input Events

Instance Methods

allofw.GL3

OpenGL 3 Bindings. The following rules apply:

Functions: To call OpenGL functions, remove the “gl” prefix, and decapitalize the first letter.

glViewport(x, y, w, h) -> GL.viewport(x, y, w, h)

Constants: To use OpenGL constants, remove the “GL_” prefix.

glDisable(GL_BLEND) -> GL.disable(GL.BLEND)

Objects: OpenGL objects (such as shaders, textures) maps to Javascript objects.

glCreateShader(GL_VERTEX_SHADER) -> new GL.Shader(GL.VERTEX_SHADER)
glGenTextures(...) -> new GL.Texture()

Objects are garbage-collected. Call obj.delete() for manual deletion. Call obj.id() to get the OpenGL id for the object.

Binding functions that accepts OpenGL objects supports both obj and obj.id(). However, the OmniStereo class only accepts obj.id().

Pointers: Javascript strings and Node.js Buffers can be used for string parameters and pointer parameters respectively.

class allofw.OmniStereo

Create an OmniStereo object with/without config file:

var omni = new allofw.OmniStereo();
var omni = new allofw.OmniStereo("allofw.yaml");

Instance Methods

Example

An example with OpenGLWindow and OmniStereo.

// Import the allofw library.
var allofw = require("allofw");
var GL = allofw.GL3;

// Create the window.
var w = new allofw.OpenGLWindow();
w.makeContextCurrent();

// Create the OmniStereo.
var omni = new allofw.OmniStereo("allofw.yaml");

// Set capture callback.
omni.onCaptureViewport(function() {
    GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT)
    GL.enable(GL.BLEND);
    GL.blendFunc(GL.ONE, GL.ONE_MINUS_SRC_ALPHA);
    // Render something here.
});

// Render as fast as possible.
var timer = setInterval(function() {
    // Capture the scene.
    omni.capture();
    // Composite the scene to the full window.
    var sz = w.getFramebufferSize();
    omni.composite(0, 0, sz[0], sz[1]);

    // Swap buffers.
    w.swapBuffers();

    // Poll window events.
    w.pollEvents();
    if(w.shouldClose()) {
        clearInterval(timer);
    }
}, 0);

w.onClose(function() {
    clearInterval(timer);
});

allofw.graphics

Bindings to the Skia graphics library for 2D graphics rendering.

allofw.log(level, string)

Add a line of log. level can be one of allofw.kInfo, allofw.kWarning, allofw.kError and allofw.kFatal.

class allofw.SharedMemory

Create the SharedMemory object with a key or existing shmid and semid:

var shm = new allofw.SharedMemory(key, size, is_create)
var shm = new allofw.SharedMemory(shmid, semid, size, is_create)

Instance Methods