Class: WebGlContext

WebGlContext(canvas)

new WebGlContext(canvas)

JavaScript Library for simple 3d Objects using WebGl

Parameters:
Name Type Description
canvas Canvas
Source:

Members

MatrixMath :Object

A sub-object with helpful matrix math functions

Type:
  • Object
Source:

Methods

addElement(element)

Adds the element to the internal list of elements so it can be easily rendered using renderFrame()

Parameters:
Name Type Description
element Object
Source:

addShaders(element, vertexShaderSrc, fragmentShaderSrc)

Compiles the vertex and fragment shader and adds them to the element

Parameters:
Name Type Description
element Object
vertexShaderSrc String
fragmentShaderSrc String
Source:

adjustScreen()

Adjusts the context so it renders properly to the canvas (shouldn't be called when target is not canvas)

Source:

bindTexture(textureId, uniformTexture)

Binds (or unbinds) an texture (textureId should be the value of the uniform). Unbinds texture if uniformTexture is null.

Parameters:
Name Type Description
textureId number
uniformTexture Object
Source:

clear()

Clears the target

Source:

clearColor(r, g, b, a)

Sets the clear/backround-color

Parameters:
Name Type Description
r number

red

g number

green

b number

blue

a number

alpha

Source:

createAttribute(name, size) → {Object}

Creates a JSON with the needed information for an attribute used by the vertexshader

Parameters:
Name Type Description
name String
size number
Source:
Returns:
Type
Object

createBuffers(program, vertices, attributes, indicies)

Creates the neccecary buffers for an render-call

Parameters:
Name Type Description
program Program
vertices Array.<Number>
attributes Array.<{}>
indicies Array.<Number>
Source:

createCamera() → {Object}

Creates a JSON with the needed information for a Camera

Source:
Returns:
Type
Object

createElement() → {Object}

Creates a JSON with the needed information for an Element

Source:
Returns:
Type
Object

createProgram(vertexShaderSrc, fragmentShaderSrc)

Creates a ShaderProgram

Parameters:
Name Type Description
vertexShaderSrc String
fragmentShaderSrc String
Source:

createShader(src, type)

Creates a Shader

Parameters:
Name Type Description
src String
type number
Source:

createUniform(name, type) → {Object}

Creates a JSON with the needed information for an uniform used by the shaders

Parameters:
Name Type Description
name String
type String
Source:
Returns:
Type
Object

disableCullface()

Disables cullface

Source:

disableDepthtest()

Disables depthtesting

Source:

enableCullface()

Enables cullface

Source:

enableDepthtest()

Enables depthtesting

Source:

removeElement(element) → {boolean}

Removes the element from the internal list of elements so it won't be rendered using renderFrame()

Parameters:
Name Type Description
element Object
Source:
Returns:
Type
boolean

renderElement(element)

Renders an specific element to the target (usually canvas)

Parameters:
Name Type Description
element Object
Source:

renderFrame()

Renders all elements which were added using addElement to the target (usually canvas)

Source:

setCubeSide(uniform, side, width, height, data)

Sets the texture of a side of an uniform (smaplerCube) to supplied data

Parameters:
Name Type Description
uniform Object
side String

<+/-><x/y/z>

width number

same as height

height number

same as width

data Array.<Number>
Source:

setCubeSideToImage(uniform, side, imageUrl)

Sets the texture of a side of an uniform (smaplerCube) to an image

Parameters:
Name Type Description
uniform Object
side String

<+/-><x/y/z>

imageUrl String
Source:

setTarget(uniformTexture)

Sets a new target to render to and unbinds all textures so an texture is not used as input and output at once. Default target is canvas. To render to canvas pass null as an parameter.

Parameters:
Name Type Description
uniformTexture Object
Source:

setTexture(uniform, width, height, data)

Sets the texture of an uniform (smapler2D) to supplied data

Parameters:
Name Type Description
uniform Object
width number
height number
data Array.<Number>

RGBA integer values [0;255]

Source:

setTextureToImage(uniform, imageUrl)

Sets the texture of an uniform (smapler2D) to an image

Parameters:
Name Type Description
uniform Object
imageUrl String
Source: