Graphics Reference
In-Depth Information
To implement these operations, our code closely follows the outline
above. The code is presented in three groups. The first code group implements
the first four points and would typically be found in your InitGraphics( )
function. This is independent of the particular teapot and quad example of the
figure.
// generate FrameBuffer handle, RenderBuffer handle, Texture
// handle
GLuint FrameBuffer;
GLuint DepthBuffer;
GLuint Texture;
glGenFramebuffers( 1, &FrameBuffer );
glGenRenderBuffers( 1, &DepthBuffer );
glGenTextures( 1, &Texture );
// set up the size for the rendered texture
int sizeX = 2048;
int sizeY = 2048;
// Bind the offscreen framebuffer to be the current output
// display
glBindFramebuffer( GL_FRAMEBUFFER, FrameBuffer );
// Bind the Depth Buffer to the context, allocate its storage,
// and attach it to the Framebuffer
glBindRenderbuffer( GL_RENDERBUFFER, DepthBuffer );
glRenderbufferStorage( GL_RENDERBUFFER,
GL_DEPTH_COMPONENT, sizeX, sizeY );
glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, DepthBuffer );
// Bind the Texture to the Context
glBindTexture( GL_TEXTURE_2D, Texture );
// Set up a NULL texture of the size you want to render into
// and set its properties
glTexImage2D( GL_TEXTURE_2D, 0, 4, sizeX, sizeY, 0, GL_RGBA,
GL_UNSIGNED_BYTE, NULL );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
GL_REPLACE );
Search WWH ::




Custom Search