Can you create OpenGL context without opening a window?
Asked Answered
U

3

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?

Uhland answered 23/2, 2009 at 8:29 Comment(0)
G
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.

Glyptodont answered 23/2, 2009 at 8:57 Comment(3)
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.Uhland
I know it works on DirectX as well but I never tried using this trick with xorgGlyptodont
I did a try but GetDesktopWindow() doesn't work for me. Using GetDC(NULL) instead of GetDC(GetDesktopWindow()) works well.Eunaeunice
H
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.

Hypermetropia answered 24/8, 2011 at 15:11 Comment(1)
In order to retrieve this extension, you need to create OpenGL context using the older 'WGL' extensions, which require a window.Unclassified
R
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.

Roseannaroseanne answered 23/2, 2009 at 8:57 Comment(2)
Is the last comment still valid? If I understood correctly, at least on Linux, Mesa is close to proprietary drivers comparing speed.Puleo
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) mesa3d.org/faq.htmlEqui

© 2022 - 2024 — McMap. All rights reserved.