Class Fz2D.CanvasWebGL

Defined in: src/renderer/canvas_webgl.coffee
Inherits: Fz2D.Canvas

Overview

Public: Canvas (WebGL)

Constant Summary

VERTEX_SHADER =
Private: Vertex Shader.
"precision mediump float;\n\nuniform vec2 screen;\nuniform vec2 texture;\n\nattribute vec4 pos;\nattribute vec4 uv;\n\nvarying vec2 texture_coord;\nvarying float alpha;\n\nvoid main(void)\n{ \n  texture_coord = uv.st * texture;\n  alpha = uv.w;\n  \n  float r = radians(uv.z);\n  float cosr = cos(r);\n  float sinr = sin(r);\n\n  vec2 pp = pos.xy - pos.zw;\n  vec2 p  = vec2(pp.x * cosr - pp.y * sinr, pp.x * sinr + pp.y * cosr);\n\n  p += pos.zw;\n  p *= screen;\n\n  ###~Private~###\n  gl_Position = vec4(p.x - 1.0, 1.0 - p.y, 0.0, 1.0);\n}"
FRAGMENT_SHADER =
Private: Fragment Shader.
"precision mediump float;\n\nuniform sampler2D texture_id;\nvarying vec2 texture_coord;\nvarying float alpha;\n  \nvoid main(void)\n{\n  vec4 color = texture2D(texture_id, texture_coord);\n  color.a *= alpha;\n\n  ###~Private~###\n  gl_FragColor = color;\n}"

Instance Method Summary

Inherited Method Summary

Methods inherited from Fz2D.Canvas

@getContext, .constructor, .fill, .clear, .flush, .draw, .toImage, .toElement

Constructor Details

::constructor() Source

Public: Constructor. w - width h - height color - background HTML color code (default: Fz2D.BG) selector - query selector or id (default: Fz2D.SELECTOR)

Parameters:

  • wwidth
  • hheight
  • colorbackground HTML color code (default: Fz2D.BG)
  • selectorquery selector or id (default: Fz2D.SELECTOR)

Instance Method Details

::clear() Source

Public: Clears the canvas.

::draw(texture, sx, sy, sw, sh, x, y, w, h, hw, hh, angle, alpha) Source

Public: Draws a Fz2D.Texture. texture - Fz2D.Texture sx - source position on the X axis sy - source position on the Y axis sw - source width sh - source height x - desired position on the X axis y - desired position on the Y axis w - desired width h - desired height hw - desired half width hh - desired half height angle - rotation angle alpha - alpha value

Parameters:

  • (Fz2D.Texture) textureFz2D.Texture
  • sxsource position on the X axis
  • sysource position on the Y axis
  • swsource width
  • shsource height
  • xdesired position on the X axis
  • ydesired position on the Y axis
  • wdesired width
  • hdesired height
  • hwdesired half width
  • hhdesired half height
  • anglerotation angle
  • alphaalpha value

::fill(color) Source

Public: Fills the canvas with a solid color. color - HTML color code

Parameters:

  • colorHTML color code

::flush() Source

Public: Flushes the canvas.