View Full Version : Switching Rendering Contexts
So i found that if I render to an offscreen bitmap that is 4 times the size of my window, and then stretchBlt that bitmap into the window's DC my image looks a lot less pixelated. I want to do this only when the user is not moving the model around wiht the mouse. To do this i render normal size directly to the window (PRD_DRAW_TO_WINDOW) most of the time. I render to the 4X bitmap (PFD_DRAW_TO_BITMAP) when a timer goes off telling me the user hasn't moved the mouse in a second.
To do this i am trying to use two different rendering contexts and switch between them using the wglMakeCurrent function. I do this in the OnPaint callback just before i write out all my polygons. The model has multiple texture maps, so I make a call to glBindTexture before writing out the polygons.
The issue is that only one of the rendering contexts actually draws to the screen, either the one that draws quickly to the window, or the one that is antialiased drawn to the bitmap. The one which works is the one that was active when i loaded the texture maps. This led me to try and load the same texture maps once for each of the rendering contexts. That didn't work either. If anyone has any ideas on whether these scheme should work, and what i'm doing wrong i would appreciate input. Thanks -
12-08-2004, 11:41 PM
The draw_to_bitmap one is highly likely to be a Microsoft OpenGL implementation, as graphics hardware doesn't render into memory DCs.
To share textures among contexts you need to call wglShareLists after you created the context and the second context in the wglShareLists call must not be current, IIRC.
OpenGL object sharing doesn't work among different implementations. The manual mentions it should use the same pixelformat, but most of the times it's enough if the same OpenGL implementation is used.
For your case that means you either need to download the textures for each context (but you said that didn't work, but it should) or ditch the draw_to_bitmap context and use a hardware accelerated render-to-texture pbuffer and downsample with a textured quad using the GL_LINEAR minification filter.
The good thing about this is that everything is hardware accelerated and the features are not limited to Microsoft's OpenGL 1.1 implementation.
I think you're right on the bitmap context being a microsoft implementation :(
As for pBuffers, I'm not familiar with them so I looked them up in my OpenGL SuperBible and it had a listing under the linux GLX section. Are pBuffers a Linux only feature, or is there a way to use them on windows? It also said that not all implementations support pBuffers. I'm wanting to use multimapping when i can do to my full-screen antialiasing, but the idea behind rendering to the bitmap and then stretchBlting was to provide a level of full-screen antialiasing for people who don't have video cards that support multisampling. Any ideas?
I'll explain in more detail how i loaded the textures into OpenGL for both contexts a little better, maybe i'm doing it wrong:
I create both contexts. Then i read my image into a BYTE array from disk. then I use wglMakeCurrent to make the first context current, i call glGenTextures using an int array for the first context. Then i load in the texture using glTexImage2D, then set the parameters. Then i switch to the second context using wglMakeCurrent again and repeat the cycle. I have noticed running through the debugger that when i do it this way the glGenTextures function returns a 1 for the texture ID for both contexts. I figured this was because there is a texture ID set for each rendering context, is this correct?
Thanks for all the feedback -
12-09-2004, 10:56 PM
P-buffers are available as an extension.
Check the official extensions site: http://oss.sgi.com/projects/ogl-sample/registry/
You need the WGL_ARB_pixelformat extension to select one.
Here are some demos
Search for "simple p-buffer" and "simple render texture"
About the texture id's, yes, each context has an own list of completely different texture objects, display lists, etc. Unless you called wglShareList successfully.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.