2

According to the registered here (khronos site):

If the OpenGL context version of <hglrc> is 3.0 or above, and if either the <hdc> parameter of wglMakeCurrent is NULL, or both of the <hDrawDC> and <hReadDC> parameters of wglMakeContextCurrentARB are NULL, then the context is made current, but with no default framebuffer defined. The effects of having no default framebuffer on the GL are defined in Chapter 4 of the OpenGL 3.0 Specification.

Trusting this information I created a device context "off screen" with:

HDC m_hDC = CreateCompatibleDC(NULL);

I configured the Pixels and added to DC with the SetPixelFormat function:

SetPixelFormat(m_hDC, iPixelFormat, &chosenPFD);

Then I created a rendering context:

m_hGLRC = ::wglCreateContextAttribsARB(m_hDC, NULL, &(iAttributes[0]));

So far so good, it works. Now it's time to make the context current.

First I delete the DC (I will not need it anymore) and call the wglMakeCurrent with a NULL dc parameter:

DeleteDC(m_hDC);
bool ret = wglMakeCurrent(NULL, m_hGLRC);

That did not work. The ret is false and I get this error:

Win32 Error# (6): ERROR_INVALID_HANDLE

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Mano-Wii
  • 592
  • 5
  • 19
  • 1
    Error code 6 is `ERROR_INVALID_HANDLE`. Nothing in the [documentation](https://msdn.microsoft.com/en-us/library/dd374387.aspx) states, that passing `NULL` as the *hdc* parameter were allowed. – IInspectable Feb 11 '18 at 07:10
  • @IInspectable, thanks for describing the error, edited :). Although the msdn documentation does not state about hdc NULL, the khronos documentation mentions :\ – Mano-Wii Feb 11 '18 at 14:27
  • Can I ask if your window is CS_OWNDC? – Robinson Feb 11 '18 at 14:44
  • @Robinson: There is no window. – IInspectable Feb 11 '18 at 14:45
  • I don't know, whether Microsoft's implementation supports this use case. If it does, you cannot simply rip the DC from underneath it, though. You have to render *somewhere* after all. You'd probably also have to select a bitmap of sufficient size and with compatible pixel format into the target DC to serve as the backing store. – IInspectable Feb 11 '18 at 15:08
  • @Mano-Wii You need a window to create an OpenGL context (at least a hidden window). See [Creating OpenGL context without window](https://stackoverflow.com/questions/12482166/creating-opengl-context-without-window) – Rabbid76 Feb 11 '18 at 15:10
  • @Rabbid76, thanks for the info. I'm still confused about the difference between DC and window. Since OpenGL works on framebuffers (not windows) I wanted to avoid then. And it would even be possible if it were not for that DC :\ – Mano-Wii Feb 11 '18 at 17:52
  • @Mano-Wii Please belive me, it is not possible to cretea an OpenGL context (above 1.0) with out an window. You need a `HWND hwnd`, `HDC hdc = ::GetWindowDC( hwnd );` and `::wglCreateContext( hdc )`. See [Render image using OpenGL in win32 window](https://stackoverflow.com/questions/47809267/render-image-using-opengl-in-win32-window/47821419#47821419) – Rabbid76 Feb 11 '18 at 17:58
  • @Rabbid76, do I really need to get the DC from a window (`::GetWindowDC( hwnd );`)?? If I use the dc from `CreateCompatibleDC(NULL);`, the context works!! I'd rather store this dc somewhere than store a window. – Mano-Wii Feb 11 '18 at 18:19
  • 1
    @Mano-Wii No, becaus if you use a memory context, the you won't get an OpenGL context above OpenGL version 1.0. – Rabbid76 Feb 11 '18 at 18:26
  • Is the OpenGL context version of 3.0 or above? – user253751 Feb 11 '18 at 22:40
  • yes, OpenGL 3.3 – Mano-Wii Feb 11 '18 at 23:28
  • @Rabbid76, It seems that the limitation with context above 1.0 only occurs with Intel cards. In my case it worked because I used AMD. Anyway I created the DC with pbuffer. But I did not want to have to create a DC :( (NULL would be perfect) – Mano-Wii Feb 14 '18 at 21:47

0 Answers0