glReadPixels and ppm

I am trying to write a ppm file after obtaining the pixel information of the image i am displaying.

How should I go about using glReadPixels?

What data type should the array be storing (i.e. the array the data is read into)?

How do I get the integer values out of the array to write the ppm?

Thanks for any help!

PPM has an interleaved format with RGB decimal, but runs top to bottom. It’s actually an ASCII format.

The simplest approach is probably just to read GL_RGB packed unsigned bytes and loop through with a byte pointer writing out the rgb in byte order with newlines are appropriate places. You’ll have to start at the last OpenGL line and work forward since OpenGL will read bottom to top first, but both are left to right at least.