Problem with CreateDC and wglMakeCurrent



PIXELFORMATDESCRIPTOR pfd = { /* otherwise fine for a window with 32-bit color */ };

HDC hDC = CreateDC(TEXT("Display"),NULL,NULL,NULL); // always OK

int ipf = ChoosePixelFormat(hDC,&pfd); // always OK

SetPixelFormat(hDC,ipf,&pfd); // always OK

HGLRC hRC = wglCreateContext(hDC); // always OK

wglMakeCurrent(hDC,hRC); // ! read error: 0xbaadf039 (debug, obviously)

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).

+3
source share
2 answers

15 , . DC CreateDC() . , , . DC. GetDC().

+3

OpenGL 3+ . RC , DC . OpenGL wiki : OpenGL 3.1 (++/Win)

+1

Source: https://habr.com/ru/post/1759991/


All Articles