View Full Version : anyone know how to use the ALIGNMENT parameter used in the glPixelStore
08-31-2002, 11:31 PM
I am new to the opengl and readign the red book.i don't know the how alignment pname used in the function glPixelstore.The book does not give away explanation which make myselves understood.
the red book give a example on the page 310,
it reads "if the image is 5 pixels wide and each pixel consists of 1 byte each of red,green,and blue information,a row requires 5x3=15 bytes of data,Maximum display efficiency can be achieved if the first row,and each successive row,begins on a 4-byte boundary,so there is 1 byte of waste in the memory storage for each row."
Why we can not set the alignment set to 3,because each pixel data occupy 3 byte. and if the alignment is 4 there is 1 byte of waste each row, there should be(4-3)*5=5 waste each row.
Can anyone enlight me on this little point ,best Appreciated .
09-02-2002, 12:45 AM
GL_PACK_ALIGNMENT and GL_UNPACK_ALIGNMENT specify how to (and whether or not to) pad each row of images that are read from and written to, respectively, OpenGL pipeline. Valid values are 1 (byte alignment), 2 (word alignment), 4 (dword alignment), and 8 (qword alignment). Defaults for both are 4. The calls are:
For example, if your GL_UNPACK_ALIGNMENT is 8, each image read from OpenGL (for example, with glReadPixels or glGetTexImage), whose (width * sizeof(one-pixel)) is not a multiple of 8, will be right-padded (in each row) to the nearest multiple of 8.
Likewise with GL_PACK_ALIGNMENT, except now we are talking about glDrawPixels and glTexImage1D/glTexImage2D. If GL_PACK_ALIGNMENT is 8, the OpenGL pipeline assumes that each row of image it is requested to read is right-padded to the nearest multiple of 8.
If your pack alignment is anything other than 1, you must take that into account when loading images, and either make sure that all your image (width * sizeof(one-pixel)) are a multiple of pack alignment or pad them accordingly. Likewise, if unpack alignment is not 1, make sure you allocate enough memory for the images you grab from the screen, or OpenGL may run out of bounds while writing pixeldata.
By the way there are other paramenters to glPixelStorei, but these are mostly related to endianness (whether you want bits in a byte from most significant to least significant or other way around, whether you want bytes in a word from most significant to least significant ot otherwise, etc) - these you might want to set depending on the platform you are working on, and the image formats you are loading.
[This message has been edited by Pa3PyX (edited 09-02-2002).]
09-02-2002, 12:53 AM
Thanks very much , I got the point at last.
[This message has been edited by RunningRabbit (edited 09-02-2002).]
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.