I am trying to save OpenGL screen to file using glReadPixels. I found this code:
void saveScreenshotToFile(const char* filename, int WIDTH, int HEIGHT) {
int* buffer = new int[WIDTH * HEIGHT * 3];
glReadPixels(0, 0, WIDTH, HEIGHT, GL_BGR, GL_UNSIGNED_BYTE, buffer);
FILE* out = fopen(filename, "w");
short TGAhead[] = { 0, 2, 0, 0, 0, 0, WIDTH, HEIGHT, 24 };
fwrite(&TGAhead, sizeof(TGAhead), 1, out);
fwrite(buffer, 3 * WIDTH * HEIGHT, 1, out);
fclose(out);
}
after it I am just calling
saveScreenshotToFile("file.tga", 800, 600);
This is what I expect. But this is what I am getting. I am using 2 VAOs, one for objects and one for light.