Hi, I posted this on another very old thread (here) but have deleted that and moved it here as it did not bump to the top of the forum.
Hi, I used code from arturo’s example here as a base to store frames in a vector of ofPixels and then retrieve them for instant playback. The storing works fine but when I retrieve the pixels I cannot load the pixels into a texture, but I can use them with the ofSaveImage() function from the same place in the code. I am guessing it is something to do with the pixel format, but when I call get pixel format I get RGB back.
Here is the code to pass the pixels to the thread (it is the same as the code above in this thread.
if(record){
if(!firstFrame){
// wait for the thread to finish saving the
// previous frame and then unmap it
saverThread.waitReady();
pixelBufferBack.unmap();
}
firstFrame = false;
// copy the fbo texture to a buffer
fbo.getTexture().copyTo(pixelBufferBack);
// bind and map the buffer as PIXEL_UNPACK so it can be
// accessed from a different thread from the cpu
// and send the memory address to the saver thread
pixelBufferFront.bind(GL_PIXEL_UNPACK_BUFFER);
unsigned char * p = pixelBufferFront.map<unsigned char>(GL_READ_ONLY);
saverThread.save(p);
// swap the front and back buffer so we are always
// copying the texture to one buffer and reading
// back from another to avoid stalls
swap(pixelBufferBack,pixelBufferFront);
}
Here is the code of the imageSaver Class .cpp threaded function
void ImageSaverThread::threadedFunction(){
// wait to receive some pixels,
// save them as jpeg and then tell the main
// thread that we are done
// if the channel closes go out of the thread
unsigned char * p;
while(channel.receive(p)){
pixels.setFromExternalPixels(p,960,540,OF_PIXELS_RGB);
lock();
frames.push_back(pixels);
ofLogVerbose()<<"Frame number " + ofToString(frames.size()) + " added"<<endl;
unlock();
channelReady.send(true);
}
}`
Here is the code of the playback function
if(play) {
//this works
ofSaveImage(saverThread.frames[frameCounter], ofGetTimestampString() + ".jpg");
//this does not throw any errors
drawTexture.loadData(saverThread.frames[frameCounter], width, height, GL_RGB);
ofLogVerbose()<<"Frame number " + ofToString(frameCounter) + " played of " + ofToString(saverThread.frames.size())<<endl;
//This shows a white screen
drawTexture.draw(0,0);
frameCounter++;
if (frameCounter>50-1) {
frameCounter=0;
}
}
Is there something I need to do to the ofPixels object when I get it from the vector and load the data to the texture to make it draw properly?
I am on an updated master branch of OF.
Cheers
Fred