PDA

View Full Version : glReadPixels/glDrawPixels



weber_ofir
08-24-2000, 06:30 PM
I have problems using the glReadPixels/glDrawPixels functions. I geting strangle results. I am using this code:


static GLfloat pixelsColor1[512*512];
static GLfloat pixelsColor2[512*512];
static GLfloat pixelsDepth1[512*512];
static GLfloat pixelsDepth2[512*512];

auxSolidBox(5, 2, 3);
glFinish(); //force openGL to start render the scene.

glReadPixels(0, 0, 450, 450, GL_DEPTH_COMPONENT, GL_FLOAT, pixelsDepth1);
glReadPixels(0, 0, 450, 450, GL_RGB, GL_FLOAT, pixelsColor1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

auxSolidBox(6, 4, 8);

glFinish(); //force openGL to start render the scene.

glReadPixels(0, 0, 450, 450, GL_DEPTH_COMPONENT, GL_FLOAT, pixelsDepth2);
glReadPixels(0, 0, 450, 450, GL_RGB, GL_FLOAT, pixelsColor2);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);



glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glDrawPixels(450, 450, GL_DEPTH_COMPONENT, GL_FLOAT, pixelsDepth1);
glDrawPixels(450, 450, GL_RGB, GL_FLOAT, pixelsColor1);
glDrawPixels(450, 450, GL_DEPTH_COMPONENT, GL_FLOAT, pixelsDepth2);
glDrawPixels(450, 450, GL_RGB, GL_FLOAT, pixelsColor2);


I am geting distorted results. if i am using the glReadPixels and glDrawPixels command only onces, the problem disappears.
Please, Help me if you know what's the problem.

inet
08-25-2000, 12:15 AM
First, I'd like to point out,your color buffer for RGB isn't enough. It should be
3 times.

Secondly, I haven't got distorted image.
But I only got the second image.
I don't know why you draw the two
depth images. I think you can only see
the second image because the depthbuffer
is totally overwritten by the second image's Depth.

If what u want is to combine two depth iamges, I think you can refer to
"OpenGL Programming Guide, 3rd Edition"
Page 587.

weber_ofir
08-26-2000, 02:53 AM
First of all thanks for your answer.
What do you mean by saying that the buffer is not enough? I am saving the data in a static array. What do you mean "It should be 3 times" ?
also, i don't have the 3rd edition of the book. Do you know if there is an electronic version of it, or do you know if the second edition also have it?
About the reason that i do that: I am writing a special renderer for "impossible 3D scenes" (like the ones that the artist M.C. Escher drew). So if i have a scene that consist of few objects, i need to render each one of them separately and save the color buffer and depth buffer for each object. Than i need to combine all of them in a special way. Do you know if there is other way that i can do this? I can identify each pixel in an image by the alpha value so each object will have a special number that identify it. But than i need a way to influence only pixels that belong to a specific object, i.e. the pixels have a specific alpha value. Do you know if there's a way to do this?

thank you very much.



Originally posted by inet:
First, I'd like to point out,your color buffer for RGB isn't enough. It should be
3 times.

Secondly, I haven't got distorted image.
But I only got the second image.
I don't know why you draw the two
depth images. I think you can only see
the second image because the depthbuffer
is totally overwritten by the second image's Depth.

If what u want is to combine two depth iamges, I think you can refer to
"OpenGL Programming Guide, 3rd Edition"
Page 587.

inet
08-28-2000, 07:30 AM
3 times just because you have to store the
RGB data(Three components)

About composite depth image,you can refer to this website http://reality.sgi.com/blythe/sig99/advanced99/notes/node118.html

The main idea is to use the stencil buffer.