PDA

View Full Version : glReadPixels()



kschroed
10-10-2001, 03:33 AM
hi there.
i want to add a 'save as' feature to my nice GL-scene. but i don't get glReadPixels() run. i use a double buffered window and it is NOT overlapped. glReadPixels does not fill the pixels array and sometimes it results in an 'int 3' ....

// PixelStore and PixelTransfer are
// at defaults;
// r containes window size
unsigned char * pixels_rgba = (unsigned char *) malloc (r.right * r.bottom * 4);

glReadPixels(0, 0, 2, 2, GL_RED, GL_UNSIGNED_BYTE, &pixels_rgba);

free(pixels_rgba);

any hints??
thanks a lot

Kai

Gavin
10-10-2001, 04:29 AM
you are not reading many pixels out, also why are you reading GL_RED?

kschroed
10-10-2001, 04:42 AM
Originally posted by Gavin:
you are not reading many pixels out, also why are you reading GL_RED?

This is just a test and i reduced the area to 2x2 also to localize the prob. neither GL_RED nor GL_RGB ... worked.

Gavin
10-10-2001, 04:55 AM
try losing the ampersand.

Tron
10-10-2001, 05:36 AM
i use this code to make a screenshot and save it into a raw-file:




UByte* Data = new UByte[Width() * Height() * 3];
if (Data)
{
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels
(
0,
0,
Width(),
Height(),
GL_RGB,
GL_UNSIGNED_BYTE,
Data
);
ofstream File("Screenshot.raw", ios::binary);
if (File.is_open())
File.write(Data, Width() * Height() * 3);
delete [] Data;
}


some explanations:
typedef unsigned char UByte;

Width() and Height() are 2 (wrapped) properties of my windowclass, guess what they mean (;


i think gavain is right, u try writing the data to the address of the pointer und not the address the pointer points at