From 2ab7fad7b308debba0aacbf76831569f360d19a0 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 18 Nov 2021 19:14:35 +0800 Subject: *misc --- .../BuiltIn/Libraries/GameLab/BuiltInResources.lua | 34 ++++++++++++++++++++++ .../BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua | 33 ++++++++++++++++----- .../Libraries/GameLab/Engine/Rendering/Texture.lua | 3 ++ .../Libraries/GameLab/Engine/Rendering/init.lua | 8 +++++ Data/BuiltIn/Libraries/GameLab/Entity.lua | 11 ------- Data/BuiltIn/Libraries/GameLab/Node.lua | 11 +++++++ Data/BuiltIn/Libraries/GameLab/define.lua | 6 ++++ Data/BuiltIn/Libraries/GameLab/init.lua | 19 ++++++++++-- 8 files changed, 103 insertions(+), 22 deletions(-) create mode 100644 Data/BuiltIn/Libraries/GameLab/BuiltInResources.lua create mode 100644 Data/BuiltIn/Libraries/GameLab/Engine/Rendering/Texture.lua delete mode 100644 Data/BuiltIn/Libraries/GameLab/Entity.lua create mode 100644 Data/BuiltIn/Libraries/GameLab/Node.lua create mode 100644 Data/BuiltIn/Libraries/GameLab/define.lua (limited to 'Data/BuiltIn/Libraries') diff --git a/Data/BuiltIn/Libraries/GameLab/BuiltInResources.lua b/Data/BuiltIn/Libraries/GameLab/BuiltInResources.lua new file mode 100644 index 0000000..03da57e --- /dev/null +++ b/Data/BuiltIn/Libraries/GameLab/BuiltInResources.lua @@ -0,0 +1,34 @@ +local find = GameLab.Find +local Shader = find "GameLab.Engine.Rendering.Shader" +local Texture = find "GameLab.Engine.Rendering.Texture" +local define = find "GameLab.define" +local Rendering = find "GameLab.Engine.Rendering" + +local SHADER = function(path) + local file = define.builtInPath .. '/Resources/Shaders/' .. path + return Rendering.CreateShaderFromFile(file) +end + +local TEXTURE = function(path) + -- local file = define.builtInPath .. '/Resources/Images/' .. path + -- return Rendering.CreateShaderFromFile(file) +end + +local res = {} + +local loadRes = function() + res.shaders = { + ["EditorShape"] = SHADER "Editor-Shape.glsl", + ["EditorText"] = SHADER "Editor-Text.glsl", + ["EditorUI"] = SHADER "Editor-UI.glsl", + } + + res.textures = { + ["White"] = TEXTURE "white.png", + } +end + +-- 加载默认资源 +GameLab.onApplicationStart:Add(loadRes) + +return res \ No newline at end of file diff --git a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua b/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua index 3030b38..c2677bc 100644 --- a/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua +++ b/Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua @@ -1,10 +1,17 @@ -local Debug = GameLab.Debug - local GUI = GameLab.Package("GameLab.Engine.GUI") -local GUIState = GUI.GUIState +local find = GameLab.Find -local Event = GameLab.Events.Event +local Res = require "GameLab.BuiltInResources" +local EditorGUI = GameLab.Editor.GUI + +local Debug = GameLab.Debug +local GUIState = GUI.GUIState +local Event = GameLab.Events.Event +local shaders = Res.shaders +local GL = GameLab.Engine.GL +local Matrix44 = find "GameLab.Engine.Math.Matrix44" +local Rendering = GameLab.Engine.Rendering GUI.BeginOnGUI = function() GUIState.ResetControlID() @@ -37,13 +44,23 @@ end GUI.Label = function() end - -GUI.Box = function() - +local shader +GUI.Box = function(position, color, size) + --Rendering.UseShader(Res.shaders["EditorShape"]) + local ortho = Matrix44() + ortho:SetOrtho(0, size.x, size.y, 0, 0.1, 10) + if shader == nil then + shader = Rendering.Shader.CreateFromFile("./Resources/Shaders/Editor-Text.glsl") + end + + Rendering.UseShader(shader) + Rendering.SetMatrix44("gamelab_mat_mvp", ortho) + Rendering.SetVector2("gamelab_ui_position", {0, 0}) + EditorGUI.Text(_G["default_font"], "你好世界!\nMaterials\nHello,World!\nProject Window Properties", 12) end GUI.HorizontalSlider = function() - + end GUI.VerticalSlider = function() diff --git a/Data/BuiltIn/Libraries/GameLab/Engine/Rendering/Texture.lua b/Data/BuiltIn/Libraries/GameLab/Engine/Rendering/Texture.lua new file mode 100644 index 0000000..4623f27 --- /dev/null +++ b/Data/BuiltIn/Libraries/GameLab/Engine/Rendering/Texture.lua @@ -0,0 +1,3 @@ +local Texture = GameLab.Engine.Rendering.Texture or {} + +return Texture \ No newline at end of file diff --git a/Data/BuiltIn/Libraries/GameLab/Engine/Rendering/init.lua b/Data/BuiltIn/Libraries/GameLab/Engine/Rendering/init.lua index 9966ea2..daa8bda 100644 --- a/Data/BuiltIn/Libraries/GameLab/Engine/Rendering/init.lua +++ b/Data/BuiltIn/Libraries/GameLab/Engine/Rendering/init.lua @@ -21,4 +21,12 @@ m.SetTexture = Shader.SetTexture m.UseShader = Shader.Use m.UnuseShader = Shader.Unuse +m.CreateShaderFromFile = function( path ) + local glsl = GameLab.IO.ReadFile(path, GameLab.IO.EFileMode.Text) + if glsl ~= nil then + local shader = Shader.New(glsl) + return shader + end +end + return m \ No newline at end of file diff --git a/Data/BuiltIn/Libraries/GameLab/Entity.lua b/Data/BuiltIn/Libraries/GameLab/Entity.lua deleted file mode 100644 index 4da28f9..0000000 --- a/Data/BuiltIn/Libraries/GameLab/Entity.lua +++ /dev/null @@ -1,11 +0,0 @@ ---https://stackoverflow.com/questions/27897714/whats-the-distinction-between-an-entity-and-a-game-object --- 游戏中的实体 -local Entity = GameLab.GlobalClass("GameLab.Entity") - -Entity.Ctor = function(self) - self.m_Components = {} - -end - - -return Entity \ No newline at end of file diff --git a/Data/BuiltIn/Libraries/GameLab/Node.lua b/Data/BuiltIn/Libraries/GameLab/Node.lua new file mode 100644 index 0000000..7eab18a --- /dev/null +++ b/Data/BuiltIn/Libraries/GameLab/Node.lua @@ -0,0 +1,11 @@ +--https://stackoverflow.com/questions/27897714/whats-the-distinction-between-an-Node-and-a-game-object +-- 游戏中的实体 +local Node = GameLab.GlobalClass("GameLab.Node") + +Node.Ctor = function(self) + self.m_Components = {} -- node properties + +end + + +return Node \ No newline at end of file diff --git a/Data/BuiltIn/Libraries/GameLab/define.lua b/Data/BuiltIn/Libraries/GameLab/define.lua new file mode 100644 index 0000000..dd4420e --- /dev/null +++ b/Data/BuiltIn/Libraries/GameLab/define.lua @@ -0,0 +1,6 @@ + +local define = {} + +define.builtInPath = "./BuiltIn" + +return define diff --git a/Data/BuiltIn/Libraries/GameLab/init.lua b/Data/BuiltIn/Libraries/GameLab/init.lua index de60ca3..2912d68 100644 --- a/Data/BuiltIn/Libraries/GameLab/init.lua +++ b/Data/BuiltIn/Libraries/GameLab/init.lua @@ -14,8 +14,20 @@ GameLab.Import = function(packageName) return import end +local gfind = function (name) + local t = _G + local pkgs = string.gmatch(name, "%.*(%w+)%.*") + for pkg in pkgs do + t = t[pkg] + if t == nil then + return nil + end + end + return t +end + GameLab.Find = function(name) - local m = _G[name] + m = require(name) if m ~= nil then return m end @@ -23,14 +35,13 @@ GameLab.Find = function(name) if m ~= nil then return m end - m = require(name) + local m = gfind(name) return m end GameLab.Include = GameLab.Find local import = GameLab.Import(...) - import "Package" import "Class" import "GlobalClass" @@ -42,4 +53,6 @@ import "EventListener" import "StaticClass" import "GlobalStaticClass" +GameLab.onApplicationStart = GameLab.Delegate() + return GameLab \ No newline at end of file -- cgit v1.1-26-g67d0