Wednesday, June 15, 2011

glReadBuffer example c c++ java objc

Name

glReadBuffer — select a color buffer source for pixels

C Specification

void glReadBuffer(GLenum  mode);

Parameters

mode
Specifies a color buffer. Accepted values are GL_FRONT_LEFTGL_FRONT_RIGHTGL_BACK_LEFTGL_BACK_RIGHTGL_FRONTGL_BACKGL_LEFTGL_RIGHT, andGL_AUXi, where i is between 0 and the value of GL_AUX_BUFFERS minus 1.

Description

glReadBuffer specifies a color buffer as the source for subsequent glReadPixelsglCopyTexImage1DglCopyTexImage2DglCopyTexSubImage1D,glCopyTexSubImage2DglCopyTexSubImage3D, and glCopyPixels commands. mode accepts one of twelve or more predefined values. (GL_AUX0 throughGL_AUX3 are always defined.) In a fully configured system, GL_FRONTGL_LEFT, and GL_FRONT_LEFT all name the front left buffer, GL_FRONT_RIGHT and GL_RIGHTname the front right buffer, and GL_BACK_LEFT and GL_BACK name the back left buffer.
Nonstereo double-buffered configurations have only a front left and a back left buffer. Single-buffered configurations have a front left and a front right buffer if stereo, and only a front left buffer if nonstereo. It is an error to specify a nonexistent buffer to glReadBuffer.
mode is initially GL_FRONT in single-buffered configurations and GL_BACK in double-buffered configurations.

Errors

GL_INVALID_ENUM is generated if mode is not one of the twelve (or more) accepted values.
GL_INVALID_OPERATION is generated if mode specifies a buffer that does not exist.
GL_INVALID_OPERATION is generated if glReadBuffer is executed between the execution of glBegin and the corresponding execution of glEnd.

Associated Gets

glGet with argument GL_READ_BUFFER

Copyright

Copyright © 1991-2006 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;
}