   Problem storing screenshots with glReadPixels
  I am trying to save screenshots in tga files using the function below, but the images in the tga files don't come out properly. The rows of pixels seem to be misaligned, some too far to the left, some too far to the right. Maybe this is some kind of packing issue. Note, however, that I am setting GL_PACK_ALIGNMENT to 1. Any help would be much appreciated. Thanks in advance.void SaveTGA(unsigned int nShot){    char cFileName[64];    FILE *fScreenshot;    int nSize = m_WindowWidth * m_WindowHeight * 3;unsigned char *pixels = new unsigned char [nSize];    if (pixels == NULL) return;    sprintf(cFileName,"screenshot_%.3d.tga",nShot);    fScreenshot = fopen(cFileName,"wb");    glPixelStorei(GL_PACK_ALIGNMENT,1);glPixelStorei(GL_PACK_IMAGE_HEIGHT, 640);    glPixelStorei(GL_PACK_ROW_LENGTH, 640);    glReadPixels(0, 0, m_WindowWidth, m_WindowHeight, GL_BGR,GL_UNSIGNED_BYTE, pixels);unsigned char TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};    unsigned char header[6] = {m_WindowWidth%256,m_WindowWidth/256, m_WindowHeight%256,m_WindowHeight/256,24,0};fwrite(TGAheader, sizeof(unsigned char), 12, fScreenshot);    fwrite(header, sizeof(unsigned char), 6, fScreenshot);    fwrite(pixels, sizeof(unsigned char), nSize, fScreenshot);    fclose(fScreenshot);delete [] pixels;   return;}[Edited by - vitaediscimus on June 7, 2010 1:10:14 AM]