Trouble with multi-window using single context and render to texture

Sorry for the long title but I couldn’t find a shorter explicit one…

I am currently implementing multi-window into my C++ game engine.
At the moment, I’m doing this with one context and several windows to swap between.

This is how I did it so far:


  • Create main context with a dummy, invisible window (HWND)
  • Create one or more visible windows
  • Set an OpenGL-compatible pixel format on those windows


  • Before rendering on a window, call wglMakeCurrent(hdcFromTheWindow, context)
  • Render (OpenGL calls)
  • After rendering everything, call SwapBuffer on every window

My first test only targets one window, but even then I don’t see anything, the screen stays black :frowning:
If I resize the window, I see the clear color appear, but nothing more.

However, if I bypass post-processing effects (working with render to textures) during execution with a shortcut, I see my animated scene Oo
Once I re-enable effects, I see two static frames flickering rapidly: one with the effects, the other without. Both don’t animate.

My application worked perfectly fine before I introduced this multi-window technique, and I get no errors so far…
I also tried with shared contexts, but got the same weird result.

So… I’m wondering, do I missed something about render to textures?

Note: I’m using raw win32 and OpenGL with Glew, no other libraries involved.

So… I’m wondering, do I missed something about render to textures?

It’s kind of hard to say, since all you’ve told us is that you are rendering to textures. There’s nothing about that concept that would necessarily cause the effect you describe. So it’s rather likely that you have a bug somewhere in your application.

Well… it looks like the window’s backbuffer is never updated when I use post-processing, hence the flickering frames… I stepped several times in my code but can’t find why. I never call wglMakeCurrent on something else than the unique window I have…

If your code is doing what you describe that it is, then it ought to work. But since it’s not working, there is clearly a discrepancy between what you intended your code to do what your code is actually doing.

You say that the problem still manifests when you only use one window. So, start removing parts of your code. This post-processsing that you’re doing? Comment out the actual rendering operation, but leave the FBO part there (you are using FBOs to do render-to-texture, right? You’re not using ARB_render_texture and PBuffers, are you?). Reduce all of your rendering operations to just framebuffer clears. Boil everything down to the absolute minimum needed to repeat the problem.

Do this in stages. At some point, as you comment out some segment of code, you may find that it works. Well, there’s your bug.

If you get all the way to the end, where you’re just clearing buffers and doing buffer blits or whatever, does the problem still happen? If so, odds are good that there’s an FBO gaffe somewhere in your code. Maybe you didn’t bind the default framebuffer after executing some FBO operation. But since your code will be very simple at that point, it shouldn’t be hard to find the problem.

Ok, I found the issue. Silly me. I didn’t disabled the depth test before processing the effects…
Now if I glDisable(GL_DEPTH_TEST) before drawing the overlay quads, I see the scene with the effect correctly applied.

However, I still don’t understand why it happened only after enabling multi-windows, my rendering code didn’t changed… or is it the backend?
This is not my definitive rendering pipeline anyways.

Thank you for your answers :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.