opengl texture byte alignment libpng libjpeg

 

glTexImage2d requires rows to be 4-byte aligned,  It's default value,but we can change

-------------------------

void glPixelStorei( GLenum pname,
      GLint param);


glPixelStorei sets pixel storage modes that affect the operation of subsequent glReadPixels as well as the unpacking of texture patterns (see glTexImage2D and glTexSubImage2D).

pname is a symbolic constant indicating the parameter to be set, and param is the new value. One storage parameter affects how pixel data is returned to client memory:

GL_PACK_ALIGNMENT
Specifies the alignment requirements for the start of each pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on double-word boundaries).

The other storage parameter affects how pixel data is read from client memory:

GL_UNPACK_ALIGNMENT
Specifies the alignment requirements for the start of each pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on double-word boundaries).

 

--------------------libpng libjpeg      determinate the width aligned mode,choose  glPixelStorei  parameters.

int rowbytes = png_get_rowbytes(png_ptr, info_ptr);

 

jpeg_start_decompress(&info); //decompress the file
//set the x and y
x = info.output_width;

 

 

 

 

posted on 2013-04-03 09:03  dearplain  阅读(278)  评论(0编辑  收藏  举报