summaryrefslogtreecommitdiff
path: root/Data/Scripts/Editor/AssetBrowser.lua
blob: 2617fbce897dacb6e4f74c96ea70cc3441876b3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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)
	self.base.Ctor(self, "AssetBrowser")
end

local shader = nil

local glsl = [[

#version 330 core

VSH_BEGIN

layout (location = 0) in vec2 vPos;
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 = 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 = Engine.Rendering.Shader.New(glsl)
	end 

	local ortho = Matrix44.New() 
    ortho:SetOrtho(0, 400, 400, 0, 0.1, 10)

	Debug.Log("AssetBrowser.OnGUI()")
	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)
	-- GL.Begin(GL.EPrimitiveType.Triangles)
	-- GL.Vertex({0,0,-1})
	-- GL.Vertex({0,300,-1})
	-- GL.Vertex({250,0,-1})
	-- GL.End()

	Engine.Rendering.UseShader(shader)
	Engine.Rendering.SetMatrix44("mvp", ortho)
	Engine.Rendering.SetTexture("tex", tex)
	Engine.Rendering.DrawUIQuad({10, 30, 100, 100})
	Engine.Rendering.ResetUniformState()
end

AssetBrowser.OnFocus = function(self)

end

return AssetBrowser