alpha blending problem: iPhone FBOs (SOLVED)

Hi

I’m having a problem with fbos. I can’t seem to get an overlapping semi-transparent line effect (the more lines that overlap, the greater the opacity of the overlap area). It’s probably me as I know very little of OpenGL. If I run this code, I get the effect I’m looking for:

  
//#define USE_FBO  
  
void App::draw()  
{  
	int w = ofGetScreenWidth();  
	int h = ofGetScreenHeight();  
  
	ofBackground(255, 255, 255);  
	  
	ofEnableAlphaBlending();  
	ofSetColor(0, 0, 0, 255/4);  // a 4 line overlap should be pitch black  
	ofSetLineWidth(50);  
  
#ifndef USE_FBO  
	ofLine(0, 0, w, h);  
	ofLine(0, h, w, 0);  
	ofLine(0, h/2, w, h/2);  
	ofLine(w/2, 0, w/2, h);  
#else  
	fboP->begin();  
	ofLine(0, 0, w, h);  
	ofLine(0, h, w, 0);  
	ofLine(0, h/2, w, h/2);  
	ofLine(w/2, 0, w/2, h);  
	fboP->end();  
	fboP->draw(0, 0, screenWidth, screenHeight);  
#endif  
  
	ofDisableAlphaBlending();  
}  

If I uncomment #define USE_FBO, hence using FBOs (ofxFBOTexture, received from SiW via http://forum.openframeworks.cc/t/ofx-061-gt;-iphone-3.2:-need-fbos-solved/4372/0), the overlap area, after a few draw cycles, melds to match the non-overlapping areas. Not what I wanted.

Also, I think this could relate to post http://forum.openframeworks.cc/t/fbo-on-iphone/2909/0.

EDIT: Okay now I figured out why the lines meld after a few draw cycles. I forgot to clear the fbo – fboP->clear()–. But the results appear washed out when compared to the non-FBO segment.

Thanks
Alex

Solved by calling glBlendFunc with the right parameters:

  
void App::draw()  
{  
	ofSetColor(255, 255, 255);  
	glEnable(GL_BLEND);  
	glBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR);  
	fboP->draw(0, 0, screenWidth, screenHeight);  
	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);  
	glDisable(GL_BLEND);  
}  
  

Alex