Hi! I am trying to solve this for a better understaing of pointers, references and how ofPixels and ofVideoGrabbers manage their contents
Let’s say I have 3 different videoGrabbers, vidGrab0, vidGrab1 and vidGrab2.
vidGrab0.getPixels() returns a pointer to the array where the pixels are stored,
if I want to Access directly to the pixels, I have to use the reference:
That let me acces to any pixel in the pixels array. pixels is an array of ofPixels
I want to store those pointers in an array, that is -if I am right- a pointer to the first pixel of each videoGrabber.
It is my understanding that
// code 2)
ofPixels * pixelsArray // this is my array of pointers to ofPixels
pixelsArray = &videoGrab0.getPixels() // I store a reference to the pointer
Later, I will use an auxiliar ofPixel object to mess around with those pixels. And here is where the problem is.
How do I get an array, like in code 1) ?
I guess that the way to do it should be
ofPixels & pixels = pixelsArray; // since I stored a reference of the pointer in the array
But does simply doesn’t work. Can somebody throw some light? Should I approach this using an array of arrays? This isin instead of pixelsArray, use pixelsArray and store the pixels directly?
Thanks a lot!
First of all, thanks for answering these kind of C++ questions.
You are right, what I am storing has to be a pointer, since pixelsArray is define like an arrays of pointer. But if I am not wrong, that’s a pointer to a reference, right?
I am afraid there is something I am not understanding correctly. Using code 1) allows me to access pixels like in an array, pixles[i]
But if I use what you are suggesting, there is no way to use pixels->[i], correct?
I don’t want to take much of your time with this, I am afraid I am just trying to make things too complicated…
Edit: It worked the other way around:
ofPixels pixels = *pixelsArray;
Now, I can access to pixels[i]
Thanks for your help! - Now I have to figure out why it worked…