Page 1 of 1

love.graphics.print( coloredText ) question

Posted: Sat Jan 20, 2018 7:08 pm
by Silver Ankh
I have a program (v0.11):

Code: Select all

local green = {0, 1, 0, 1}
local blue = {0, 0, 1, 1}
local white = {1, 1, 1, 1}

function love.draw()
	love.graphics.setColor(green)
	-- something
	-- love.graphics.setColor(white)
	love.graphics.print({blue, "TEXT"}, 10, 10)
end
Text is not printed in blue unless color will be "reseting" to white. It's feature or bug?

Re: love.graphics.print( coloredText ) question

Posted: Sat Jan 20, 2018 7:45 pm
by erasio
SetColor is a filter applied to everything that's being drawn.

Since it moved to numbers between 0 and 1 in 0.11 you can imagine it like every color is multiplied by what's been set in setColor.

0 * 1 = 0. So no blue will be rendered.

Re: love.graphics.print( coloredText ) question

Posted: Sat Jan 20, 2018 8:40 pm
by Silver Ankh
I expected coloredText option for print do the same as setColor (for the moment). Now I understand is not. Thank you!

Re: love.graphics.print( coloredText ) question

Posted: Sun Jan 21, 2018 12:07 pm
by erasio
Well. It actually is doing exactly the same!

Both filter out color. Or rather remap it.

If you setColor of the blue component to 0.5. And then apply a textcolor of 0.5 you get one half of one half. Or 0.25 in short.

Since 0.11 you can really just think of all color functions as multiplying with one another.

1 * 0 = 0
1 * 0.5 = 0.5
0.5 * 0.5 = 0.25
etc

The default is white. So 1,1,1. You just start dividing that down. (Or in cases of images you have a wide range of color which gets divided down)

Re: love.graphics.print( coloredText ) question

Posted: Wed Jan 24, 2018 12:58 am
by Silver Ankh
erasio wrote: Sun Jan 21, 2018 12:07 pm Well. It actually is doing exactly the same!
Not exactly I think.

Code: Select all

love.graphics.setColor(green)
love.graphics.print({blue, "TEXT"}, 10, 10)
is not the same as:

Code: Select all

love.graphics.setColor(green)
love.graphics.setColor(blue)
love.graphics.print("TEXT", 10, 10)
This is what I mean.

Re: love.graphics.print( coloredText ) question

Posted: Thu Jan 25, 2018 7:22 pm
by erasio
Silver Ankh wrote: Wed Jan 24, 2018 12:58 am Not exactly I think.

Code: Select all

love.graphics.setColor(green)
love.graphics.print({blue, "TEXT"}, 10, 10)
is not the same as:

Code: Select all

love.graphics.setColor(green)
love.graphics.setColor(blue)
love.graphics.print("TEXT", 10, 10)
This is what I mean.
Because setColor() doesn't stack!

If you call it twice in a row, the first one is overwritten.

However. The following two have the same result:

Code: Select all

love.graphics.print({green, "TEXT"}, 10, 10)
And

Code: Select all

love.graphics.setColor(green)
love.graphics.print("TEXT", 10, 10)

Re: love.graphics.print( coloredText ) question

Posted: Thu Jan 25, 2018 8:27 pm
by Silver Ankh
I'm very pleased to write with you, but I think we do not understand each other because of my bad english.
Sorry, I'm trying hard ;)
erasio wrote: Thu Jan 25, 2018 7:22 pm However. The following two have the same result:

Code: Select all

love.graphics.print({green, "TEXT"}, 10, 10)
And

Code: Select all

love.graphics.setColor(green)
love.graphics.print("TEXT", 10, 10)
Hmmm... no? Is dependent what setColor was set before. If this will be in function which can be called from many places of the program, I'm not sure what setColor is currently set. So I need to use 2nd option.
That was my first question. I expected, that print({green, "Text"}) give me green text ALWAYS. Now I know how it works (maybe I can't write this out - sorry again).

Re: love.graphics.print( coloredText ) question

Posted: Thu Jan 25, 2018 8:44 pm
by Nixola
setColor works by modifying the color of everything you draw. lg.print({green, "TEXT"}) works by printing, with the current color, text that is already green; if the color is blue, it will not draw anything. It's like drawing a green image.