generated from S1M0N38/base.nvim
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add shaders example to test/game
- Loading branch information
Showing
1 changed file
with
32 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |