|
|
发表于 2005-4-30 12:04:00
|
显示全部楼层
Re:如何在指定窗口实现OpenGL?
Off-screen Rendering Using Pixel Buffers
The samples below demonstrate how to create dynamic textures through off-screen rendering. The off-screen rendering step is accomplished using a pbuffer, which is created through a combination of OpenGL's WGL_ARB_pbuffer, and WGL_ARB_pixel_format extensions. The second step of dynamic texture creation varies between the versions. Please see the implementation notes below for further information.
Version #1 - The dynamic texture is created by reading the pixel data out of the pbuffer with glReadPixels and then loading it into our texture with a regular call to glTexImage2D. This is by far the slowest way to create dynamic textures from a pbuffer.
Version #2 - In this version, we use wglShareLists to help out dynamic texture creation by sharing the window's rendering context with the pbuffer's context. With the two contexts sharing the same display list and texture space, we can simply load the texture with pixel data by calling glCopyTexSubImage2D. This is obviously faster than version #1, if you're willing to share contexts.
Version #3 - For our last version, we actually add a third extension, WGL_ARB_render_texture, and as the name implies, the extension basically lets us render directly to our dynamic texture. If the hardware supports it, this is the fastest method of creating dynamic textures from a pbuffer.
Relevant Keywords: WGL_ARB_pbuffer, WGL_ARB_pixel_format, WGL_ARB_render_texture, wglCreatePbufferARB, wglGetPbufferDCARB, wglReleasePbufferDCARB, wglDestroyPbufferARB, wglQueryPbufferARB, wglGetPixelFormatAttribivARB, wglGetPixelFormatAttribfvARB, wglChoosePixelFormatARB, wglBindTexImageARB, wglReleaseTexImageARB, wglSetPbufferAttribARB, wglGetExtensionsStringARB, wglGetProcAddress, glGenTextures, glBindTexture, glTexParameteri, glTexImage2D, glReadPixels, glCopyTexSubImage2D, WGL_SUPPORT_OPENGL_ARB, WGL_DRAW_TO_PBUFFER_ARB, WGL_BIND_TO_TEXTURE_RGBA_ARB, WGL_RED_BITS_ARB, WGL_GREEN_BITS_ARB, WGL_BLUE_BITS_ARB, WGL_ALPHA_BITS_ARB, WGL_DEPTH_BITS_ARB, WGL_DOUBLE_BUFFER_ARB, WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB, WGL_TEXTURE_2D_ARB, WGL_PBUFFER_WIDTH_ARB, PFNWGLCREATEPBUFFERARBPROC, PFNWGLGETPBUFFERDCARBPROC, PFNWGLRELEASEPBUFFERDCARBPROC, PFNWGLDESTROYPBUFFERARBPROC, PFNWGLQUERYPBUFFERARBPROC, PFNWGLGETPIXELFORMATATTRIBIVARBPROC, PFNWGLGETPIXELFORMATATTRIBFVARBPROC, PFNWGLCHOOSEPIXELFORMATARBPROC, PFNWGLBINDTEXIMAGEARBPROC, PFNWGLRELEASETEXIMAGEARBPROC, and PFNWGLSETPBUFFERATTRIBARBPROC. |
|