PIXELFORMATDESCRIPTOR pfd = { };
HDC hDC = CreateDC(TEXT("Display"),NULL,NULL,NULL);
int ipf = ChoosePixelFormat(hDC,&pfd);
SetPixelFormat(hDC,ipf,&pfd);
HGLRC hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC,hRC);
But the following works with the same hRC:
wglMakeCurrent(hSomeWindowDC,hRC);
The above part is part of the OpenGL 3.0+ initialization system for Windows.
I am trying to avoid creating a dummy window for aesthetics.
I had never used CreateDC before, so maybe I missed something.
edit: hSomeWindowDC will point to a DC window with the corresponding pixel format.
Additional Information:
I want to create a window-independent rendering context for OpenGL.
Due to the selected answer, it seems that I need to use a dummy window (not a very big deal, just a pen to get around anyway).
Why I would like to do this: since you can use the same rendering context for multiple windows with the same pixel format in the same stream, you can create a rendering context (in fact, only a container for gl-related objects) that doesn't depends on the specific window. Thus, you can create a clear separation between the graphics and the initialization of the user interface.
The purpose of the context initially was not to render (although I believe that it would be possible to convert it to textures). If someone wanted to change the contents of the buffer in a specific context, the desired context object would just have to be made current (since it carries a dummy window in it, this is possible). Rendering to a window is simple: as follows from the above, the DC window only needs to have the same pixel format. Just create a rendering context and current DC current and render.
Please note that at the time of writing this idea, this idea is still in testing. I will update this post if this is a change (or if I remember: P).
source
share