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_default
Booleanprevent default behaviour (like scroll on the web, etc)
-
only_canvas
Booleanonly 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_wheel
Booleancapture also the mouse wheel
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:
-
texture
Texture -
x
Numberin viewport coordinates
-
y
Numberin viewport coordinates
-
w
Numberin viewport coordinates
-
h
Numberin viewport coordinates
-
tx
Numbertexture x in texture coordinates
-
ty
Numbertexture y in texture coordinates
-
tw
Numbertexture width in texture coordinates
-
th
Numbertexture height in texture coordinates
execute
-
callback
executes callback inside this webgl context
Parameters:
-
callback
Function
fullscreen
()
launches de canvas in fullscreen mode
getGamepads
-
skip_mapping
returns the detected gamepads on the system
Parameters:
-
skip_mapping
Boolif set to true it returns the basic gamepad, otherwise it returns a class with mapping info to XBOX controller
gl.reset
()
use it to reset the the initial gl state
isMobile
()
Boolean
Tells you if the app is running on a mobile device (iOS or Android)
Returns:
true if is running on a iOS or Android device
loadTexture
-
url
-
options
-
callback
returns a texture and caches it inside gl.textures[]
Parameters:
-
url
String -
options
Object(same options as when creating a texture)
-
callback
Functionfunction 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:
-
startx
Numberviewport x coordinate
-
starty
Numberviewport y coordinate from bottom
-
areax
Numberviewport area width
-
areay
Numberviewport area height
Returns:
canvas