Renderer

Class with all of the essential rendering setup and methods.

Constructor

new Renderer()

(DO NOT USE) Internal use by Hummingbird only, all methods are available on HB.renderer.

Members

(readonly) maxIndexCount

(DO NOT USE) Internal variable to keep track of max indices in one batch, default is 6000.

(readonly) maxVertexCount

(DO NOT USE) Internal variable to keep track of max vertices in one batch, default is 4000.

(readonly) textureUnits

(DO NOT USE) This is the amount of texture units available, for increased compatibility/performance.

Methods

clear(color)

Method for clearing the screen with a certain color, can only be called when a batch has been started.

Parameters:
NameTypeDescription
colorglMatrix.vec4

Color to clear the screen with.

colorEllipse(pos, size, color)

Method for drawing a colored ellipse on screen, can only be called when a batch has been started.

Parameters:
NameTypeDescription
posglMatrix.vec2

Top-left position of the ellipse.

sizeglMatrix.vec2

Size of the ellipse's individual axes.

colorglMatrix.vec4

Color of the ellipse.

colorLine(vectorA, vectorB, thickness, color)

Method for drawing a colored line on screen from one point to another, can only be called when a batch has been started.

Parameters:
NameTypeDescription
vectorAglMatrix.vec2

First point of the line.

vectorBglMatrix.vec2

Second point of the line.

thicknessnumber

The thickness of the line in pixels.

colorglMatrix.vec4

Color of the rectangle.

colorPoint(pos, size, color)

Method for drawing a colored point on screen, can only be called when a batch has been started.

Parameters:
NameTypeDefaultDescription
posglMatrix.vec2

Center position at which to draw the point.

sizenumber1

Size of the point, the point is a square defaulting to 1 pixel.

colorglMatrix.vec4

Color of the point.

colorPolygon(points, color, center)

Method for drawing a colored polygon on screen, can only be called when a batch has been started.

Parameters:
NameTypeDefaultDescription
pointsArray

Array of glMatrix.vec2s with positions of all points.

colorglMatrix.vec4

Color of the polygon.

centernumber0

Element of points Array which indicates the center of the polygon, only needed occasionally for concave polygons.

colorRectangle(pos, size, color)

Method for drawing a colored rectangle on screen, can only be called when a batch has been started.

Parameters:
NameTypeDescription
posglMatrix.vec2

Top-left position of the rectangle.

sizeglMatrix.vec2

Size of the rectangle.

colorglMatrix.vec4

Color of the rectangle.

colorText(string, pos, size, align, color) → {number}

Method for drawing colored text on screen, can only be called when a batch has been started.

Parameters:
NameTypeDefaultDescription
stringstring

ASCII text to be rendered, see the charset in https://projects.brandond.nl/Hummingbird/assets/arial_pretty.json for all characters.

posglMatrix.vec2

Position of the text, anchor-point determined by the align parameter.

sizenumber12

Pixel size (height) of the text.

alignstring"start-start"

Where to place the anchor-point, this is a string formatted as "'x-anchor'-'y-anchor'", e.g. "end-center". Possible values are [start, center, end], modelled after this.

colorglMatrix.vec4

Color of the text.

Returns:

Final width of the rendered text.

Type: 
number

delete()

(DO NOT USE) Internal method for cleaning up all renderer related objects (textures, shader, buffers, etc.), is automatically called when the window is closed.

drawArbitraryBatchedQuad(x0, y0, x1, y1, x2, y2, x3, y3, tex, col, textRange, sx, sy, sw, sh)

