I am working on a University Project that is to make a game like Bejewled. We are using OpenGL and CImg. The Project file has the following function in it:
void ReadImage(string imgname, vector<unsigned char> &imgArray)
{
using namespace cimg_library;
CImg<unsigned char> img(imgname.c_str());
imgArray.resize(img.height() * img.width() * 3, 0);
int k = 0;
unsigned char *rp = img.data();
unsigned char *gp = img.data() + img.height() * img.width();
unsigned char *bp = gp + img.height() * img.width();
for (int j = 0; j < img.width(); ++j)
{
int t = j;
for (int i = 0; i < img.height(); ++i, t += img.width())
{
imgArray[k++] = rp[t];
imgArray[k++] = gp[t];
imgArray[k++] = bp[t];
}
//imgArray[i][j] = img[k++];
}
}
As far as I understand, and as the name implies, this function is supposed to read an Image. But I can't figure out how to use it and how can I read an Image. I would appreciate it if someone could guide me.
EDIT: This is how I'm calling the function:
vector<unsigned char> imgvec;
ReadImage("donut", imgvec);
which results in an error:
[CImg] *** CImgIOException *** [instance(0,0,0,0,00000000,non-shared)] CImg<unsigned char>::load(): Failed to open file 'donut'.