View Full Version : glReadPixels and viewport problem

11-26-2003, 01:29 PM
Hi all,
I'm developing an application in which I get the viewport through glReadPixels and then I write it in to a PPM file. A situation depending on the viewport size arises. If the viewport is 250x250, the buffer returned from glReadPixels shows the viewport in 'italic' (the image is incorrect), a vertical line comes as a diagonal for example. However, if size is 500x500, everything is fine. Other similar situations arise depending on the viewport size. This is indeed strange, I've not set any state variable relating to glReadPixels, do I need to set or enable any special variable? Is this a known issue?I've decided not to include any code, if you would like some code to test it, I'll be happy to send it to you privately.Oh, and the problem is not in the procedure that writes the PPM file from the glReadPixels buffer since it was tested by some people and all get the same results with glReadPixels (I cannot assure you it's not in the PPM file but it's not probable).

Best regards,
Paulo J. Matos : pocm [_at_] mega . ist . utl . pt
Instituto Superior Tecnico - Lisbon
Computer and Software Eng. - A.I.
- > http://mega.ist.utl.pt/~pocm
--- -> God had a deadline... So, he wrote it all in Lisp!

11-26-2003, 01:46 PM
Check out the pack alignment. 250 is not a multiple of 4, which is the default pack alignment, so you must either change it, or change the destination buffer to hold the padding (2 bytes at the end of each row in this case).

Chapter 9 (http://www.parallab.uib.no/SGI_bookshelves/SGI_Developer/books/OpenGL_PG/sgi_html/ch09.html) in the Red Book is a good start.