Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you create OpenGL context without opening a window?

Tags:

opengl

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?

like image 664
Cheery Avatar asked Feb 23 '09 08:02

Cheery


People also ask

How to create an OpenGL context?

Create the Context Before you can use OpenGL, the context you created must be made current. This is done with the wglMakeCurrent function. This takes a DC and the HGLRC context. If there is already a current context, then this function will cause the old context to be replaced with the new.

What is an OpenGL context?

An OpenGL rendering context is a port through which all OpenGL commands pass. Every thread that makes OpenGL calls must have a current rendering context. Rendering contexts link OpenGL to the Windows windowing systems. An application specifies a Windows device context when it creates a rendering context.


2 Answers

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.

like image 163
Dror Helper Avatar answered Nov 02 '22 06:11

Dror Helper


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.

like image 23
ahoffer Avatar answered Nov 02 '22 06:11

ahoffer