diff options
-rw-r--r-- | honey/asset/shader.lua | 43 | ||||
-rw-r--r-- | honey/ecs/script.lua | 22 | ||||
-rw-r--r-- | main.lua | 28 | ||||
-rw-r--r-- | palette.png | bin | 0 -> 36541 bytes | |||
-rw-r--r-- | starfield.png | bin | 0 -> 116815 bytes | |||
-rw-r--r-- | starfield2.png | bin | 0 -> 88326 bytes |
6 files changed, 90 insertions, 3 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) @@ -26,6 +26,26 @@ db:createEntityWithComponents{ }, } +-- skybox +db:createEntityWithComponents{ + node = { + matrix = Mat4() + :identity(), + }, + renderMesh = { + mesh = { + filename = "assets/skybox.obj", + index = 1, + }, + uniforms = { + textures = { + surface = { filename = "starfield2.png" }, + }, + }, + shader = { vertex = "builtin.basic3d.vert", fragment = "builtin.flat.frag" }, + }, +} + -- mesh db:createEntityWithComponents{ node = { @@ -37,15 +57,17 @@ db:createEntityWithComponents{ filename = "assets/dodecahedron.obj", index = 1, }, - textures = { - ourTexture = { filename = "assets/green-grass.jpg" }, + uniforms = { + textures = { + ourTexture = { filename = "assets/green-grass.jpg" }, + }, }, shader = { vertex="vertex.glsl", fragment="fragment.glsl" }, }, } honey.loop(function(dt) - gl.ClearColor(0.2, 0.4, 1.0, 1.0) + gl.ClearColor(0xa/0xff, 0x10/0xff, 0x1f/0xff, 1.0) gl.Clear(gl.COLOR_BUFFER_BIT + gl.DEPTH_BUFFER_BIT + gl.STENCIL_BUFFER_BIT) systems:update(dt) end) diff --git a/palette.png b/palette.png Binary files differnew file mode 100644 index 0000000..52a1cbd --- /dev/null +++ b/palette.png diff --git a/starfield.png b/starfield.png Binary files differnew file mode 100644 index 0000000..f67fc93 --- /dev/null +++ b/starfield.png diff --git a/starfield2.png b/starfield2.png Binary files differnew file mode 100644 index 0000000..c6a4853 --- /dev/null +++ b/starfield2.png |