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
returns true if button num is pressed (where num could be GL.LEFT_MOUSE_BUTTON, GL.RIGHT_MOUSE_BUTTON, GL.MIDDLE_MOUSE_BUTTON
Parameters:
-
capture_wheelBooleancapture also the mouse wheel
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
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
-
skip_mapping
returns the detected gamepads on the system
Parameters:
-
skip_mappingBoolif 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:
-
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
