rendering to multiple windows

I’m trying to render to multiple windows. Each window has its own rendering context which is set before any rendering operations are done on the individual window.

This works fine on my desktop. When I tried running it on my laptop, I found that when I opened the second window, the rendering in the first window went crazy (I know not very specific, hard to describe whats happening).

Anyway, just wanted to ask here and see if there are any specific things to keep in mind when rendering to multiple windows, aside from the obvious one of making a separate context and setting each window’s context before rendering, which I’m already doing.

well, no sooner did I post than I found the problem :slight_smile:

I was using a class for 2D text rendering which loaded fonts and created textures. These were cached. Problem is, the cache was used from both windows and both contexts. So it was trying to use a texture from one context in another.

The cache needs to be on a per-context basis.

another thing to keep in mind if you’re using multiple rendering contexts. if you’re using HW accelerated GL, you can’t share resources (display lists, textures) between rendering contexts, so each context needs its own. but, when you do your cleanup for a context (deleting display lists, textures, etc) that context must be active while you’re doing this.

  • set context active
  • delete resources
  • set no active context
  • delete context

If you’re not careful about the order you can end up freeing resources (or trying to) from the wrong context.

That is a completely false statement. How did you get that idea?

I’m trying to render to multiple windows. Each window has its own rendering context which is set before any rendering operations are done on the individual window.

My suggestion to this is: spare yourself the hassle and just use one rendering context for all windows. In Windows’ terms this means using one HGLRC for all your HDC’s.

See wglShareLists.

sorry for the confusion, I think I spoke too quickly there and without enough precision.

We used to do SW rendering only. We used wglShareLists and it worked well. We could share resources between the screen context and the printer context and an offscreen bitmap context as examples.

We then switched to HW accelerated rendering for the on-screen display. When we did this, we found that sharing resources between the hardware accelerated context for the screen with the context for the printer, for example, didn’t work.

From the MSDN docs for wglShareLists:

… However, not all rendering contexts in a process can share display lists. Rendering contexts can share display lists only if they use the same implementation of OpenGL functions. All client rendering contexts of a given pixel format can always share display lists …

So because of this, we moved from just sharing everything to using per-context storage so that we could more generally use multiple contexts.

I believe you’re correct in that, in this case, since both contexts are the same implementation (both on screen HW accelerated rendering) we could probably use wglShareLists and it would work here.

My point was just that using the resources across contexts was what was causing the problem (as you pointed out probably because we’re not calling wglShareLists).

So calling wglShareLists would be one solution for these two contexts, or using a single context for screen rendering.

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