Backend

interface Backend

All drawing operations are done from here. By having this as an interface, this lets us have different backends, which leaves open the possibility of creating a multi-platform kotlin project with a different Backend for the js platform for use in a browser.

NOTE. LoggingBackend doesn't draw anything, but lets us create test cases without setting up an OpenGL.

Inheritors

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract 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
abstract 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
abstract fun clear(color: Color)

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

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
abstract fun createTexture(name: String, width: Int, height: Int, pixels: IntArray): Texture
Link copied to clipboard
abstract fun createWindow(width: Int, height: Int): Window
Link copied to clipboard
abstract fun drawFrame(window: Window, block: () -> Unit)
Link copied to clipboard
abstract fun drawTexture(texture: Texture, srcX: Float, srcY: Float, width: Float, height: Float, destX: Float, destY: Float, destWidth: Float = width, destHeight: Float = height, modelMatrix: Matrix? = null)

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
abstract fun drawTintedTexture(texture: Texture, tint: Color, srcX: Float, srcY: Float, width: Float, height: Float, destX: Float, destY: Float, destWidth: Float = width, destHeight: Float = height, modelMatrix: Matrix? = null)
Link copied to clipboard
abstract fun drawView(width: Float, height: Float, scale: Float, block: () -> Unit)
Link copied to clipboard
abstract fun endClipping()
Link copied to clipboard
abstract fun fillQuarterCircle(x1: Float, y1: Float, x2: Float, y2: Float, color: Color, radius: Float)
Link copied to clipboard
abstract fun fillRect(rect: GlokRect, color: Color)
abstract fun fillRect(left: Float, top: Float, right: Float, bottom: Float, color: Color)
Link copied to clipboard
abstract fun gradient(triangles: FloatArray, colors: Array<Color>)

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

Link copied to clipboard
abstract fun hsvGradient(triangles: FloatArray, colors: Array<FloatArray>)
Link copied to clipboard
abstract fun monitorSize(): Pair<Int, Int>?
Link copied to clipboard
abstract fun processEvents(timeoutSeconds: Double)
Link copied to clipboard
open fun reportError(): Boolean
Link copied to clipboard
abstract fun resources(path: String): Resources
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
abstract fun setCursor(window: Window, cursor: StandardCursor)
Link copied to clipboard
abstract fun strokeInsideRect(rect: GlokRect, thickness: Float, color: Color)
abstract fun strokeInsideRect(left: Float, top: Float, right: Float, bottom: Float, thickness: Float, color: Color)
Link copied to clipboard
abstract fun strokeQuarterCircle(x1: Float, y1: Float, x2: Float, y2: Float, color: Color, radius: Float, innerRadius: Float)
Link copied to clipboard
abstract 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.