From c5cd04fa1fc97c1eed50d8d58ce7d9e8295f6650 Mon Sep 17 00:00:00 2001 From: S1M0N38 Date: Mon, 13 May 2024 08:40:41 +0200 Subject: [PATCH] feat: add shaders example to test/game --- tests/game/main.lua | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/tests/game/main.lua b/tests/game/main.lua index aab3193..69bca29 100644 --- a/tests/game/main.lua +++ b/tests/game/main.lua @@ -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