PDA

View Full Version : Reading buffers problems



Zoran Zivkovic
07-03-2000, 01:54 AM
The problem is that when I read depth buffer and color buffer the images I get are horizontaly displaced with respect to each other.

I draw the scene in the back buffer, and than I do:

glPixelStorei(GL_PACK_ALIGNMENT,1);
glFlush();
glReadBuffer(GL_BACK);

glReadPixels (0, 0, m_myRect.right, m_myRect.bottom, GL_RED, GL_UNSIGNED_BYTE, frameBuffer);

glReadPixels (0, 0, m_myRect.right, m_myRect.bottom, GL_DEPTH_COMPONENT, GL_FLOAT, ZBuffer);

It is done under Windows.

Does anybody have an idea what might be the problem?

Zoran Zivkovic
07-03-2000, 10:56 PM
By horizontally misaligned I mean something like the following:

float r;
BYTE p;
glReadPixels (63, 128,1,1, GL_DEPTH_COMPONENT, GL_FLOAT, &r);
glReadPixels (63, 128,1,1, GL_RED, GL_UNSIGNED_BYTE, &p);

glReadPixels (64, 128,1,1, GL_DEPTH_COMPONENT, GL_FLOAT, &r);
glReadPixels (64, 128,1,1, GL_RED, GL_UNSIGNED_BYTE, &p);
...

I have a white object on black background(far clipping plane) and I get the
something like:
r: 1 0.4 0.4 0.4 0.4 ...
p: 0 0 0 255 255 ...

Bob
07-05-2000, 07:18 AM
Let's see if I get your results right here.
You get the values at two pixels ((63, 128) and 64, 128)), and you get:
First read: depth=1 and RGB=0,0,0
Second read: depth=0.4 and RGB=255,255,255

Correct?

If so, i can't see no problem.
You said black background, and that seems to be first read, rgb=0,0,0 and depth=1. This makes sence to me, because nothing is drawn (color is black, as the background), then depth is 1, which means far plane.
You said white object, and that seems to be second read, rgb=255,255,255 and depth=0.4. White object (color matches the object), and depth is 0.4 (means 40% from near to far plane), and something must have been drawn here.

Am I wrong?

Zoran Zivkovic
07-19-2000, 02:41 AM
I am reading only RED component so:
position:
(63,128)(64,128)(65,128)(66,128)(67,128)...
r: 1 0.4 0.4 0.4 0.4 ...
p: 0 0 0 255 255 ...

Relic
07-19-2000, 07:58 AM
>>I am reading only RED component so:
position:
(63,128)(64,128)(65,128)(66,128)(67,128)...
r: 1 0.4 0.4 0.4 0.4 ...
p: 0 0 0 255 255 ...
<<

I also would expect that to work.

It looks like the GL_RED does not work for you and puts RGB into your p-buffer.
Check if this could be the case with a byte buffer three times as big as the desired one and look at the contents of the first depth dropping back to zFar. Is it three bytes per pixel position in the p-buffer?

If yo work under Windows and have HW acceleration enabled, try working with the Microsoft software OpenGL implementation by specifying PFD_GENERIC_FORMAT in the pixelformatdescriptor.
Does this work? Could be a driver error then.


[This message has been edited by Relic (edited 07-19-2000).]