gl-now
Create a WebGL context right now!
This module is an extension of game-shell that creates a WebGL enabled canvas and adds it to the specified container.
Example
//Initialize shellvar shell = shell shell shell
Result:
Install
npm install gl-now
API
var shell = require("gl-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. (Defaultgl.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 to1.0
)clearStencil
value to clear stencil buffer to (Defaults to0
)extensions
a list of necessary WebGL extensions to support. Vendor prefix optional. You can access these extensions later using webglewglOptions
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