API Docs for:
Show:

gl Class

Defined in: ../src/core.js:29
Module: GL

the webgl context returned by GL.create, its a WebGLRenderingContext with some extra methods added

Methods

animate

()

Defined in ../src/core.js:111

Launch animation loop (calls gl.onupdate and gl.ondraw every frame) example: gl.ondraw = function(){ ... } or gl.onupdate = function(dt) { ... }

captureGamepads

()

Defined in ../src/core.js:444

Tells the system to capture gamepad events on the canvas.

captureKeys

(
  • prevent_default
  • only_canvas
)

Defined in ../src/core.js:361

Tells the system to capture key events on the canvas. This will trigger onkey

Parameters:

  • prevent_default Boolean

    prevent default behaviour (like scroll on the web, etc)

  • only_canvas Boolean

    only caches keyboard events if they happen when the canvas is in focus

captureMouse

(
  • capture_wheel
)

Defined in ../src/core.js:205

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 Boolean

    capture also the mouse wheel

create

(
  • options
)
Gl

Defined in ../src/core.js:2

creates a new WebGL context (it can create the canvas or use an existing one)

Parameters:

  • options Object

    supported are: width, height, canvas

Returns:

Gl:

gl context for webgl

destroy

()

Defined in ../src/core.js:166

Destroy this WebGL context (removes also the Canvas from the DOM)

drawTexture

(
  • texture
  • x
  • y
  • w
  • h
  • tx
  • ty
  • tw
  • th
)

Defined in ../src/core.js:613

draws a texture to the viewport

Parameters:

  • texture Texture
  • x Number

    in viewport coordinates

  • y Number

    in viewport coordinates

  • w Number

    in viewport coordinates

  • h Number

    in viewport coordinates

  • tx Number

    texture x in texture coordinates

  • ty Number

    texture y in texture coordinates

  • tw Number

    texture width in texture coordinates

  • th Number

    texture height in texture coordinates

execute

(
  • callback
)

Defined in ../src/core.js:97

executes callback inside this webgl context

Parameters:

  • callback Function

fullscreen

()

Defined in ../src/core.js:526

launches de canvas in fullscreen mode

getGamepads

()

Defined in ../src/core.js:466

returns the detected gamepads on the system

gl.reset

()

Defined in ../src/core.js:675

use it to reset the the initial gl state

loadTexture

(
  • url
  • options
  • callback
)
Texture

Defined in ../src/core.js:581

returns a texture and caches it inside gl.textures[]

Parameters:

  • url String
  • options Object

    (same options as when creating a texture)

  • callback Function

    function called once the texture is loaded

Returns:

Texture:

texture

makeCurrent

()

Defined in ../src/core.js:88

sets this context as the current global gl context (in case you have more than one)

snapshot

(
  • startx
  • starty
  • areax
  • areay
)
Canvas

Defined in ../src/core.js:543

returns a canvas with a snapshot of an area this is safer than using the canvas itself due to internals of webgl

Parameters:

  • startx Number

    viewport x coordinate

  • starty Number

    viewport y coordinate from bottom

  • areax Number

    viewport area width

  • areay Number

    viewport area height

Returns:

Canvas:

canvas