Multiple windows -> multiple shaders?

I have a window that is successfully being rendered by opengl. I now want a second window rendered the same way. The second window is build exactly like the first one, same parameters for createwindow, same PIXELFORMATDESCRIPTOR, same shader, same drawing function.
Supposebly you can use wglMakeCurrent (and maybe glUseProgram) to switch to the second window, however, it does not work.
The first window renders, the second does not.

I suspect the shader is somehow connected to the window, because that is the only difference.
Also glCreateShader fails if there is no current window.

Do I need to create a new shader for every window?
Can I not just use one shader program for multiple windows?

Any help is appreciated.

On Windows use wglShareLists() to share some resources (display lists, texture objects, shaders) between multiple OpenGL contexts.

http://msdn.microsoft.com/en-us/library/dd374390(VS.85).aspx

PS: stop using the word “window”, use the word “OpenGL context”.
For example, wglMakeCurrent() set the current “OpenGL context” for the calling thread.

Any OpenGL function needs to be called with an actuall current OpenGL context, it is normal for example that glCreateShader() fails with no current OpenGL context.

First: Thanks, with wglShareLists the other windows rendered correctly.

Second:
With window I meant device context.
I tried using wglMakeCurrent with a valid OpenGL context but without a device context, and glCreateShader still fails.
I imagine that a device context is needed to create an OpenGL context. I still don’t understand why glCreateShader needs a device context (because it has an OpenGL context) and what an OpenGL context actually is. Anyways, it works, thanks.

I still don’t understand why glCreateShader needs a device context (because it has an OpenGL context) and what an OpenGL context actually is.

It’s a chain of requirements. glCreateShader is an OpenGL functions. OpenGL functions need an OpenGL rendering context to be current in the current thread. An OpenGL render context needs a device context, which is used by Windows to denote a particular window’s rendering surface and the resources used by that window for rendering. Therefore, all GL functions need a device context.

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