PDA

View Full Version : glReadPixels(....)



dummy_24
02-10-2004, 07:34 AM
somebody plzz help me with this

unsigned char buffer =[400*600*3]

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?

nexusone
02-10-2004, 09:03 AM
How are you writting the data to the file as ASCII or binary?

maybe post your save file routine.

mithun_daa
02-10-2004, 11:01 AM
Originally posted by dummy_24:
somebody plzz help me with this

unsigned char buffer =[400*600*3]

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?

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

dummy_24
02-10-2004, 12:18 PM
here's the code i am using for that.

unsigned char buffer[400*600*3];

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

fwrite(buffer, 400*60*3, 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.

al_bob
02-10-2004, 07:34 PM
fwrite(buffer, 400*60*3, 1, jptr);
Maybe it should be 400*600*3 instead?

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

dummy_24
02-10-2004, 07:39 PM
yeah it is 400*600*3.

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.

al_bob
02-10-2004, 07:41 PM
What are you draw and read buffers? ie: did you call glDrawBuffer() or glReadBuffer() at any point?

dummy_24
02-10-2004, 07:52 PM
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.

mikael_aronsson
02-10-2004, 10:00 PM
Hi !

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

Mikael

roffe
02-11-2004, 07:17 AM
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?

mithun_daa
02-11-2004, 10:35 AM
glReadBuffer back/front. are you setting this one right?

roffe
02-11-2004, 11:52 AM
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.