diff options
author | chai <chaifix@163.com> | 2021-10-29 15:02:46 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-29 15:02:46 +0800 |
commit | 796b4b05ec62eb5d58a634854998f485072e8a2b (patch) | |
tree | 30f188382f14b3b9c69fe5846262a39a8b4664cc /Data/Scripts/Editor/AssetBrowser.lua | |
parent | 91c32cb173201ac8803a1e4452e8342969b8e484 (diff) |
*passing texture to glsl
Diffstat (limited to 'Data/Scripts/Editor/AssetBrowser.lua')
-rw-r--r-- | Data/Scripts/Editor/AssetBrowser.lua | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/Data/Scripts/Editor/AssetBrowser.lua b/Data/Scripts/Editor/AssetBrowser.lua index b936702..34337b1 100644 --- a/Data/Scripts/Editor/AssetBrowser.lua +++ b/Data/Scripts/Editor/AssetBrowser.lua @@ -2,6 +2,7 @@ local Debug = GameLab.Debug local AssetBrowser = GameLab.Editor.GUI.EditorWindow.Extend("GameLab.Editor.AssetBrowser")
local GL = GameLab.Engine.GL
local Matrix44 = GameLab.Engine.Math.Matrix44
+local Engine = GameLab.Engine
local inspect = require("inspect")
AssetBrowser.Ctor = function(self)
@@ -21,37 +22,49 @@ layout (location = 1) in vec2 vUV; uniform mat4 mvp;
+out vec2 uv;
+
void main()
{
vec4 clip = mvp * vec4(vPos, -1, 1.0);
gl_Position = clip;
+ uv = vUV;
}
VSH_END
FSH_BEGIN
+uniform sampler2D uiTex;
+
+in vec2 uv;
out vec4 FragColor;
void main()
{
- FragColor = vec4(1,1,1,1);
+ FragColor = texture(uiTex, uv);
}
FSH_END
]]
+local tex
+
AssetBrowser.OnGUI = function(self)
+ if tex == nil then
+ tex = Engine.Resource.LoadTexture("./Resources/Images/brickwall.jpg")
+ end
+
if shader == nil then
- shader = GameLab.Engine.Rendering.Shader.New(glsl)
+ shader = Engine.Rendering.Shader.New(glsl)
end
local ortho = Matrix44.New()
ortho:SetOrtho(-200, 200, -200, 200, 0.1, 10)
Debug.Log("AssetBrowser.OnGUI()")
- GL.ClearColor({0,0,0,1})
+ GL.ClearColor({0.1,0.1,0.1,1})
GL.Clear(GL.EBufferType.ColorBuffer)
-- GL.Color({1,1,0,1})
-- GL.LoadPixelMatrix(-250, 250, -300, 300)
@@ -61,10 +74,11 @@ AssetBrowser.OnGUI = function(self) -- GL.Vertex({250,0,-1})
-- GL.End()
- shader:Use()
- shader:SetMatrix44("mvp", ortho)
- GameLab.Engine.Rendering.DrawUIQuad({0, 0, 100, 100})
-
+ Engine.Rendering.UseShader(shader)
+ Engine.Rendering.SetMatrix44(shader, "mvp", ortho)
+ Engine.Rendering.SetTexture(shader, "tex", tex)
+ Engine.Rendering.DrawUIQuad({0, 0, 100, 100})
+ Engine.Rendering.ResetUniformState()
end
AssetBrowser.OnFocus = function(self)
|