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]);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
}
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]);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
}
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]);
ofFill();
ofSetPolyMode(OF_POLY_WINDING_ODD);
ofBeginShape();
ofVertex(0, 0);
ofVertex(0, ofGetWidth());
ofVertex(ofGetWidth(), ofGetHeight());
ofVertex(ofGetHeight(), 0);
ofEndShape();
–
Best