Something weird is happening to me on Monday morning.
My problem is, I have a class called “ImageResource” containing a vector of ofImages, and I want to pass one of those images to a shader in my ofApp.
This is the ImageResource class header.
#pragma once
#include "ofMain.h"
class ImageResources
{
public:
ImageResources();
void update();
void setup(); // this is just for test
ofImage getCurrentImageColor();
// Images
vector<ofImage> imageColors;
ofImage activeImg;
int textureIndex;
}
I have already tried to see if getCurrentImageColor() was not returni any image, but if I draw it to the screen using getCurrentImageColor().getTexture(0,0) it works.
This does not work, error: /OF/of_v20190324_linux64gcc6_release/apps/myApps/test/src/ImageResources.cpp:16: error: reference to type 'const ofImage' (aka 'const ofImage_<unsigned char>') could not bind to an rvalue of type '__gnu_cxx::__alloc_traits<std::allocator<ofImage_<unsigned char> > >::value_type *' (aka 'ofImage_<unsigned char> *')
Do you think it is something related to the fact that I am not passing the variable correctly?
/src/ImageResources.cpp:20: error: invalid initialization of non-const reference of type ‘ofImage& {aka ofImage_<unsigned char>&}’ from an rvalue of type ‘__gnu_cxx::__alloc_traits<std::allocator<ofImage_<unsigned char> > >::value_type* {aka ofImage_<unsigned char>*}’
return & imageColors.at(textureIndex);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I did some more test and basically what I see is that in order to have a vector of ofImages, from which you can pick a texture and set it as uniform for a shader, that vector has to be in ofApp.h.
If you put it in another class it is not working. @arturo do you have some hints about this behaviour? I can put all my images in the ofApp class, but it requires a bit of refactoring and I would like to avoid it.
I think you are right, I made a test app to try to replicate the issue and it is not happening, the textures are displayed as expected. How could I inadvertently destroy a texture?
I am using textures from a vector of images in a ping-pong fbo:
updateCol.setUniformTexture("posData", posPingPong.src->getTexture(), 1); // passing the position information
updateCol.setUniformTexture("colImage", testImages[1].getTexture(), 2); //broken, texture is not displayed
Probably by copying it somewhere else, in your first example you were copying the image which would be really slow but should work i think but something like that where you copy an image and destroy the original after having set the uniform in the shader could have that effect
Also try using something like renderdoc to see what’s going on in the shader