Cannot set mesh coordinates from fbo

Hi everybody!

I’m making an application where I need to set the texture coordinates of a ofPrimitivePlane. Everything works with the texture of a simple ofImage, but if I try to do the same thing with a fbo I get no values.

ofImage simpleImage;
ofFbo rgbaFBO;
ofImage fboImage;
ofPlanePrimitive plane;
ofPixels p;

simpleImage.load(myPath);
simpleImage.setImageType(OF_IMAGE_GRAYSCALE);

//allocate rgbaFBO

rgbaFBO.begin();

//draw something;

rgbaFBO.end();

rgbaFBO.readToPixels(p);
fboImage.setFromPixels(p);
fboImage.setImageType(OF_IMAGE_GRAYSCALE);


plane.set(width, height, numCols, numRows);

plane.mapTexCoordsFromTexture(fboImage.getTexture());
plane.mapTexCoordsFromTexture(simpleImage.getTexture());

fboImage has the same parameters of simpleImage (width, height, imageType, ecc…)
fboImage.getTexture().draw(0,0) works fine

What is wrong in this code?

Thanks!!!

Hi,
there’s no need to copy the pixels from the fbo to that ofImage.
just use rgbaFBO.getTexture();
Instead of doing the readToPixels operation which is quite slow, you can just have an ofTexture object and pass to it the texture from the fbo in case that you want to reuse the fbo and not loose the previous texture.

In any case, just to clear your doubts, what’s wrong with your code is that you are not updating fboImage. It should be like this

rgbaFBO.readToPixels(p);
fboImage.setFromPixels(p);
fboImage.setImageType(OF_IMAGE_GRAYSCALE);
fboImage.update();

cheers

Thanks Roy for your reply,

I was using rgbaFBO.getTexture(), but it didn’t work for me. So I used a new ofImage, because I didn’t have any problem on taking texture coordinates from this type of data. Now I added fboImage.update() but I still don’t see nothing. I don’t find examples, so I’m just tryng by myself

Well, I’ll try to make a very simple app that do the same thing and see if the problem persist. In case, I’ll post the code.

Paolo

not sure if you are doing so since it’s not shown in you example but in order to draw with a texture you have to bind it like:

tex.bind()
primitive.draw();
tex.unbind();

Really sorry, it’s my fault. There was a call to ofDisableArbTex(); in setup() that I had added some years ago … next time I’ll read ten times my code before posting an issue!!