How to use glReadPixel problem...

Hi,

I use readPixel for generating pictures from my OpenGL scene.

I would like to generate BMP pictures. For that, I need the bytes table returns by glReadPixel… I work in Java and all I arrive to produce is blackpictures. It seems that my Java code is correctly written for generating the picture.

I Think I have a problem with the byte table of glReadPixel… Here is my code

byte [] Frame = new byte[Height_Picture*scanlineStride];
gl.glReadPixels(0, 0, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, Frame);

I do not know also how to correctly define the syze of the table.

Could you help on how to use glReadpixel and how to configure the size of the table…

Thanks a lot
Mat

Its been ages since I’ve wriiten in Java, but memory tells me there me be some issue with the size of a byte??? Try set the array to GLubyte. Also, is there a reason your array isn’t HeightWidthBYTES_PER_PIXEL?
Joe

Hi,

Thanks for your reply,
there is one thing I do not understand. If I use as parameters:

gl.glReadPixels(0, Height, Width, -Height, GL_RGB, GL_BYTE, Frame);

it means it will gives me 8 bits for each composant R,G and B of one Pixel ??

So the size of my table shouldn’t be

widthheight8*3 ??

Thanks a lot

Mat

No, you specify the size of your table in bytes not bits.

So… the size of your table should be
width * height * 3 for an RGB image. For RGBA it would be width * height * 4.

[QUOTE]Originally posted by Deiussum:

Thanks for your reply…

I arrived to generate the pictures. I worked since I put the gl.glReadPixels command before gljFree()…

Now I have a problem with the color that are not correctly rendered… Do you know from what it could come ?

I used GL_RGB and I work on Windows…

Thank a lot
Mat

What do you mean by the colors not being correctly rendered? glReadPixels reads the rendered colors, not renders them?

One other thing I thought of that would be worth noting is to check out the documentation for glPixelStore. For glReadPixels you may need to set the GL_PACK_ALIGNMENT to 1, and for glWritePixels you may need to set GL_UNPACK_ALIGNMENT to 1.

In fact,

the picture I get, has many defaults:

  • first, it is deformed and not in the right way.

  • I have many thin lines crossing the pictures

  • And finally I do not have the same colours as the colour of my OpenGL scene.

But I just arrived to produce the pictures yersteday evening… I did not have time yet to work on it. I will try what you told me… and post new topic if I still have problems !

Thanks for your help

Regards
Mat

Could you perhaps provide a screenshot so we can see what’s wrong with the image?

-Mezz

Hi,

here is a page with the the correct view (up) and the picture I have (down). I t seems that the line crossing the picture and not appearing normally results from the deformation. It must the border of the picture…
http://perso.wanadoo.fr/mathieu.rossier/Doc1.htm

Mat

I am sorry but you do not see it very well the colours on the pictures…In the correct view, you only have blue and red and in the picures, it seems difficult to see clearly what are the colours, like a mix…

Mat

Hi,

I tried what Deiussum told to do (set up glPixelRead with glPixelStore) and it works perfectly ! The picture is not deformed anymore and the colours are perfect.

But the picture is still not in the right way… I will work on this…

Thanks a lot Deiussum

Mat

Windows .BMP files havy the origin at the top left corner of the bitmap. I believe that the buffer filled out by glReadPixels has the origin at the bottom left corner. You cancorrect for this by setting the height member of the BITMAPINFOHEADER struct to be negative.

Originally posted by Mat:
[b]Hi,

I tried what Deiussum told to do (set up glPixelRead with glPixelStore) and it works perfectly ! The picture is not deformed anymore and the colours are perfect.

But the picture is still not in the right way… I will work on this…

Thanks a lot Deiussum

Mat

[/b]

Hi

thanks for your reply
it is exactly what happened… The left bottom corner was in fact in the left up corner… I arrived to change this by exercing a flip vertical rotation to the BufferedImage with the help of JAI APIS… (Java Advance Imaging)…

Thanks for your solution
Mat