diff options
author | sanine <sanine.not@pm.me> | 2023-03-13 22:42:40 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-03-13 22:42:40 -0500 |
commit | 344d6e68bee7f286f7c4b4b25518367c595b4619 (patch) | |
tree | 9abb86b714fef18aef0d8048bd4931f6adcf9fd0 /main.lua | |
parent | 53b151b3fd6d4c2b953d8ed93261125577f1c123 (diff) |
add shader.lua
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 36 |
1 files changed, 8 insertions, 28 deletions
@@ -64,25 +64,10 @@ void main() } ]] --- vertex shader -local vertexShader = gl.CreateShader(gl.VERTEX_SHADER) -gl.ShaderSource(vertexShader, vertexShaderSource) -gl.CompileShader(vertexShader) - --- fragment shader -local fragmentShader = gl.CreateShader(gl.FRAGMENT_SHADER) -gl.ShaderSource(fragmentShader, fragmentShaderSource) -gl.CompileShader(fragmentShader) - --- link -local shader = gl.CreateProgram() -gl.AttachShader(shader, vertexShader) -gl.AttachShader(shader, fragmentShader) -gl.LinkProgram(shader) --- clean up -gl.DeleteShader(vertexShader) -gl.DeleteShader(fragmentShader) - +local shader = honey.Shader{ + vertex = vertexShaderSource, + fragment = fragmentShaderSource, +} local tetra = honey.mesh.loadFile("assets/tetrahedron.obj")[1] local cube = honey.mesh.loadFile("assets/cube.obj")[1] @@ -117,15 +102,10 @@ while not window:shouldClose() do gl.ClearColor(0.2, 0.4, 1.0, 1.0) gl.Clear(gl.COLOR_BUFFER_BIT + gl.DEPTH_BUFFER_BIT) - gl.UseProgram(shader) - - local modelLocation = gl.GetUniformLocation(shader, "model") - local viewLocation = gl.GetUniformLocation(shader, "view") - local projectionLocation = gl.GetUniformLocation(shader, "projection") - - gl.UniformMatrix4fv(modelLocation, false, model.data) - gl.UniformMatrix4fv(viewLocation, false, view.data) - gl.UniformMatrix4fv(projectionLocation, false, projection.data) + shader:use() + shader:setMatrix('model', model) + shader:setMatrix('view', view) + shader:setMatrix('projection', projection) mesh:drawElements() |