(DO NOT USE) Internal, most basic method for drawing a quad on screen. Use any of the quad methods instead (HB.Renderer#colorRectangle, HB.Renderer#textureRectangle, etc.). Can only be called when a batch has been started.

Parameters:
NameTypeDefaultDescription
x0number

Top-left x-coordinate.

y0number

Top-left y-coordinate.

x1number

Top-right x-coordinate.

y1number

Top-right y-coordinate.

x2number

Bottom-right x-coordinate.

y2number

Bottom-right y-coordinate.

x3number

Bottom-left x-coordinate.

y3number

Bottom-left y-coordinate.

texnumber0

Optional internal batch-specific texture ID.

colglMatrix.vec4{@link

HB.Colors.White} - Optional color of the quad.

textRangenumber0

Optional value to check whether text is being rendered and anti-alias it.

sxnumber0

UV x-coordinate of the texture, 0-1.

synumber0

UV y-coordinate of the texture, 0-1.

swnumber1

UV width of the texture, 0-1.

shnumber1

UV height of the texture, 0-1.

drawBatchedQuad(x, y, w, h, tex, col, textRange, sx, sy, sw, sh)

(DO NOT USE) Internal method for drawing a quad on screen. Use any of the quad methods instead (HB.Renderer#colorRectangle, HB.Renderer#textureRectangle, etc.). Can only be called when a batch has been started.

Parameters:
NameTypeDescription
xnumber

X-coordinate of the quad.

ynumber

Y-coordinate of the quad.

wnumber

Width of the quad.

hnumber

Height of the quad.

texnumber

Optional internal batch-specific texture ID.

colglMatrix.vec4

Optional color of the quad.

textRangenumber

Optional value to check whether text is being rendered and anti-alias it.

sxnumber

UV x-coordinate of the texture, 0-1.

synumber

UV y-coordinate of the texture, 0-1.

swnumber

UV width of the texture, 0-1.

shnumber

UV height of the texture, 0-1.

drawBatchedTriangle(x1, y1, x2, y2, x3, y3, color)

(DO NOT USE) Internal method for drawing a triangle on screen. Use HB.Renderer#colorPolygon instead. Can only be called when a batch has been started.

Parameters:
NameTypeDescription
x1number

X-coordinate of the first point.

y1number

Y-coordinate of the first point.

x2number

X-coordinate of the second point.

y2number

Y-coordinate of the second point.

x3number

X-coordinate of the third point.

y3number

Y-coordinate of the third point.

colorglMatrix.vec4

Color of the triangle.

drawIndexedTriangles(indexCount)

(DO NOT USE) Internal method with the final draw call, is automatically called by HB.Renderer#flushBatch.

Parameters:
NameTypeDescription
indexCountnumber

Amount of indices to be rendered.

drawRectangleWithRotation(pos, size, angle, texture, color)

(DO NOT USE) Internal method for drawing a rotated rectangle on screen. Use HB.Renderer#rotatedColorRectangle or HB.Renderer#rotatedTextureRectangle instead. Can only be called when a batch has been started.

Parameters:
NameTypeDefaultDescription
posglMatrix.vec2

Top-left position of the rectangle.

sizeglMatrix.vec2

Size of the rectangle.

anglenumber

Angle in radians with which the rectangle gets rotated around its center (pos[0] + (size[0] / 2), pos[1] + (size[1] / 2)).

textureHB.Texture0

If available, HB.Texture instance to texture with.

colorglMatrix.vec4{@link

HB.Colors.White} - If available, color of the rectangle.

endBatch()

Method for ending the rendering batch, is automatically called in HB.internalUpdate.

flushBatch()

(DO NOT USE) Internal method for rendering the current batch's contents, is automatically called by HB.Renderer#endBatch or HB.Renderer#flushBatchIfBufferFilled.

flushBatchIfBufferFilled(vertices, indices) → {boolean}

(DO NOT USE) Internal method to test whether the batch has to rendered to the screen, this happens whenever either the Vertex- or IndexBuffer is filled. Can only be called when a batch has been started.

Parameters:
NameTypeDefaultDescription
verticesnumber4

Amount of vertices to add to buffer for check.

indicesnumber6

Amount of indices to add to buffer for check.

Returns:

Whether the batch had to be rendered.

Type: 
boolean

getBatchTextureIndex(texture) → {number}

(DO NOT USE) Internal method to get a batch-specific texture ID. Can only be called when a batch has been started.

Parameters:
NameTypeDescription
textureHB.Texture

HB.Texture instance to texture with.

Returns:

Internal batch-specific texture ID.

Type: 
number

resetBatch()

(DO NOT USE) Internal method for resetting the rendering batch's variables, is automatically called by HB.Renderer#startBatch.

rotatedColorRectangle(pos, size, angle, color)

Method for drawing a rotated colored rectangle on screen, can only be called when a batch has been started.

Parameters:
NameTypeDescription
posglMatrix.vec2

Top-left position of the rectangle.

sizeglMatrix.vec2

Size of the rectangle.

anglenumber

Angle in radians with which the rectangle gets rotated around its center (pos[0]+size[0]/2, pos[1]+size[1]/2).

colorglMatrix.vec4

Color of the rectangle.

rotatedTextureRectangle(pos, size, angle, texture)

Method for drawing a rotated textured rectangle on screen, can only be called when a batch has been started.

Parameters:
NameTypeDescription
posglMatrix.vec2

Top-left position of the rectangle.

sizeglMatrix.vec2

Size of the rectangle.

anglenumber

Angle in radians with which the rectangle gets rotated around its center (pos[0] + (size[0] / 2), pos[1] + (size[1] / 2)).

textureHB.Texture

HB.Texture instance to texture with.

startBatch()

Method for starting a new rendering batch, is automatically called in HB.internalUpdate.

textureRectangle(pos, size, texture)

Method for drawing a textured rectangle on screen, can only be called when a batch has been started.

Parameters:
NameTypeDescription
posglMatrix.vec2

Top-left position of the rectangle.

sizeglMatrix.vec2

Size of the rectangle.

textureHB.Texture

HB.Texture instance to texture with.

(static) init()

(DO NOT USE) Internal method for creating the HB.renderer instance.