gl Class
the webgl context returned by GL.create, its a WebGLRenderingContext with some extra methods added
Item Index
Methods
animate
()
Launch animation loop (calls gl.onupdate and gl.ondraw every frame) example: gl.ondraw = function(){ ... } or gl.onupdate = function(dt) { ... }
captureGamepads
()
Tells the system to capture gamepad events on the canvas.
captureKeys
-
prevent_default -
only_canvas
Tells the system to capture key events on the canvas. This will trigger onkey
Parameters:
-
prevent_defaultBooleanprevent default behaviour (like scroll on the web, etc)
-
only_canvasBooleanonly caches keyboard events if they happen when the canvas is in focus
captureMouse
-
capture_wheel
Tells the system to capture mouse events on the canvas. This will trigger onmousedown, onmousemove, onmouseup, onmousewheel callbacks assigned in the gl context example: gl.onmousedown = function(e){ ... } The event is a regular MouseEvent with some extra parameters
Parameters:
-
capture_wheelBooleancapture also the mouse wheel
create
-
options
creates a new WebGL context (it can create the canvas or use an existing one)
Parameters:
-
optionsObjectsupported are: width, height, canvas
Returns:
gl context for webgl
destroy
()
Destroy this WebGL context (removes also the Canvas from the DOM)
drawTexture
-
texture -
x -
y -
w -
h -
tx -
ty -
tw -
th
draws a texture to the viewport
Parameters:
-
textureTexture -
xNumberin viewport coordinates
-
yNumberin viewport coordinates
-
wNumberin viewport coordinates
-
hNumberin viewport coordinates
-
txNumbertexture x in texture coordinates
-
tyNumbertexture y in texture coordinates
-
twNumbertexture width in texture coordinates
-
thNumbertexture height in texture coordinates
execute
-
callback
executes callback inside this webgl context
Parameters:
-
callbackFunction
fullscreen
()
launches de canvas in fullscreen mode
getGamepads
()
returns the detected gamepads on the system
gl.reset
()
use it to reset the the initial gl state
loadTexture
-
url -
options -
callback
returns a texture and caches it inside gl.textures[]
Parameters:
-
urlString -
optionsObject(same options as when creating a texture)
-
callbackFunctionfunction called once the texture is loaded
Returns:
texture
makeCurrent
()
sets this context as the current global gl context (in case you have more than one)
snapshot
-
startx -
starty -
areax -
areay
returns a canvas with a snapshot of an area this is safer than using the canvas itself due to internals of webgl
Parameters:
-
startxNumberviewport x coordinate
-
startyNumberviewport y coordinate from bottom
-
areaxNumberviewport area width
-
areayNumberviewport area height
Returns:
canvas
