Download OpenGL Programming on Mac OS X
Transcript
Creation and use of off-screen surfaces begins with specification of the GL AGL OFFSCREEN token when constructing a pixel format. Only an AGLContext that has been successfully created with a pixel format using this token can be used to perform true off-screen rendering. After creation of a context, the next steps are to bind this off-screen render area, to make it active for rendering, and to render. As with full-screen and windowed rendering, there is an analogous command, aglSetOffScreen, to perform this binding. The target of this binding is a memory buffer you specify in the call, rather than an existing Carbon window. The Apple documentation pages have detailed information on all the arguments these calls take. As this isn’t really recommended practice, we won’t describe this technique in more detail. Consult the Apple documentation for the most complete descriptions of the methods. Pbuffers Pixel buffers are another alternative rendering destination commonly used for off-screen rendering. However, unlike the named “off-screen” areas, pbuffers can be fully hardware accelerated. That makes them quite useful for real-time generation of textures, among other things. Pbuffers are an invention of the late 1990s (circa 1997) and, though fully functional, they contain a bit of complexity that more modern render implementations such as framebuffer objects do not. In essence, pbuffers are useful analogs to framebuffer objects, but for modern code, framebuffer objects are preferred. Table 7-4 shows the list of functions within AGL useful for creation and use of pbuffers. Chapter 6 showed the same procedure necessary for this task, so we’ll simply summarize and show some example code here. The basic process is as before: Create a pbuffer (aglCreatePBuffer), make it active (aglSetPBuffer), and perform some rendering into it. Example 7-8 demonstrates the main loop performing the basic AGL context and AGL pbuffer context creation tasks. Table 7-4 AGL Pbuffer Functions Function Description aglCreatePBuffer Creates an AGL pixel buffer for use with an OpenGL texture type Destroy an AGL pixelbuffer Gather information about an AGL pixelbuffer Query a context for the pixelbuffer attached to it Set the pixel buffer to be the target for the specified context Binds a pixel buffer as a texture; analogous to glTexImage2D aglDestroyPBuffer aglDescribePBuffer aglGetPBuffer aglSetPBuffer aglTexImagePBuffer 110 Chapter 7: The AGL API for OpenGL Configuration