diff options
Diffstat (limited to 'honey')
-rw-r--r-- | honey/asset/shader.lua | 43 | ||||
-rw-r--r-- | honey/ecs/script.lua | 22 |
2 files changed, 65 insertions, 0 deletions
diff --git a/honey/asset/shader.lua b/honey/asset/shader.lua index a23c17b..d1fecc4 100644 --- a/honey/asset/shader.lua +++ b/honey/asset/shader.lua @@ -140,4 +140,47 @@ clearCache = function() end +--===== builtin shaders =====-- + +builtin["builtin.basic3d.vert"] = [[ + #version 410 core + layout (location = 0) in vec3 in_position; + layout (location = 1) in vec3 in_normal; + layout (location = 2) in vec2 in_texture; + + uniform mat4 model; + uniform mat4 view; + uniform mat4 projection; + + out vec3 position; + out vec3 normal; + out vec2 tex; + + void main() + { + gl_Position = projection * view * model * vec4(in_position, 1.0); + + position = in_position; + normal = in_normal; + tex = in_texture; + } +]] + +builtin["builtin.flat.frag"] = [[ + #version 410 core + + out vec4 frag_color; + + in vec3 position; + in vec3 normal; + in vec2 tex; + + uniform sampler2D surface; + + void main() + { + frag_color = texture(surface, tex); + } +]] + return module diff --git a/honey/ecs/script.lua b/honey/ecs/script.lua index 46af4fa..a9b7644 100644 --- a/honey/ecs/script.lua +++ b/honey/ecs/script.lua @@ -1,3 +1,5 @@ +local glfw = honey.glfw + local ecs = require 'honey.ecs.ecs' local node = require 'honey.ecs.node' @@ -27,6 +29,26 @@ dispatch = function(db, msg, data) end end +--===== bind window events to script handlers =====-- + +bindEvents = function(window, db) + glfw.SetFramebufferSizeCallback(window, function(w, width, height) + dispatch(db, "onFramebufferSize", {window=w, width=width, height=height}) + end) + + glfw.SetKeyCallback(window, function(w, key, scancode, action, mods) + dispatch(db, "onKey", {window=w, key=key, scancode=scancode, action=action, mods=mods}) + end) + + glfw.SetCursorPosCallback(window, function(w, xpos, ypos) + dispatch(db, "onCursorPos", {window=w, xpos=xpos, ypos=ypos}) + end) + + glfw.SetMouseButtonCallback(window, function(w, button, action, mods) + dispatch(db, "onMouseButton", {window=w, button=button, action=action, mods=mods}) + end) +end + --===== script system =====-- local script = ecs.System("script", function(db, dt, params) |