32

Occassionally I hit places where I'd want to get an OpenGL framebuffer object, but where I'm not interested about opening a window of any kind.

Is it possible to create an opengl context without attaching it to a window of any kind?

Cheery
  • 24,645
  • 16
  • 59
  • 83

3 Answers3

14

Yes! you can use the desktop window as the window passed to OpenGL- as long as you don't try to display anything on it ;)

Just Call GetDesktopWindow and pass the result as an argument when creating new OpenGL window.

Dror Helper
  • 30,292
  • 15
  • 80
  • 129
  • Does this also work for xorg? When tried it seemed to open the context well, but I didn't try open a framebuffer object and render. – Cheery Feb 23 '09 at 12:50
  • I know it works on DirectX as well but I never tried using this trick with xorg – Dror Helper Feb 23 '09 at 14:05
  • I did a try but GetDesktopWindow() doesn't work for me. Using GetDC(NULL) instead of GetDC(GetDesktopWindow()) works well. – 0xAA55 Aug 08 '21 at 11:08
6

http://www.opengl.org/wiki/Creating_an_OpenGL_Context

According to this Web page, WGL_ARB_create_context can be used to create a context without a window. I have not actually tried it myself. I used freeGLUT to create the context and then rendered off-screen to a framebuffer+renderbuffer. I exit the program without ever calling glutMainLoop. It is klugy, but it works for my purposes.

ahoffer
  • 6,347
  • 4
  • 39
  • 68
  • 2
    In order to retrieve this extension, you need to create OpenGL context using the older 'WGL' extensions, which require a window. –  Aug 02 '16 at 13:41
2

Yes, you can perform off-screen rendering with OpenGL, but the exact way to set it up is dependent on the operating system. The closest you get to an OS independent way would be to use Mesa 3D, but then your off-screen rendering would not be hw accelerated.

Ronny Vindenes
  • 2,361
  • 1
  • 18
  • 15
  • Is the last comment still valid? If I understood correctly, at least on Linux, Mesa is close to proprietary drivers comparing speed. – Adrian Maire Mar 15 '16 at 12:23
  • Sort of. Mesa on linux allows both software and hardware rendering, however the results can be subtly different between the two depending on the renderer and driver and GL commands sent. The Mesa software renderer tends to get similar results across different OSes but may not be necessarily easy to setup on every OS, and like Ronny said, software only Mesa is not hw accelerated with the graphics card GPUs. (although, modern software-only Mesa code has a huge amount of speedups on modern main processor CPUs) http://www.mesa3d.org/faq.html – don bright Sep 13 '16 at 03:51