wglCreateContext twice for the same window?

Hi folks,
I’ve got an OpenGL visualization plugin for Windows Media Player (and other players). The problem is that when the visualization is started, stopped, and then started again, wglCreateContext fails the second time. Because the code is a plugin, and not its own program, I have to create an OpenGL context in whatever window it gives me – I cannot apply the obvious solution of creating a new window.

Creating a child window is an option, but one that would require a great deal of code to properly handle events and other issues, so I would prefer not to go that route.

Has anybody come across this problem? Is there any thing I can do to get a new OpenGL context working in this window?


  • jon

Well, you could create the context only once and store it’s id somewhere… Actually, you can create more then one context, but you have to delete the previous context before. What you cannot do more then once is setting the pixel format of the window. My approach would be: On start: check the pixel format, if it is wrong one, change it, otherwise leave it. Create the context + do your stuff. On stop, delete the context.

Thanks for your reply.

The problem with hanging on to the same OpenGL context is that the visualization plugin is fully destroyed when the visualization stops (or switches to another plugin). This means that we have to create a new context, and for some unknown reason, it is failing the second time around.

  • jon


maybe your problem is not related to wglCreateContext, but to SetPixelFormat()

MSDN states:

An application can only set the pixel format of a window one time. Once a window’s pixel format is set, it cannot be changed.

Maybe you´re allowed to create serveral contexts for the same window, as long as you don´t call SetPixelFormat a second time…

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