summaryrefslogtreecommitdiff
path: root/demo/ScreenQuad.lua
blob: 73cce4653de0b8aa18fd0ae8f27ac054bf480009 (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
local ScreenQuad = {}

ScreenQuad.quad = honey.primitives.plane(2,2)

local vertexShader = [[
#version 330 core

layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec2 uv;

out vec2 UV;

void main() 
{
  gl_Position = vec4(position.xy, 0, 1) - vec4(1,1,0,0);
  UV = uv;
} ]]

local fragmentShader = [[
#version 330 core

in vec2 UV;

uniform sampler2D tex;

out vec4 color;

void main()
{
  color = vec4(texture(tex, UV).xyz, 1);
} ]]

ScreenQuad.shader = honey.shader(vertexShader, fragmentShader)

ScreenQuad.tex   = honey.texture.new()
ScreenQuad.depth = honey.texture.new()
ScreenQuad.tex:create('rgb', 640, 480)
ScreenQuad.depth:create('depth', 640, 480)
--honey.texture.load(ScreenQuad.texture, 'checkerboard.png', false)

ScreenQuad.fb = honey.texture.new_framebuffer(ScreenQuad.tex, ScreenQuad.depth, 640, 480)

ScreenQuad.draw = function(self)
   honey.texture.use(self.tex, 0)
   honey.mesh.draw(self.quad, self.shader)
end

return ScreenQuad