I have a code for SSAO at: https://github.com/sjhalayka/opengl4_stlview
I have a different code for shadow mapping and SSAO at the same time: https://github.com/sjhalayka/opengl4_stlview_shadow_map
Regarding the first code, included here is an image of what the 2nd colour attachment looks like. It's basically a normal + depth texture:
In the second code however, it's like the 2nd colour attachment is not being written to properly – it's like it's being overwritten with a duplicate of the values of the 1st colour attachment.
Any ideas why my 2nd colour attachment is not working?
The code for saving a colour attachment to disk is:
vector<unsigned char> output_pixels(2048*2048*4);
glReadBuffer(GL_COLOR_ATTACHMENT1);
glReadPixels(0, 0, 2048, 2048, GL_RGBA, GL_UNSIGNED_BYTE, &output_pixels[0]);
// Set up Targa TGA image data.
unsigned char idlength = 0;
unsigned char colourmaptype = 0;
unsigned char datatypecode = 2;
unsigned short int colourmaporigin = 0;
unsigned short int colourmaplength = 0;
unsigned char colourmapdepth = 0;
unsigned short int x_origin = 0;
unsigned short int y_origin = 0;
unsigned short int px = 2048;
unsigned short int py = 2048;
unsigned char bitsperpixel = 32;
unsigned char imagedescriptor = 0;
vector<char> idstring;
// Write Targa TGA file to disk.
ofstream out("attachment.tga", ios::binary);
if (!out.is_open())
{
cout << "Failed to open TGA file for writing: attachment.tga" << endl;
return;
}
out.write(reinterpret_cast<char*>(&idlength), 1);
out.write(reinterpret_cast<char*>(&colourmaptype), 1);
out.write(reinterpret_cast<char*>(&datatypecode), 1);
out.write(reinterpret_cast<char*>(&colourmaporigin), 2);
out.write(reinterpret_cast<char*>(&colourmaplength), 2);
out.write(reinterpret_cast<char*>(&colourmapdepth), 1);
out.write(reinterpret_cast<char*>(&x_origin), 2);
out.write(reinterpret_cast<char*>(&y_origin), 2);
out.write(reinterpret_cast<char*>(&px), 2);
out.write(reinterpret_cast<char*>(&py), 2);
out.write(reinterpret_cast<char*>(&bitsperpixel), 1);
out.write(reinterpret_cast<char*>(&imagedescriptor), 1);
out.write(reinterpret_cast<char*>(&output_pixels[0]), 2048*2048 * 4 * sizeof(unsigned char));
out.close();
exit(1);