glReadPixels(....)

somebody plzz help me with this

unsigned char buffer =[4006003]

i draw a rectangle on the screen.
i use glReadPixels (0,0,400,600,GL_RGB,GL_UNSIGNED_BYTE,buffer)
to read the pixel values.

when i write the contents of buffer to a file, the file contains all I’s [ some dots on top of I ]. why is this? why am i not able to read the pixel values. and why is the file containing all same characters when i write to it?

How are you writting the data to the file as ASCII or binary?

maybe post your save file routine.

Originally posted by dummy_24:
[b]somebody plzz help me with this

unsigned char buffer =[4006003]

i draw a rectangle on the screen.
i use glReadPixels (0,0,400,600,GL_RGB,GL_UNSIGNED_BYTE,buffer)
to read the pixel values.

when i write the contents of buffer to a file, the file contains all I’s [ some dots on top of I ]. why is this? why am i not able to read the pixel values. and why is the file containing all same characters when i write to it?[/b]

shouldnt there be a pointer to “buffer” (&buffer / *buffer). its been sometime since i programmed in c/c++

here’s the code i am using for that.

unsigned char buffer[4006003];

glReadPixels( 0, 0, 400, 600 , GL_RGB, GL_UNSIGNED_BYTE, buffer );

fwrite(buffer, 400603, 1, jptr);
// jptr is the pointer to the file i am writing.

i am trying to do this to get a ppm image of the type “P6”. i have included the necessary header information for ppm format in the file.

fwrite(buffer, 400603, 1, jptr);

Maybe it should be 4006003 instead?

That said, it’s hard to tell what’s going on without a more detailed explanation and/or code.

yeah it is 4006003.

all i do is

draw a set of points
glBegin(GL_LINES)
glVertex2i(100,100);

glEnd();

now i read the frame buffer
glReadPixels(…)

i write it to the file
fwrite(…)

the contents of the o/p files is same, i mean only one funny character is wriiten on the o/p file. why is this ?

i can’t explain anything more simple than this.

What are you draw and read buffers? ie: did you call glDrawBuffer() or glReadBuffer() at any point?

nope, i am not using them anytime, anywhere. i read glReadPixels(…) does all the work of copying pixel information from the frame buffer into the declared array.

Hi !

I assume you check for errors (glGetError) and that you have an active rendering context when you call glReadPixels() ?

Mikael

Did you examine the readback buffer before dumping it to a file? Maybe ReadPixels returned the “correct” data, but you are writing/viewing it incorrectly?

glReadBuffer back/front. are you setting this one right?

Originally posted by mithun_daa:
glReadBuffer back/front. are you setting this one right?

Most of the time you shouldn’t have to touch ReadBuffer since it is initialized automatically. For a single buffered fb ReadBuffer defaults to GL_FRONT and for double buffering it defaults to GL_BACK.