Results 1 to 3 of 3

Thread: anyone know how to use the ALIGNMENT parameter used in the glPixelStore

  1. #1
    Senior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Nanjing,China
    Posts
    116

    anyone know how to use the ALIGNMENT parameter used in the glPixelStore

    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 .

    Regards

  2. #2

    Re: anyone know how to use the ALIGNMENT parameter used in the glPixelStore

    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:

    glPixelStorei(GL_PACK_ALIGNMENT, value);
    glPixelStorei(GL_UNPACK_ALIGNMENT, value);

    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).]

  3. #3
    Senior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Nanjing,China
    Posts
    116

    Re: anyone know how to use the ALIGNMENT parameter used in the glPixelStore

    Thanks very much , I got the point at last.

    [This message has been edited by RunningRabbit (edited 09-02-2002).]

Similar Threads

  1. What does glPixelStore() do?
    By yj1214 in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 09-01-2015, 08:03 PM
  2. glReadPixel and glPixelStore
    By devdept in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 11-25-2008, 01:49 AM
  3. Scope of glTexParameter, glTexEnv, glPixelStore.
    By JCipriani2 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-06-2008, 12:04 PM
  4. gldrawpixels and glpixelstore tutorial request
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-10-2004, 04:11 AM
  5. Dose glPixelStore affect convolution?
    By xysh in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 06-05-2002, 10:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean