I have main render loop in which initial drawing is done via OpenGL to an SDL window, and after that the same window handle is passed to a Direct3D device, which does subsequent rendering.

Once I execute the program it will initially draw the OpenGL scene, and then do Direct3D drawing but that latter drawing overwrites the OpenGL work.

What I want to see is both drawings in parallel. How can I accomplish that?

  • \$\begingroup\$ by overwrites do you mean that it clears the window before drawing? Do you ever see the openGL drawing on the screen? \$\endgroup\$
    – Will
    Jun 25, 2013 at 11:32
  • \$\begingroup\$ Dismissing whether this is possible or useful, I just have one question: Why? \$\endgroup\$ Jul 1, 2015 at 7:59
  • \$\begingroup\$ As for why? It's 2022 and I'm considering using OpenGL (because I'm familiar with it and really like it), but I also want excellent font rendering at small font sizes from Microsoft's DirectWrite. So far, the only way I've got this working easily is to Render OpenGL first, then rendering fonts using DirectWrite to a GDI+ render target (ID2D1DCRenderTarget). \$\endgroup\$ Aug 20, 2022 at 9:30

3 Answers 3


You cannot do this directly. Both OpenGL and Direct3D operate under the assumption that they are the only things writing to the window.

Furthermore, most of their actual rendering is done in in-memory back buffers and not directly onto the presentation window. It's only once all rendering commands are complete for a particular frame that the back buffer contents is transferred, wholesale, to the front buffer (the presentation window). This transfer is done without regard to what currently exists in that front buffer, and so D3D and GL are totally ignorant of the render results of the other.

There are two ways to achieve what you want, and you can choose between them based on whether or not you want the respective scenes to ever overlap.

In the simple case, where you want only the D3D stuff on the left half of the screen and the OpenGL stuff on the right (for example), you can simply adjust the viewport of both APIs accordingly (using glViewport in OpenGL or RSSetViewports in D3D).

However, if you want the scenes to potentially overlap (as it sort of sounds like you do), you have to instead render your scenes to textures in both APIs (potentially outdated OpenGL example, D3D example). Then you'll need to recover the bits of those textures manually and composite them into a final scene.

You can do this composition and final presentation via a third graphics API (likely GDI), if you wish, but that would probably be unpleasantly inefficient. Instead, I would suggest you do the final composition with D3D or GL itself again. You can pick either, but for the sake of demonstration I'll assume you prefer GL.

That means you will, every frame:

  • perform your OpenGL rendering into a texture
  • perform your D3D rendering into a different texture
  • copy the contents of the D3D texture into CPU memory and from there into GPU memory of a second OpenGL texture.
  • render a fullscreen quad in OpenGL using both your OpenGL textures and a shader or with appropriate blend mode settings enabled to handle composition however you'd like

You can also use the OpenGL Extensions WGL_NV_DX_interop and WGL_NV_DX_interop2

The first one is well supported by Nvidia and AMD and even Intel chips but works only with D3D9 objects. If you want to use DXGI (DirectX 10 and 11) you need to use the second one which only works with Nvidia and some AMD GPUs.

By using these extensions you can render to a surface or texture as Josh suggested, but you don't need to perform the expensive GPU -> CPU -> GPU copies that would slow down your program substantially.


I think I will use ANGLE to convert opengl calls to DirectX. The transferring of framebuffer to the RAM and then construct a backbuffer in DirectX from it, is time-consuming involving DMA and releasing resource from Opengl to hand over the gpu to DirectX. I am trying to use ANGLE and will update my answer when I know exactly how

  • \$\begingroup\$ This doesn't yet appear to present a completer answer to the question. I'd recommend waiting until you've sorted out the details before posting an answer (after all, this question has lasted 4 years, it will wait for you). If you need help sorting this out, feel free to post a new question instead. \$\endgroup\$
    – DMGregory
    Nov 20, 2017 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .