npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gl2-now

v1.4.2

Published

Create a WebGL2 context now!

Downloads

2

Readme

gl2-now

Create a WebGL(2) context right now!

This is a very minor fork of gl-now. I created it because I wanted to persist a single monkeypatched change. Playing around with WebGL requires asking the browser for different WebGL context ("webgl2", not "webgl"), and so, this fork was born. All the credits go to Mikola Lysenko, the original author.

gl-now is an extension of game-shell that creates a WebGL enabled canvas and adds it to the specified container.

Example

Try this demo in your browser

//Initialize shell
var shell = require("gl2-now")() //

shell.on("gl-init", function() {
  var gl = shell.gl
  
  //Create fragment shader
  var fs = gl.createShader(gl.FRAGMENT_SHADER)
  gl.shaderSource(fs, [
    "void main() {",
      "gl_FragColor = vec4(1, 0, 0, 1);",
    "}"].join("\n"))
  gl.compileShader(fs)

  //Create vertex shader
  var vs = gl.createShader(gl.VERTEX_SHADER)
  gl.shaderSource(vs, [
    "attribute vec3 position;",
    "void main() {",
      "gl_Position = vec4(position, 1.0);",
    "}"].join("\n"))
  gl.compileShader(vs)

  //Link
  var shader = gl.createProgram()
  gl.attachShader(shader, fs)
  gl.attachShader(shader, vs)
  gl.linkProgram(shader)
  gl.useProgram(shader)
  
  //Create buffer
  gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
    -1, 0, 0,
    0, -1, 0,
    1, 1, 0
  ]), gl.STATIC_DRAW)
  
  //Set up attribute pointer
  var position_attribute = gl.getAttribLocation(shader, "position")
  gl.enableVertexAttribArray(position_attribute)
  gl.vertexAttribPointer(position_attribute, 3, gl.FLOAT, false, 0, 0)
})

shell.on("gl-render", function(t) {
  var gl = shell.gl

  //Draw arrays
  gl.drawArrays(gl.TRIANGLES, 0, 3)
})

shell.on("gl-error", function(e) {
  throw new Error("WebGL not supported :(")
})

Result:

Install

npm install gl2-now

API

var shell = require("gl2-now")([options])

Options is an object that takes the same fields as in game-shell with the following additions:

  • clearFlags a list of flags to clear on redraw. (Default gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
  • clearColor a length 4 array representing background clear color. (Defaults to element's background-color or else [0.2, 0.4, 0.8, 1.0]
  • clearDepth value to clear depth buffer to (Defaults to 1.0)
  • clearStencil value to clear stencil buffer to (Defaults to 0)
  • extensions a list of necessary WebGL extensions to support. Vendor prefix optional. You can access these extensions later using webglew
  • glOptions on object containing a set of parameters which are passed to the webgl context directly.

Events

In addition to all the events inherited from game-shell, gl-now adds the following events:

gl-init

Called once the WebGL context is initialized

gl-render([frame_time])

Called at the start of the WebGL frame.

gl-error(reason)

Called if there was an error initializing webgl

gl-resize(width, height)

Called when the WebGL window is resized

Properties

Finally gl-now adds the following extra properties to game-shell:

shell.gl

The WebGL context

shell.canvas

The canvas object

shell.width

The width of the gl context

shell.height

The height of the context

shell.scale

The scale of the context, which defaults to 1. Set it to higher values for a smaller viewport and faster rendering at the expense of quality.

shell.mouse

A length 2 vector giving the current coordinate of the mouse on the screen

shell.prevMouse

A length 2 vector giving the previous coordinate of the mouse on the screen

Credits

(c) 2013 Mikola Lysenko. MIT License