Unable to properly load PPM texture data
-
I'm trying to turn my PPM (lossless image file) into a texture, but the texture is not showing up correctly. I've tried loading a bitmap image as a texture using glaux and a call to auxDIBImageLoad(), however, I would simply like to implement my own parser for PPM. Basically, in PPM, the line after the getting the value for "int maxValue" is a long line of binary data that stores the 8-bit RGB (total 24 bits) going from left to right, top to bottom in the image. If we think about this in a 2D coordinate system, parsing the file would first get you (x, y) = (0, 0), then (1, 0), then (2, 0), until the end of the width, then (0, 1), and etc. Knowing this, does anyone know why my texture is being parsed incorrectly?
ifstream texFile("brickbump.ppm");
if (texFile.is_open())
{
//Load texture properties
char propBuf[8];
texFile.getline(propBuf, 8);
string format = propBuf;
texFile.getline(propBuf, 8);
int x = atoi(propBuf);
texFile.getline(propBuf, 8);
int y = atoi(propBuf);
texFile.getline(propBuf, 8);
int maxValue = atoi(propBuf);//Load texture data char\* texArray = new char\[3 \* x \* y\]; int count = 0; while (!texFile.eof()) { texFile.get(texArray\[count\]); count++; } //Generate textures glGenTextures(1, &m\_textures\[0\]); glBindTexture(GL\_TEXTURE\_2D, m\_textures\[0\]); glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, x, y, 0, GL\_RGB, GL\_UNSIGNED\_BYTE, texArray); glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MIN\_FILTER, GL\_LINEAR); glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MAG\_FILTER, GL\_LINEAR); delete \[\] texArray;
}