love.graphics.print( coloredText ) question

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Silver Ankh
Prole
Posts: 11
Joined: Tue Dec 19, 2017 10:29 am

love.graphics.print( coloredText ) question

Post 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?
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: love.graphics.print( coloredText ) question

Post 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.
Silver Ankh
Prole
Posts: 11
Joined: Tue Dec 19, 2017 10:29 am

Re: love.graphics.print( coloredText ) question

Post by Silver Ankh »

I expected coloredText option for print do the same as setColor (for the moment). Now I understand is not. Thank you!
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: love.graphics.print( coloredText ) question

Post 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)
Silver Ankh
Prole
Posts: 11
Joined: Tue Dec 19, 2017 10:29 am

Re: love.graphics.print( coloredText ) question

Post 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.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: love.graphics.print( coloredText ) question

Post 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)
Silver Ankh
Prole
Posts: 11
Joined: Tue Dec 19, 2017 10:29 am

Re: love.graphics.print( coloredText ) question

Post 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).
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: love.graphics.print( coloredText ) question

Post 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.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests