OpenGL - DirectX Interop
A library that allows the developer to render in OpenGL or DirectX or both.  Supports nVidia's 3D Vision stereo.
Want to render some things in DirectX and other things using OpenGL, and have them all render to a single output screen?  Yep, this is what this library does...  well, mostly (read the Background section for details).  Render your scene partially with either technology and have the output smashed together in one harmonious and glorious rendered output.  You can even switch back and forth between OpenGL and DirectX multiple times before calling Present on the DirectX device or SwapBuffers on the OpenGL context.  The library even supports nVidia's 3D Vision stereo, so you can render your scene from the left eye and render again for the right eye, and then the library takes care of the rest.
Please check out this site for downloads
I know what you're thinking...  no way does this work!  Yeah, that's what we were thinking too, but in fact, it does work.  Right now, the library is setup to render a scene using OpenGL and then display that rendered scene using DirectX, but this can easily be modified to render DirectX data as well.
The interop is really just a wrapper around a pre-existing interop provided by nVidia.  nVidia's interop is provided as part of the wgl extensions (see NV_DX_interop and NV_DX_interop2), so your current OpenGL driver version must support this wgl extension.  If the extension does not exist, GetLastError( ) will return a message like "Could not find the _____ function pointer".
One big struggle that we had - you must choose the right texture type in order for this to work correctly.  The multi-sample, the way you create textures, and the value you pass in to the wgl function to register the surface / texture must all agree.  Originally, we were using GL_RENDERBUFFER as the texture type, which seemed to work just fine until we tried to do stereo.  Once you try to do stereo, it  worked fine on some computers, showed only one eye on other computers, or just didn't work at all.  GL_TEXTURE_2D seems to be the better choice if you are planning on doing stereo.
Here's how you use the code:

Include the render target factory.

#include "GlDxRenderTargetFactory.h"

Use the factory to create a renderer. Note that the parameter passed in does not set the DirectX capabilities to use, but rather the DirectX SDK to use. The difference, for example, is that you can use the DirectX 11 SDK, but force it to only use DirectX 9 capabilities. Also note that the caller is responsible for deleting the object created by the factory.

IGlDxRenderTarget * dxRenderer = GlDxRenderTargetFactory::CreateRenderTarget(GLDX_DIRECTX_SDK_TYPE::DX_SDK_9);

Next, create your window and also your OpenGl rendering context (see NeHe productions for helpful tutorials on how to do this: Once the window has been setup, call initialize on the renderer (making sure to check for errors).

if(dxRenderer->Initialize(window-hWnd) == false)
   ::MessageBoxA(NULL, dxRenderer->GetLastError(), "Error", 0);

In your rendering loop, you can switch to your hearts content between OpenGl and DirectX. In the code below, we're simply clearing to a purple screen.


glClearColor(1.f, 0.f, 1.f, 1.f);


Finally, call flush to flush the graphics from the buffer.