Drawing images unaffected by setColor

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.
User avatar
Dr. Magnusson
Prole
Posts: 22
Joined: Sun Jul 20, 2008 6:10 pm

Drawing images unaffected by setColor

Post by Dr. Magnusson »

I really can't figure out why love.graphics.setColor doesn't have any effect on the images I draw.

Is it not supposed to do this?
Is something wrong with the image?

I guess I could live without this, but it'd be greatly appreciated if it could be added, if it isn't already that is.
User avatar
Nexion
Prole
Posts: 46
Joined: Fri Sep 05, 2008 1:40 pm

Re: Drawing images unaffected by setColor

Post by Nexion »

Is your image an actual IMAGE object or is it one of the love.graphics.draw/circle/polygon objects?
I wouldnt think that the setColor function would affect imported bmps or anything like that
User avatar
Dr. Magnusson
Prole
Posts: 22
Joined: Sun Jul 20, 2008 6:10 pm

Re: Drawing images unaffected by setColor

Post by Dr. Magnusson »

It is an imported png. I use it for corners so I guess I could use scissor'd circles for the corners then.

Thanks
User avatar
Lord Tim
Prole
Posts: 30
Joined: Sun Jul 20, 2008 4:07 am

Re: Drawing images unaffected by setColor

Post by Lord Tim »

I'm pretty sure this does work. Have you tried using love.graphics.setColorMode( love.color_modulate )? Use "love.color_normal" to set it back to normal.

http://love2d.org/docs/love_graphics_se ... ode_1.html
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Drawing images unaffected by setColor

Post by rude »

We chose not to color the images by default.

As usual, I'm sure some will like it that way, and some won't. It is subject to debate though, as "everything is affected by setColor" is easier to remember than "some thing are affected, and other things aren't".

Yup, I'll add this to the ever-growing "API Review" list.
User avatar
Dr. Magnusson
Prole
Posts: 22
Joined: Sun Jul 20, 2008 6:10 pm

Re: Drawing images unaffected by setColor

Post by Dr. Magnusson »

Thank you rude.

I was originally planning on using the image in question for drawing rounded corners on a box. Since the idea was that these boxes should be able to have any color, it really wouldn't be very effecient if you had to make a different image for each shade (16581375 combinations, excluding alpha).

This time we were able to find a way around it using the scissoring method, but I doubt all uses for colored images have such easy and resource-cheap solutions.
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: Drawing images unaffected by setColor

Post by Mr. Strange »

color_modulate is very handy. I've wanted to do similar things myself, and didn't realize how easy they already were to do.

I think the documentation for love.setColor should be expanded upon, to explain with a couple sentences exactly what it does. For example:

"getColorMode returns an int. 0 indicates love.color_normal, 1 indicatens love.color_modulate."
(Are there more than just color_modulate and color_normal?)

"setColor: This sets the color to be used when drawing text or shape primitives. Applying setColorMode can apply this default color to images as well."

Documentation is the least exciting, but possibly the most important part of a lovely project like this one.

--Mr. Strange
User avatar
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

Re: Drawing images unaffected by setColor

Post by Dr. Peeps »

Ancient thread, I know ... but I can't find a clear answer to this: is love.graphics.setColor() supposed to affect love.graphics.draw()? If so, how?

Code: Select all

love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(myimage)  -- this displays the normally colored image

love.graphics.setColor(0, 0, 0, 255)
love.graphics.draw(myimage)  -- this displays image as a black rectangle

love.graphics.setColor(0, 255, 255, 255)
love.graphics.draw(myimage)  -- this displays image colored as cyan (no red channel present)

love.graphics.setColor(1, 255, 255, 255)
love.graphics.draw(myimage)  -- unexpectedly, this also displays the full normally colored image
It appears that each channel is counted as either zero or not zero, i.e. anything from 1 - 255 is counted as 255. Is this the expected behaviour?
MrFariator
Party member
Posts: 512
Joined: Wed Oct 05, 2016 11:53 am

Re: Drawing images unaffected by setColor

Post by MrFariator »

Yes, love.graphics.setColor() should affect how drawables (images, quads, meshes, etc) should be drawn, and you pass it values between [0,255] (works as expected for me in 0.10.2). However, I read that 0.11 version of love will use values between [0,1] (link).

Hard to say what is going on with your code, so can you provide an example .love file that shows the behavior you're encountering?
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Drawing images unaffected by setColor

Post by s-ol »

Dr. Peeps wrote: Wed Mar 08, 2017 8:53 pm Ancient thread, I know ... but I can't find a clear answer to this: is love.graphics.setColor() supposed to affect love.graphics.draw()? If so, how?

Code: Select all

love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(myimage)  -- this displays the normally colored image

love.graphics.setColor(0, 0, 0, 255)
love.graphics.draw(myimage)  -- this displays image as a black rectangle

love.graphics.setColor(0, 255, 255, 255)
love.graphics.draw(myimage)  -- this displays image colored as cyan (no red channel present)

love.graphics.setColor(1, 255, 255, 255)
love.graphics.draw(myimage)  -- unexpectedly, this also displays the full normally colored image
It appears that each channel is counted as either zero or not zero, i.e. anything from 1 - 255 is counted as 255. Is this the expected behaviour?
are you using the unreleased 0.11.0? Color ranges are 0-1 there. Since it clamps above the range, it looks the same at 1 and 255.

https://love2d.org/wiki/0.11.0#Other_changes

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: No registered users and 207 guests