hello !
An FBO seems to be able to carry multiple textures inside itself. What I would like is to use it as a container of different drawns on it. Is it possible?
So, What Im trying is {1} attach first internal fbo texture #1 {2} then draw inside with the same fbo,{3} update that attached texture {4} trying to recover them and Draw all them.
But that’s not working, is painting just the last drawn in the FBO in the first layer of that FBO…
Here some code references and uploaded the full code example. This example should draw a raw of 4 colored rects of 160x160 (red, green yellow and blue)
FBO_MultiTexturing_Example - forum.zip (16.3 KB)
windows8.1 and OF 0.9.1 and nvida card
//--------------------------------------------------------------
void ofApp::updateFbo(int attachmentPoint, ofColor mycolor) {
ofSetColor(100);
//Trying to Attach the Texture id from the FBO itself
myFbo.attachTexture(myFbo.getTexture(attachmentPoint), GL_RGB, attachmentPoint);
myFbo.begin();
//Drawing diferent Colors inside
ofSetColor(mycolor);
ofRect(0, 0, fboWidth, fboHeight);
ofSetColor(200);
ofCircle(mouseX, mouseY, 10, 10);
myFbo.end();
//update the painted texture
myFbo.updateTexture(attachmentPoint);
}
//--------------------------------------------------------------
void ofApp::drawFbo(int idTextureFbo, int x, int y) {
ofSetColor(255);
//Get Texture idTextureFbo from FBO
myFbo.getTexture(idTextureFbo).draw(x, y);
}
//--------------------------------------------------------------
void ofApp::update() {
//Paint all my Internal Texture FBO
int indextAttachedTexture = 1;
for (int i = 0; i < myColors.size(); i++) {
updateFbo(i + 1, myColors[i]); //If the textureId parameter is set to 0, then, the texture image will be detached from the FBO
}
}
//--------------------------------------------------------------
void ofApp::draw() {
ofColor(255, 0, 0);
ofNoFill();
ofRect(0, 0, fboWidth, fboHeight);
ofFill();
ofColor(255);
for (int i = 0; i < myColors.size(); i++) {
drawFbo(i, fboWidth*i + 10, fboHeight);
}
}
//--------------------------------------------------------------
void ofApp::setup() {
fboWidth = 160;
fboHeight = 160;
myFbo.allocate(fboWidth, fboHeight, GL_RGB);
myFbo.createAndAttachTexture(GL_RGB, 0);//http://www.songho.ca/opengl/gl_fbo.html
myFbo.createAndAttachTexture(GL_RGB, 1);//This allocates GL_COLOR_ATTACHMENT0+1
myFbo.createAndAttachTexture(GL_RGB, 2);
myFbo.createAndAttachTexture(GL_RGB, 3);
myFbo.createAndAttachTexture(GL_RGB, 4);
myColors.push_back(ofColor(255, 0, 0));//0 red
myColors.push_back(ofColor(0, 255, 0));//1 green
myColors.push_back(ofColor(255, 255, 0));//3 yellow
myColors.push_back(ofColor(0, 0, 255));//2 blue
}