@andrei_j wrote:
hello, I am trying to put together a framebuffer delay and I seem to be messing something up in my code.
`
int framecount=0;
int maxFrames=120;
const int fbob=6;
ofFbo pastFrames[fbob];
//int pastInts[fbob];
bool swictch=false;
//--------------------------------------------------------------
void ofApp::setup(){
ofBackground(0);//load the shader txt files shader_fbdelay.load("shadersGL2/shader_fbdelay"); shader_mix.load("shadersGL2/shader_mix"); //allocate and clear framebuffer1 framebuffer1.allocate(ofGetScreenWidth(), ofGetScreenHeight()); framebuffer1.begin(); ofClear(0,0,0,255); framebuffer1.end(); tmp.allocate(ofGetScreenWidth(), ofGetScreenHeight()); tmp.begin(); ofClear(0,0,0,255); tmp.end(); //allocate and clear framebufferarray for(int i=0;i<fbob;i++){ pastFrames[i].allocate(ofGetScreenWidth(), ofGetScreenHeight()); pastFrames[i].begin(); ofClear(0,0,0,255); pastFrames[i].end(); //pastInts[i]=i; }//endifor for(int i=0;i<maxFrames;i++){ ofFbo f; f.allocate(ofGetScreenWidth(),ofGetScreenHeight()); framebuffervector.push_back(f); } //initialize the camera cam1.listDevices(); cam1.setVerbose(true); cam1.setDeviceID(1); cam1.initGrabber(640, 480);
}
//--------------------------------------------------------------
void ofApp::update(){cam1.update();
}
//--------------------------------------------------------------
void ofApp::draw(){// cam1.draw(0,0);
// ofSetColor(ofColor::white);
//ofDrawRectangle(0,0,20,20);//draw camera stuff to framebuffer1 framebuffer1.begin(); shader_mix.begin(); cam1.draw(0,0); shader_mix.setUniformTexture("cam1",cam1.getTexture(),1); ofVec2f camdim; camdim.set(cam1.getWidth(),cam1.getHeight()); ofVec2f windowdim; windowdim.set(ofGetWidth(),ofGetHeight()); shader_mix.setUniform2f("camdim",camdim); shader_mix.setUniform2f("windowdim",windowdim); // ofDrawRectangle(0,0,200,200); //shader_mix.end(); //ofSetColor(ofColor::white); //ofDrawRectangle(0,0,20,20); framebuffer1.end();
// framebuffer1.draw(0,0,800,600);
pastFrames[0].draw(800,0,800,600);/* if(framebuffervector.size()>1){ framebuffervector[framebuffervector.size()-1].draw(800,0,800,600); } */
// framebuffer1.draw(0,0);
/*
if(framecount>120){for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ int look=j+10*i; int x=j*ofGetWidth()/10; int y=i*ofGetWidth()/10; //pastFrames[2*look].draw(x,y,ofGetWidth()/10,ofGetHeight()/10); framebuffervector[(look)%framebuffervector.size()].draw(x,y,ofGetWidth()/10,ofGetHeight()/10); } } } */ framecount++;
// if(framecount%60==0){
for(int i=fbob-2;i>=0;i–){
// pastFrames[i+1]=pastFrames[i];
// pastInts[i+1]=pastInts[i];
pastFrames[i+1].begin();
pastFrames[i].draw(0,0);
pastFrames[i+1].end();}//endifor
// }
//pastInts[0]=framecount; if(framecount%60==0){ pastFrames[0].begin(); ofTranslate(ofGetWidth()/2.0,ofGetHeight()/2.0); //ofTranslate(dd,ff,0); //ofRotateYRad(ss); //ofTranslate(dd,ff,0); framebuffer1.draw(-ofGetWidth()/2.0,-ofGetHeight()/2.0); cout << "wft"<< framecount<< endl; pastFrames[0].end(); } /* for(int i=0;i<fbob-2;i++){ tmp=pastFrames[i+1]; pastFrames[i+1]=pastFrames[i]; pastFrames[i+2]=tmp; } */ //welp lets try a vector version
// if(framecount%30==0){
if(swictch==true){ framebuffervector.push_back(framebuffer1); if(framebuffervector.size()>maxFrames){framebuffervector.erase(framebuffervector.begin());}
// cout << “wft”<< framecount<< endl;
}//} /* for(int i=0;i<fbob;i++){ cout << "pastints["<< i << "]="<< pastInts[i]<< endl; } cout << "***************************************************"<< endl; */
}
`you can see i’ve tried a couple different ways, what is confusing me at this point is that while i’m strobing the feed into the framebufferdelay to only refresh every 60 frames it still plays live video when i draw to the screen. am i goofing something up and just like passing like copies of the same pointer to the framebuffer i’m drawing the camera input too? no matter what i’ve tried so far im not getting any delay more than like 1 frame off.
also sorry my formatting turned out all wonky this is the first time i’ve posted here or anywhere to ask for help with code and don’t exactly know the proper way to format that stuff in these environments
Posts: 1
Participants: 1