Skip to content

Commit c5cd04f

Browse files
committed
feat: add shaders example to test/game
1 parent bfafe88 commit c5cd04f

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

tests/game/main.lua

+32-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
1-
function love.load()
2-
Number = 0
3-
end
1+
-- Create triangle mesh
2+
local attributes = {
3+
{ "VertexPosition", "float", 2 },
4+
{ "VertexColor", "byte", 4 },
5+
}
6+
local vertices = {
7+
{ -0.5, -0.5, 1, 0, 0 },
8+
{ 0.5, -0.5, 0, 1, 0 },
9+
{ 0, 0.5, 0, 0, 1 },
10+
}
11+
local triangle = love.graphics.newMesh(attributes, vertices, "triangles", "static")
412

5-
function love.update()
6-
Number = Number + 1
7-
end
13+
-- If you have install glsl parser with TreeSitter, the multi-line string will be
14+
-- highlighted like the rest of the code.
15+
-- See `:help love2d-glsl`
16+
local shader = love.graphics.newShader(
17+
[[
18+
varying vec4 vColor;
19+
vec4 position( mat4 transform_projection, vec4 vertex_position ) {
20+
vColor = VertexColor;
21+
return transform_projection * vertex_position;
22+
}
23+
]],
24+
[[
25+
varying vec4 vColor;
26+
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
27+
return vColor;
28+
}
29+
]]
30+
)
831

932
function love.draw()
10-
love.graphics.print(tostring(Number))
33+
love.graphics.setShader(shader)
34+
love.graphics.draw(triangle, love.graphics.getWidth() / 2, love.graphics.getHeight() / 2, 0, 200, 200)
35+
love.graphics.setShader()
1136
end

0 commit comments

Comments
 (0)