Skip to content

Instantly share code, notes, and snippets.

@eevee
Created January 21, 2018 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eevee/4ff11dd51116d32102c5a0fa287918cf to your computer and use it in GitHub Desktop.
Save eevee/4ff11dd51116d32102c5a0fa287918cf to your computer and use it in GitHub Desktop.
non-working LÖVE app with a rotating quad that never draws
local checkerboard
local shader
function love.load()
love.graphics.setDefaultFilter('nearest', 'nearest')
local imagedata = love.image.newImageData(8, 8)
imagedata:mapPixel(function(x, y, r, g, b, a)
if (x + y) % 2 == 1 then
return 192, 192, 192, 255
else
return 64, 64, 64, 255
end
end)
checkerboard = love.graphics.newImage(imagedata)
shader = love.graphics.newShader([[
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
{
vec4 texcolor = Texel(texture, texture_coords);
return texcolor * color;
}
]], [[
extern float theta;
vec4 position( mat4 transform_projection, vec4 vertex_position )
{
float l = -1024.0;
float r = 1024.0;
float t = 1024.0;
float b = -1024.0;
float n = 1024.0;
float f = -1024.0;
mat4 persp = mat4(
2 * n / (r - l), 0, 0, 0,
0, 2 * n / (t - b), 0, 0,
(r + l) / (r - l), (t + b) / (t - b), (n + f) / (n - f), -1,
0, 0, 2 * f * n / (n - f), 0);
float c = cos(theta);
float s = sin(theta);
mat4 rot = mat4(
c, 0, -s, 0,
0, 1, 0, 0,
s, 0, c, 0,
0, 0, 0, 1);
return transform_projection * persp * rot * vertex_position;
}
]])
end
local theta = 0
function love.update(dt)
theta = (theta + dt) % (math.pi * 2)
end
function love.draw()
local w, h = love.graphics.getDimensions()
local s = w / 2 * 0.9
shader:send('theta', theta)
love.graphics.setShader(shader)
love.graphics.draw(checkerboard, 0, 0, 0, math.min(w, h) / 8)
love.graphics.setShader()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment