Hi guys,
i have two problems:
At first i need to load 2 images in ppm-file-format. Unfortunately there is a problem in my code and i dont know whats going wrong:
void loadGraphic(const std::string filename, GLubyte image[256][256][3])
{
std::ifstream fin(filename.c_str(), std::ios::binary);
if (fin.fail())
{
std::cerr << "Error: Could not open '" << filename << "' for reading." << std::endl;
return;
}
std::string magic;
std::string comment;
long width = 0;
long height = 0;
long pixel_max = 0;
fin >> magic >> comment >> width >> height >> pixel_max;
std::cout << magic << " " << width << " " << height << " " << pixel_max << std::endl;
// check the header
if (magic == "P6" && width > 0 && height > 0 && pixel_max > 0 && pixel_max < 256)
{
GLubyte value[3];
for(unsigned int y = 0; y < height; y++)
{
for(unsigned int x = 0; x < width; x++)
{
fin >> value[0] >> value[1] >> value[2];
image[x][y][0] = value[0];
image[x][y][1] = value[1];
image[x][y][2] = value[2];
if(x < 10 && y == 0)
std::cout << "(" << int(value[0]) << "," << int(value[1]) << "," << int(value[2]) << ")" << std::endl;
}
}
}
else
{
std::cerr << "Error: Bad file header" << std::endl;
}
fin.close();
}
As you can see the image data is saved in a array, the header is read successfully. But the image data isn’t read as it should be…
And the second task is to use a stencil buffer, to draw the first image whereever there is a 0 in the stencil buffer and to draw the second when there is a 1 in the stencil buffer. And with the left/right mouse button you should change the stencil buffer for the current x/y position, so that you can select some pixels where the other image should appear.
I have no idea how to do that… I need this by tomorrow, and i tried it the whole week, but nothing works. Can somebody help me?
Felix