Question about ofSetColor

How does ofSetColor affect what I draw with ofImage.draw ? Is it just changing all the white/transparent pixels to the set color?

Does it affect the behavior of anything else outside ofGraphics?

I want to add info about it to the api wiki…


1 Like

Hey Thiago,
under your draw function you will call your ofImage.draw. If you want your image to be displayed in it’s original color, you need to use ofSetColor(255,255,255); above ofImage.draw. This means that anything that comes after ofImage.draw will also be drawn in white - since 255,255,255 stands for white. If you want other things after ofImage.draw to be drawn in red, for example, you would have to call ofSetColor(255,0,0) after drawing your ofImage.

Hope this helps,

Thanks Lucas.

But I still don’t quite understand what it does if I have ofSetColor set to something else before I call ofImage.draw. I originally thought it was turning all the white or transparent pixels into the set color, but now I think that it adds a tint to the whole image somehow.

This is what I want to know, so I can add info to the ofSetColor entry of the wiki.

And also if anything on other classes (say, some function in ofVideoPlayer) has this kind of dependency on ofSetColor as well.


Has anyone come up with an answer explaining how ofSetColor affects ofImage::draw()?

I’m writing a Mandelbrot fractal explorer as a way of learning OF, so far so good. However, I too am puzzled about how ofSetColor affects the rendering of ofImages. I currently have a greyscale fractal (not a greyscale ofImage though) if the current color is say, yellow, then the fractal is rendered in perfectly scaled yellow tint.

I’m evaluating OF for use in a programming class I am teaching next semester and I’d really like to understand this issue.

in the graphics card colors are treated as floats in the range of 0…1. when you use ofSetColor and then draw an image, each pixel color in the image is multiplied by the color you set before, so if you set for example red (255,0,0) in floats (1,0,0) and a pixel is 127,127,127 in floats (0.5,0.5,0.5) the result will be:

1*0.5,0*0.5,0*0.5 = 0.5,0,0

which translated to the 0…255 range will be 127,0,0. The result is your image is tinted with the color you set with ofSetColor

Thanks! So, just so I’m clear, a faithful rendering of the ofImage requires ofSetColor (255,255,255) or (1.0,1.0,1.0)?

yes that’s it

Have there been any changes in ofSetColor() and ofImage::draw() in OF 7?
I’ve just installed the latter and discovered that imageLoaderExample and dirListExample don’t show any images as they did in OF 6.2.
I guess something has to be fixed in these examples?

there hasn’t been a change that would make image dissapear – what compiler / OS are you using? Do the other examples that load media (font, etc) work? Do you still the same thing in debug and release?


Not shure if this is related, but in OF 6 it was possible to use ofSetColor with a single parameter, f.e. 0xFFFFFF.
This is no longer possible in OF 7, you have to use ofSetHexColor(0xFFFFFF) for that.

I don’t think it’s a matter of SetColor. DirListExample invokes it like this: ofSetColor(ofColor::white);
which looks correct to me.

I use Code::Blocks 10.05 under Windows 7.
Examples from OF 6.2 work fine.

I have not tried all the examples with ofImage. I have just tried blendingExample. Rectangles are displayed instead of images.

Addition: Windows XP SP3, the same problem.
movieGrabberExample doesn’t show image on screen, only a white rectangle.
Added a few lines to save a captured image to a file - the file contains a picture.

I am in trouble with this issue. It might be difficult to reproduce and thus impossible to fix.

I copied binaries to another computer (Windows 7 Professional) and everything works fine - all images are shown as they should. But they are not shown in both Windows development computers that I have. What might be different in environment? Which part of environment is required for OF007 to show images?

it seems it could be related with your graphics card, which model are you using?

I have Intel Graphics Media Accelerator 3150 in my laptop.

I’ve just found that this is a known issue:

Calling ofDisableArbTex(); solves the problem.

Thank you for the hint : )