Negative color
Posted: Fri Dec 04, 2015 10:17 am
How can i color a text (created with love.graphics.print) with the negative of the backgruond?
Code: Select all
r, g, b, a = love.graphics.getBackgroundColor( )
love.graphics.setColor( 255-r, 255-g, 255-b)
I wasn't mean this, for background i mean everything that is behind the number (it isn't just one color)Zeliarden wrote:Like thisCode: Select all
r, g, b, a = love.graphics.getBackgroundColor( ) love.graphics.setColor( 255-r, 255-g, 255-b)
Code: Select all
love.graphics.setBlendMode('subtractive')
Code: Select all
local img, canvas, shader
local lg = love.graphics
function love.load()
canvas = lg.newCanvas()
img = lg.newImage("image1.jpg")
lg.setFont(lg.newFont(80))
shader = lg.newShader
[[
extern Image bgimg;
vec4 effect(vec4 clr, Image img, vec2 imgpos, vec2 scrpos)
{
float alpha = Texel(img, imgpos).w * clr.w;
vec4 bgpixel = Texel(bgimg, vec2(scrpos.x / love_ScreenSize.x, 1. - scrpos.y/love_ScreenSize.y));
return vec4(vec3(1., 1., 1.) - bgpixel.xyz, alpha);
}
]]
end
function love.draw()
-- This represents drawing the background to the canvas
lg.setCanvas(canvas)
lg.draw(img)
lg.setCanvas()
-- Send the background to the shader
shader:send('bgimg', canvas)
-- Draw the background on the actual screen
lg.draw(canvas)
-- Apply the shader to the text
lg.setShader(shader)
lg.print("█*#%█", 450, 0)
lg.setShader()
end