Created
September 5, 2022 20:25
-
-
Save ker2x/21ccfd86d1c6b50053526fef9145dffb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kleolife.gl | |
import kleolife.data.GraphicData | |
import org.khronos.webgl.WebGLProgram | |
import org.khronos.webgl.WebGLRenderingContext | |
import org.khronos.webgl.WebGLShader | |
class GLUtils { | |
companion object { | |
fun clearScreen(gfx: GraphicData) { | |
gfx.ctx.clearColor(0.0f, 0.0f, 0.0f, 1.0f) | |
gfx.ctx.clear(WebGLRenderingContext.COLOR_BUFFER_BIT) | |
} | |
fun createShader(gfx: GraphicData, type: Int, source: String): WebGLShader? { | |
val shader = gfx.ctx.createShader(type) | |
gfx.ctx.shaderSource(shader, source) | |
gfx.ctx.compileShader(shader) | |
return shader | |
} | |
fun createProgram(gfx: GraphicData, vertexShader: WebGLShader, fragmentShader: WebGLShader): WebGLProgram? { | |
val program = gfx.ctx.createProgram() | |
gfx.ctx.attachShader(program, vertexShader) | |
gfx.ctx.attachShader(program, fragmentShader) | |
gfx.ctx.linkProgram(program) | |
return program | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment