PDA

View Full Version : Reading Rendered Image



King Fuzzy
09-17-2001, 06:49 PM
I am trying to read a rendered image
I have the command
glReadPixels(x,y,1,1,GL_RGBa,GL_INT,@pxd);
in my code but all i get is black (0's)
Please Help Me http://www.opengl.org/discussion_boards/ubb/confused.gif

mikael_aronsson
09-17-2001, 09:41 PM
Hi !

Maybe the pixel in the lower left (or upper left) corner is black ?, you have put 1 for both width and height ?, is this what you want ?

Mikael

King Fuzzy
09-18-2001, 12:37 AM
Originally posted by mikael_aronsson:
Hi !

Maybe the pixel in the lower left (or upper left) corner is black ?, you have put 1 for both width and height ?, is this what you want ?

Mikael
by changing x and y I scan the whole pic and all the pixels read as black even though some of them are green

Gavin
09-18-2001, 02:17 AM
So all components r,g,b and a are 0? Are you sure there is not a pointer problem or you have allocated enough memory and so on? do you want to post the code

gav

King Fuzzy
09-18-2001, 03:22 AM
Originally posted by Gavin:
do you want to post the code
gav

setup procedures have been removed
the cube is being rendered correctly


var pxd:array[0..256000] of integer;
cube:integer;

procedure TForm1.GLControl1Render(Sender: TObject);
var x,y:integer;
Begin
glLoadIdentity;
gluLookAt(5,5,5, 0,0,0, 5,5,1000);
glPushMatrix;
glCallList(cube);
for y:=0 to 168 do
begin
for x:=0 to 184 do
begin
glReadPixels(x,y,1,1,GL_RGBa,GL_INT,@pxd);
PaintBox1.Canvas.Pixels[x,y]:=pxd[0];
end;
end;
end;

Gavin
09-18-2001, 04:15 AM
a couple of things. why is pxd so big? if the image size rendered can change why are you not allocating it dynamically (setlength). I have a funny feeling that you need to declare a type, bugger I can't remember. Something like
glubyte := ^array_pointer;

glReadPixels(x,y,1,1,GL_RGBa,GL_INT,@array_pointer );

its a while since I did it in delphi. Also I would imagine that it will be quicker to read the whole image to an arrray and then access the array. Also look at using a array[x][y].record if you see what I mean. I think opengl can read from the buffer to a array of structures (records).

King Fuzzy
09-18-2001, 09:53 AM
Originally posted by Gavin:
a couple of things...
at the moment it is so big because the last thing i need is errors from it overwriting the alocated space,
when I am finished I will be reading only a few pixels each time it is rendered. so speed isnt required,
the perpose of this it to enable me to locate what object is under the mouse pointer

I have discovered that by changing the background color I det a different result, I might be able to figure out what is wrong myself now , Will publish findings

Gavin
09-18-2001, 10:24 AM
Why not use a selection buffer?

King Fuzzy
09-18-2001, 10:30 AM
I discovered I should have been using GL_BYTE not GL_INT
I also found the pic is upside down (easy fixed)

if the buffer was alocated for the size I required I would have had it 1/4 of the size glReadPixels needed

It is working but not the way I wanted
Will be posting a new topic for this problem