Wednesday, June 15, 2011

glPixelStorei example c c++ java objc

Name

glPixelStorei — set pixel storage modes

C Specification

void glPixelStorei(GLenum pname,
GLint param);

Parameters

pname
Specifies the symbolic name of the parameter to be set. GL_PACK_ALIGNMENT affects the packing of pixel data into memory. GL_UNPACK_ALIGNMENTaffects the unpacking of pixel data from memory.
param
Specifies the value that pname is set to.

Description

glPixelStorei sets pixel storage modes that affect the operation of subsequent glReadPixels as well as the unpacking of glTexImage2D, andglTexSubImage2D.
pname is a symbolic constant indicating the parameter to be set, and param is the new value. The following storage parameter affects how pixel data is returned to client memory. This value is significant for glReadPixels:

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 initial value is 4.
The following storage parameter affects how pixel data is read from client memory. This value is significant for glTexImage2D and glTexSubImage2D:

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). The initial value is 4.

Notes

Pixel storage modes are client states.
glCompressedTexImage2D and glCompressedTexSubImage2D are not affected by glPixelStorei.

Errors

GL_INVALID_ENUM is generated if pname is not an accepted value.
GL_INVALID_VALUE is generated if alignment is specified as other than 1, 2, 4, or 8.

Associated Gets

glGet with argument GL_PACK_ALIGNMENT or GL_UNPACK_ALIGNMENT

Copyright

Copyright © 2003-2004 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, seehttp://oss.sgi.com/projects/FreeB/.



Example

void DrawIt()
{
unsigned char *pBuffer = new unsigned char[300*300*4];

// Drawing OpenGL Geometry.
//
glClear(GL_COLOR_BUFFER_BIT);

//glPushMatrix();

glScalef(0.5f, 0.5f, 0.5f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 1.0f, -1.0f);
glEnd();

//glPopMatrix();

SwapBuffers(g_hDC);

// Read pixels from color buffer.
//
memset(pBuffer, 0, 300*300*4);
glPixelStorei(GL_PACK_ALIGNMENT, 4);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

// Choose where to read from.
//
glReadBuffer(GL_FRONT);
glReadPixels((GLdouble)300, (GLdouble)300, 30, 30, GL_RGBA, GL_UNSIGNED_BYTE, pBuffer);
delete[] pBuffer;

return;
}