diff options
Diffstat (limited to 'Data/BuiltIn')
-rw-r--r-- | Data/BuiltIn/Libraries/GameLab/BuiltInResources.lua | 34 | ||||
-rw-r--r-- | Data/BuiltIn/Libraries/GameLab/Engine/GUI/IMGUI.lua | 33 | ||||
-rw-r--r-- | Data/BuiltIn/Libraries/GameLab/Engine/Rendering/Texture.lua | 3 | ||||
-rw-r--r-- | Data/BuiltIn/Libraries/GameLab/Engine/Rendering/init.lua | 8 | ||||
-rw-r--r-- | Data/BuiltIn/Libraries/GameLab/Entity.lua | 11 | ||||
-rw-r--r-- | Data/BuiltIn/Libraries/GameLab/Node.lua | 11 | ||||
-rw-r--r-- | Data/BuiltIn/Libraries/GameLab/define.lua | 6 | ||||
-rw-r--r-- | Data/BuiltIn/Libraries/GameLab/init.lua | 19 | ||||
-rw-r--r-- | Data/BuiltIn/Resources/Shaders/Editor-Shape.glsl | 34 | ||||
-rw-r--r-- | Data/BuiltIn/Resources/Shaders/Editor-Text.glsl | 46 | ||||
-rw-r--r-- | Data/BuiltIn/Resources/Shaders/Editor-UI.glsl | 45 |
11 files changed, 228 insertions, 22 deletions
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 diff --git a/Data/BuiltIn/Resources/Shaders/Editor-Shape.glsl b/Data/BuiltIn/Resources/Shaders/Editor-Shape.glsl new file mode 100644 index 0000000..5ce755f --- /dev/null +++ b/Data/BuiltIn/Resources/Shaders/Editor-Shape.glsl @@ -0,0 +1,34 @@ +#version 330 core +//绘制纯色的几何图形 + +CMD_BEGIN +Cull Off +Blend SrcAlpha OneMinusSrcAlpha +DepthTest Off +CMD_END + +uniform mat4 gamelab_mat_mvp; +uniform sampler2D gamelab_main_tex; +uniform vec2 gamelab_ui_position; +uniform vec4 gamelab_color; + +VSH_BEGIN +layout (location = 0) in vec2 vPos; + +void main() +{ + vec2 pos = vPos + gamelab_ui_position; + vec4 clipPos = gamelab_mat_mvp * vec4(pos, -1, 1.0); + gl_Position = clipPos; +} +VSH_END + +FSH_BEGIN + +out vec4 FragColor; + +void main() +{ + FragColor = gamelab_color; +} +FSH_END diff --git a/Data/BuiltIn/Resources/Shaders/Editor-Text.glsl b/Data/BuiltIn/Resources/Shaders/Editor-Text.glsl new file mode 100644 index 0000000..d1003c3 --- /dev/null +++ b/Data/BuiltIn/Resources/Shaders/Editor-Text.glsl @@ -0,0 +1,46 @@ +#version 330 core + +CMD_BEGIN +Cull Off +Blend SrcAlpha OneMinusSrcAlpha +DepthTest Off +CMD_END + +uniform mat4 gamelab_mat_mvp; +uniform sampler2D gamelab_main_tex; +uniform vec2 gamelab_ui_position; + +VSH_BEGIN +layout (location = 0) in vec2 vPos; +layout (location = 1) in vec2 vUV; +layout (location = 2) in vec4 vColor; + +out vec2 uv; +out vec4 color; + +void main() +{ + vec2 pos = vPos + gamelab_ui_position; + vec4 clip = gamelab_mat_mvp * vec4(pos, -1, 1.0); + gl_Position = clip; + uv = vUV; + color = vColor; +} +VSH_END + +FSH_BEGIN +in vec2 uv; +in vec4 color; + +out vec4 FragColor; + +void main() +{ + //vec2 uv = vec2(uv.x, 1 - uv.y); + vec4 sampled = vec4(0.8,0.8,0.8,texture(gamelab_main_tex, uv).r); + sampled *= color; + // if(sampled.a == 0) + // sampled = vec4(1,0,0,1); + FragColor = sampled; +} +FSH_END diff --git a/Data/BuiltIn/Resources/Shaders/Editor-UI.glsl b/Data/BuiltIn/Resources/Shaders/Editor-UI.glsl new file mode 100644 index 0000000..b2b348b --- /dev/null +++ b/Data/BuiltIn/Resources/Shaders/Editor-UI.glsl @@ -0,0 +1,45 @@ +#version 330 core + +CMD_BEGIN +Cull Off +Blend SrcAlpha OneMinusSrcAlpha +DepthTest Off +CMD_END + +uniform mat4 gamelab_mat_mvp; +uniform sampler2D gamelab_main_tex; +uniform vec2 gamelab_ui_position; + +VSH_BEGIN +layout (location = 0) in vec2 vPos; +layout (location = 1) in vec2 vUV; +layout (location = 2) in vec4 vColor; + +out vec2 uv; +out vec4 color; + +void main() +{ + vec2 pos = vPos + gamelab_ui_position; + vec4 clip = gamelab_mat_mvp * vec4(pos, -1, 1.0); + gl_Position = clip; + uv = vUV; + color = vColor; +} +VSH_END + +FSH_BEGIN +in vec2 uv; +in vec4 color; + +out vec4 FragColor; + +void main() +{ + //vec2 uv = vec2(uv.x, 1 - uv.y); + vec4 sampled = texture(gamelab_main_tex, uv); + // sampled *= color; + //sampled = vec4(1,1,1,1); + FragColor = sampled; +} +FSH_END |