Negative color
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Negative color
How can i color a text (created with love.graphics.print) with the negative of the backgruond?
Re: Negative color
Like this
Code: Select all
r, g, b, a = love.graphics.getBackgroundColor( )
love.graphics.setColor( 255-r, 255-g, 255-b)
Re: Negative color
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)
Re: Negative color
You could maybe achieve something like this using two images for example. One for the background and one for the text or whatever.
ImageData has https://love2d.org/wiki/ImageData:setPixel and https://love2d.org/wiki/ImageData:getPixel
If you keep the starting position of both images (top left corner for example) you could read/write colors for the pixels you want to change (overlapping).
Just read the color on the bottom image and set the color on the top one to the inverse.
This wouldn't be good for performance I guess but it should work.
ImageData has https://love2d.org/wiki/ImageData:setPixel and https://love2d.org/wiki/ImageData:getPixel
If you keep the starting position of both images (top left corner for example) you could read/write colors for the pixels you want to change (overlapping).
Just read the color on the bottom image and set the color on the top one to the inverse.
This wouldn't be good for performance I guess but it should work.
Re: Negative color
Maybe something like this helps?
Edit: Hm, maybe not.
A shader and a canvas is probably the way to go. Stay tuned.
Edit2: Here we go:
Code: Select all
love.graphics.setBlendMode('subtractive')
A shader and a canvas is probably the way to go. Stay tuned.
Edit2: Here we go:
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
Who is online
Users browsing this forum: Amazon [Bot] and 2 guests