WebGLBackend

The backend rendering code for the web (i.e. in a web browser). Unlike the JVM backend (GLBackend), the WebGLBackend only support a single instance of Window, which uses a html canvas.

Major difference between WebGL and a regular GL frame buffer :

A WebGL canvas has transparency by default
A WebGL canvas uses pre-multiplied alphas

I really don't want to deal with pre-multiplied alphas, so I've turned this off.

I've read that turning off alpha gives large a performance hit, so I've left it on. Instead, within clear, we ensure the fill color is fully opaque and then turn off the alpha channel with a color mask. I don't know if this is any quicker than turning off alpha completely.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun batch(texture: Texture, tint: Color?, modelMatrix: Matrix?, block: TextureBatch.() -> Unit)

OpenGL is moe efficient when operations can be batched. So rather than call drawTexture multiple times (with the same texture, tint, and modelMatrix), batch them and call TextureBatch.draw instead.

Link copied to clipboard
open override fun beginClipping(left: Float, top: Float, width: Float, height: Float): Boolean

Clip (scissor). The values are LogicalPixels measured from the TOP left of the window. The clipped region is the intersection of the currently clipped region and the newly requested region.

Link copied to clipboard
open override fun clear(color: Color)

Draws a flot color over the entire viewport. Used at the start of each redraw.

Link copied to clipboard
open override fun clearTransform()
Link copied to clipboard
open fun clip(left: Float, top: Float, width: Float, height: Float, block: () -> Unit)

A convenient way to call beginClipping and endClipping, with a block of code in between.

open fun clip(clip: Boolean, left: Float, top: Float, width: Float, height: Float, block: () -> Unit)
Link copied to clipboard
open override fun createTexture(name: String, width: Int, height: Int, pixels: IntArray): Texture

Creates a texture filled with the given color.

open override fun createTexture(name: String, width: Int, height: Int, color: Color): Texture

Creates a texture filled with the given color.

Link copied to clipboard
open override fun createWindow(width: Int, height: Int): Window

This must be called only once (i.e. only 1 window is allowed when using the WebGLBackend).

Link copied to clipboard
open override fun drawFrame(window: Window, block: () -> Unit)
Link copied to clipboard
open override fun drawTexture(texture: Texture, srcX: Float, srcY: Float, width: Float, height: Float, destX: Float, destY: Float, destWidth: Float, destHeight: Float, modelMatrix: Matrix?)

Draws the part of the texture defined by the rectangle srcX, srcY, height to destX, destY (which is where the top-left of the source corresponds to).

Link copied to clipboard
open override fun drawTintedTexture(texture: Texture, tint: Color, srcX: Float, srcY: Float, width: Float, height: Float, destX: Float, destY: Float, destWidth: Float, destHeight: Float, modelMatrix: Matrix?)
Link copied to clipboard
open override fun drawView(width: Float, height: Float, scale: Float, block: () -> Unit)
Link copied to clipboard
open override fun endClipping()
Link copied to clipboard
open override fun fileResources(path: String): Resources

In a JVM context, path is the path of a file (which may be a relative path). The textures are loaded immediately (unlike in a JS context, where there will be a delay).

Link copied to clipboard
open override fun fillCircle(centerX: Float, centerY: Float, radius: Float, color: Color)
Link copied to clipboard
open override fun fillQuarterCircle(centerX: Float, centerY: Float, cornerX: Float, cornerY: Float, color: Color, radius: Float)
Link copied to clipboard
open fun fillRect(rect: GlokRect, color: Color)
open override fun fillRect(left: Float, top: Float, right: Float, bottom: Float, color: Color)
Link copied to clipboard
open override fun gradient(triangles: FloatArray, colors: Array<Color>)

A gradient fill. Each vertex of each triangle has a color.

Link copied to clipboard
open override fun hsvGradient(triangles: FloatArray, colors: Array<FloatArray>)
Link copied to clipboard
open override fun monitorSize(): Pair<Int, Int>
Link copied to clipboard
open override fun noClipping(block: () -> Unit)
Link copied to clipboard
open override fun pollEvents(timeoutSeconds: Double)
Link copied to clipboard
open fun reportError(): Boolean
Link copied to clipboard
open override fun resources(path: String, klass: KClass<*>?): Resources

For built-in resources. The textures from Resources.loadTexture will be available immediately.

Link copied to clipboard
open fun saveRestoreState(block: () -> Unit)

If you need to use OpenGL while Glok is rendering a scene, you must perform these actions within a block. This saves the OpenGL state, runs the block, and then restores the state again.

Link copied to clipboard
open override fun setMousePointer(window: Window, cursor: MousePointer)
Link copied to clipboard
open override fun strokeCircle(centerX: Float, centerY: Float, radius: Float, innerRadius: Float, color: Color)
Link copied to clipboard
open fun strokeInsideRect(rect: GlokRect, thickness: Float, color: Color)
open fun strokeInsideRect(rect: GlokRect, insideRect: GlokRect, color: Color)
open fun strokeInsideRect(left: Float, top: Float, right: Float, bottom: Float, thickness: Float, color: Color)
open override fun strokeInsideRect(left: Float, top: Float, right: Float, bottom: Float, insideLeft: Float, insideTop: Float, insideRight: Float, insideBottom: Float, color: Color)
Link copied to clipboard
open override fun strokeQuarterCircle(centerX: Float, centerY: Float, cornerX: Float, cornerY: Float, color: Color, radius: Float, innerRadius: Float)
Link copied to clipboard
open override fun transform(transformation: Matrix)

open override fun transform(transformation: Matrix, block: () -> Unit)

Transforms the coordinates of all drawing calls within the block of code. Used by the Rotation node and ProxyNode.