overloading ofBackgroud to accept an alpha component

Fellow OFers,

i want to overload the ofBackground function so as to allows the user to specify an alpha for the background.
the current ofBackground function in ofGraphics is as follows (i have omitted the .h code being that it’s straightforward):

void ofBackground(int r, int g, int b){  
	bgColor[0] = (float)r / (float)255.0f;  
	bgColor[1] = (float)g / (float)255.0f;  
	bgColor[2] = (float)b / (float)255.0f;  
	bgColor[3] = 1.0f;  
	if (ofbClearBg() == false){  
		glClearColor(bgColor[0],bgColor[1],bgColor[2], bgColor[3]);  

i (naively) assumed that the following will do it;

void ofBackground(int r, int g, int b, int a){  
	bgColor[0] = (float)r / (float)255.0f;  
	bgColor[1] = (float)g / (float)255.0f;  
	bgColor[2] = (float)b / (float)255.0f;  
	bgColor[3] = (float)a / (float)255.0f;  
	if (ofbClearBg() == false){  
		glClearColor(bgColor[0],bgColor[1],bgColor[2], bgColor[3]);  

but when i make a call like ofBackground(r,g,b,a), it complains that there are too many arguments

Any thoughts?

I’m about to try opening the openFrameworksLib project file, make the changes in there, compile that and then try it. (i actually thought of that just now, before i has directly opening the ofGraphics.h and .cpp files and just saving them but i can imagine that this doesn’t effect the core compiled library until adjusted it in the actual project file.)

Am i missing anything though? i have not been able to to see anything in ofGraphics which will be effected by this change but could there be anything in other areas of the library?

of course instead of messing with the core library, i could just manually draw the background with something like (which i resorted to)

ofSetColor(bgRGB[0], bgRGB[1], bgRGB[2], bgRGB[3]);  
      ofVertex(0, 0);  
      ofVertex(0, ofGetWidth());  
      ofVertex(ofGetWidth(), ofGetHeight());  
      ofVertex(ofGetHeight(), 0);  


Fellow OFers,

i tried changing it in the openFrameworksLib file but it is still complaining.
my application code (the one making the call ofBackground(r,g,b,a)) fully compiles/rebuilds but the following error is thrown by the object file:

obj\release\src\mainScene.o:mainScene.cpp|| undefined reference to `ofBackground(int, int, int, int)’

not clear on what the issue is. the function prototype is good in the .h file.

again any thoughts are appreciated!


Fellow OFers,

Really, any comments about augmenting the of library is appreciated. Is it a breach of the license? Or…blah blah blah. Again, anything will be helpful. Thanks

you must be missing the implementation of the function in the cpp or have not compiled the OF library before compiling your project or something like that. anyway this is already added in 007


did you mange to get the app transparent?
I tried the same as you did with
ofBackground(r, g, b, a)
and also changed:

void ofSetupGraphicDefaults(){


here-> ofBackground(200, 200, 200, 100);
ofSetColor(255, 255, 255, 255);


it compiles fine, but unfortunately - no result ! :frowning:



ohh I’ve overseen that this is possible with OF 007 …
let’s go.

Got the lastest version from git, but it doesn’t work for me.

Is there anything else to setup before?

ofBackground(255, 0, 0, 20); -> this is just RED, no alpha used :frowning:


the normal render buffer for the window doesn’t have an alpha component so it’s not going to work. this is meant to be used with fbos

To expand on that a little bit: what would setting the background alpha do? It’s the background, so there’s nothing behind it. The reason this works with an FBO is b/c the FBO can be drawn with something behind it, like an image, another FBO, or a background. Can you explain a little bit what you’re trying to accomplish by setting the background alpha?

Hi joshau,

first of all, I’m a big fan of your book “programming interactivity”! Thanks for writing that!

Back to the topic:
I’m working on a project where there will be projections on a dancers-body on stage. Therefor I track the dancer with a kinect-camera and opencv. And build a mask.
There is an other guy who will do the live-graphics in “whatever” programm, i don’t know…
So I want to make a OF-mask-application, that runs in front of the other app, and just lets the part come thru were the dancer is recognized.

I might be wrong, but I’m pretty sure the only way to do this is to make OS-native windows and not use the GLUT openGL context that oF normally uses. You can do it on all OS’s but you’d need to look it up depending on your OS-version, hardware, etc. For instance, OSX, doing it in Cocoa is quite easy and there’s a cocoa adddon here: http://forum.openframeworks.cc/t/new-ofxcocoa-was-ofxmacosx/4872/0 that would let you create OSX-native windows.

If you are on OSX and “whatever” graphic program supports Syphon, that would be an easy way to pipe the graphics data to your project. Otherwise, if that app supports FreeFrame, there are FreeFrame plugins that stream graphics between apps (with more overhead).


Have you checked?


Also for syphon, you can check this out:


Hi guys,

super-cool, thanks for that many helpful replies! Spyon seems to be a good choice to try out.
I’ve used that ofxTransparentWindow addon, which is fantastic, but not easy to handle. You can choose wether your app is a normal app, than you have the menu bar above, or do it on screensaver level, which is above everything, but than you can’t switch to the software underneath. An another problem is, that key-commands doesn’t work with it.

I think ofxTransparentWindow is based on a Cocoa hack, but I will check using ofxCocoa as well!