[SDL] [SDL 1.3] Create Opengl Context without window?

Forest Hale havoc at ghdigital.com
Wed Feb 8 16:00:05 PST 2012


Actually a GL context is independent of the windowing system, but a Render context is indeed tied to a Window, or a pixelbuffer of some form (wgl has an extension for creating these offscreen buffers
independently of windows, similar in glX and others).

A GL context itself is more or less a state tracker for a thread, and the wglMakeCurrent and glXMakeCurrent and similar functions manipulate which Render context is used by this thread's GL context.

The above is my understanding, I haven't dug deeply into this matter.

On 02/08/2012 08:14 AM, Patrick Baggett wrote:
> The way OpenGL is defined, there are interactions with the window system, be it X Windows / Quartz / Windows. It doesn't make sense to create a GL context without a window because a GL context has to
> be able to allow the user to query the number of color bits / depth bits / size of the viewport, etc. The system has to be able to determine by the capabilities of the card and the request format
> whether it can allow this or not. For example, let's say you had 8MB of video memory, and wanted to create a 1920x1080 window in 32 bit color with 24 bit z buffer / 8 bit stencil. That's 64 bits per
> pixel x 2073600 pixels = 16588800 bytes of VRAM, not including the backbuffer, or just under 16MB. Clearly, this would not be supported. However, make it a 100x100 window, and then you're using
> a measly 78KB of VRAM -- all is good. If you failed to create a GL context for the 1920x1080 window, would you say "32 bit color isn't supported by the hardware"? -- No, because it isn't that the
> hardware can't do it, it's that the combinations of options makes it impossible.
> 
> Even if you had infinite VRAM, an OpenGL context has to render TO something. The closest thing you can do is render of an off-screen surface, but even then, you are rendering TO somewhere.
> Additionally, rendering to an offscreen surface can have different properties than rendering to a window. It doesn't make sense to initialize OpenGL and have nowhere to render. If you could, then what
> would calls like glReadPixels() do? glGetIntegerv(GL_VIEWPORT, ...)? Crash? The OpenGL spec is designed to remove the ambiguity of a situation where there isn't anywhere to render to.
> 
> I don't know what you're trying to do, but if it is detect the user's hardware or something, then make a window, don't show it, query the hardware, then close the window/GL context and be done with it.
> 
> Patrick
> 
> 
> On Wed, Feb 8, 2012 at 3:36 AM, mercurio7891 <jianann87 at gmail.com <mailto:jianann87 at gmail.com>> wrote:
> 
>     __
>     hi, yup I was thinking of not creating the window. Or perhaps create the window and then destroy it after acquiring the opengl context.
> 
>     Setting the hide flag was not good in os x, a hidden window can easily be redisplayed by user from the window menu in the finder bar.
> 
>     regards
> 
>     _______________________________________________
>     SDL mailing list
>     SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
>     http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
> 
> 
> 
> 
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-- 
LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier




More information about the SDL mailing list