Skip to content

Commit

Permalink
feat: add shaders example to test/game
Browse files Browse the repository at this point in the history
  • Loading branch information
S1M0N38 committed May 13, 2024
1 parent bfafe88 commit c5cd04f
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions tests/game/main.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
function love.load()
Number = 0
end
-- Create triangle mesh
local attributes = {
{ "VertexPosition", "float", 2 },
{ "VertexColor", "byte", 4 },
}
local vertices = {
{ -0.5, -0.5, 1, 0, 0 },
{ 0.5, -0.5, 0, 1, 0 },
{ 0, 0.5, 0, 0, 1 },
}
local triangle = love.graphics.newMesh(attributes, vertices, "triangles", "static")

function love.update()
Number = Number + 1
end
-- If you have install glsl parser with TreeSitter, the multi-line string will be
-- highlighted like the rest of the code.
-- See `:help love2d-glsl`
local shader = love.graphics.newShader(
[[
varying vec4 vColor;
vec4 position( mat4 transform_projection, vec4 vertex_position ) {
vColor = VertexColor;
return transform_projection * vertex_position;
}
]],
[[
varying vec4 vColor;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
return vColor;
}
]]
)

function love.draw()
love.graphics.print(tostring(Number))
love.graphics.setShader(shader)
love.graphics.draw(triangle, love.graphics.getWidth() / 2, love.graphics.getHeight() / 2, 0, 200, 200)
love.graphics.setShader()
end

0 comments on commit c5cd04f

Please sign in to comment.