如果我直接在屏幕上渲染场景,渲染是不同的,如果我在FBO(帧缓冲区对象)上渲染,我怀疑添加混合模式在后面的情况下不起作用:
这是直接在屏幕上显示的结果:
以下是帧缓冲区的结果:
如您所见,在帧缓冲区中,蓝色不会总和变亮。
要在屏幕上绘图,我只需调用绘制粒子函数:
drawParticles();
对于FBO(来自openframeworks的ofFbo):
ofClear(0, 0, 0, 0);
fbo.begin();
drawParticles();
fbo.end();
fbo.draw(0,0);
----编辑----
这就是fbo的初始化方式:
fbo.allocate(ofGetScreenWidth(), ofGetScreenHeight(), GL_RGBA32F_ARB);
这是我的整个代码,在屏幕上绘制我使用这个版本,并在fbo上绘制我取消注释评论:
// ofClear(0, 0, 0, 0);
// bodyFBO.begin();
if(persistence>0)
{
ofSetColor(0,0,0,255*(1.0-persistence));
ofFill();
ofRect(0, 0, ofGetScreenWidth(), ofGetScreenHeight());
}
else
ofBackground(0, 0, 0);
effects[effect]->draw();
// bodyFBO.end();
ofEnableAlphaBlending();
// bodyFBO.draw(0,0);
这是实际绘图,效果[效果] - > draw():
ofSetColor(color);
ofEnableBlendMode(OF_BLENDMODE_ADD);
ofEnablePointSprites();
ofTexture &texture = textureIndex>0?texture2:texture1;
texture.bind();
vbo.draw(GL_POINTS, 0, (int)points.size());
texture.unbind();
ofDisablePointSprites();
----编辑2 ----
显示相同问题的另一段代码(来自openframeworks论坛的mikewesthad):
void testApp::setup(){
ofSetFrameRate(60);
ofSetBackgroundAuto(false);
ofBackground(0);
fbo.allocate(ofGetWidth()/2, ofGetHeight(), GL_RGBA32F);
fbo.begin();
ofBackground(0);
fbo.end();
}
void testApp::draw(){
// Draw directly to screen
drawCircle();
// Draw to fbo
fbo.begin();
drawCircle();
fbo.end();
ofDisableBlendMode();
fbo.draw(ofGetWidth()/2, 0);
}
void testApp::drawCircle() {
ofEnableAlphaBlending();
ofSetColor(0, 0, 0, 2);
ofFill();
ofRect(0, 0, ofGetScreenWidth(), ofGetScreenHeight());
ofSetColor(50, 50, 255, 255);
ofEnableBlendMode(OF_BLENDMODE_ADD);
ofCircle(ofRandomWidth()/2, ofRandomHeight(), 50);
----回答----
在绘制FBO之前缺少ofSetColor(255,255,255);
。
要在屏幕和FBO上使用完全相同的东西,我还需要使用GL_RGB(使用openframeworks中的默认参数)分配我的FBO:
fbo.allocate(ofGetWidth()/2, ofGetHeight(), GL_RGB);