Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gl

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gl

Creates a WebGL context without a window

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20K
decreased by-10.63%
Maintainers
1
Weekly downloads
 
Created
Source

headless-gl

This is a gutted version of node-webgl with no external dependencies, DOM emulation or window handling. You can use it to create WebGL contexts for GPGPU programming and server-side rendering in node. It should also work in browsers that support WebGL.

Installation

Just do:

npm install gl

Currently only works on OS X. I think adding Linux should be easy, though Windows may be more complicated. If you have access to working Linux or Windows systems and want to contribute, please let me know.

Usage

To get a handle on the headless OpenGL context, just do:

var gl = require("gl");

Then you can use all the ordinary WebGL methods.

Example

Here is an example that creates an offscreen framebuffer, clears it to red, reads the result and writes the image to stdout as a PPM :

//Create context
var gl = require("gl");
var width   = 64;
var height  = 64;

//Create texture
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex)
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);

//Create frame buffer
var fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);

//Clear screen to red
gl.clearColor(1.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);

//Write output
var pixels = new Uint8Array(width * height * 3);
gl.readPixels(0, 0, width, height, gl.RGB, gl.UNSIGNED_BYTE, pixels);
process.stdout.write(["P3\n# gl.ppm\n", width, " ", height, "\n255\n"].join(""));
for(var i=0; i<pixels.length; ++i) {
  process.stdout.write(pixels[i] + " ");
}

Multiple Contexts

You can create multiple WebGL contexts if you like. To do this, just call:

var my_context = gl.createContext();

Which will work just like any other WebGL context. To get rid of a context when you are done with it, jst call destroy() on it:

my_context.destroy();

Why use this thing instead of node-webgl?

It depends on what you are trying to do. node-webgl is good if you are making a graphical application like a game. On the other hand, because headless-gl does not create any windows, it is suitable for running in a server environment. This means that you can use it to generate figures using OpenGL or perform GPGPU computations using shaders.

Credits

See LICENSES

Keywords

FAQs

Package last updated on 30 Jan 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc