[SDL 1.3] Create Opengl Context without window?

Hi is it possible to create an opengl context in SDL 1.3 without a window?

E.g
Create SDL Window
Get Opengl Context from window
Destroy Window but keep the opengl context?

I need a dummy opengl context around.

I previously kept a dummy window (hidden), however this was not elegant, as the dummy window can be reactivated by the user through the finder bar (OSX) or taskbar etc.

regards

afair, you can use SDL_WINDOW_SHOWN flag to hide/display the SDL window.
or maybe you’re trying to skip window creation completely?
VittorioOn Tue, Feb 7, 2012 at 6:40 AM, mercurio7891 wrote:

Hi is it possible to create an opengl context in SDL 1.3 without a window?

E.g
Create SDL Window
Get Opengl Context from window
Destroy Window but keep the opengl context?

I need a dummy opengl context around.

I previously kept a dummy window (hidden), however this was not elegant, as
the dummy window can be reactivated by the user through the finder bar (OSX)
or taskbar etc.

regards


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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

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.

PatrickOn Wed, Feb 8, 2012 at 3:36 AM, mercurio7891 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
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi, I am trying to use opengl for General purpose computation (GPGPU), on multiple windows.

Thus I was trying to decouple the context from the window as windows can be created and disappear at anytime

Anyway if the context is tied to the window, I was wondering if the opengl context are transferable to other windows? (All windows are rendered on the main thread)

Suppose the scenario below will it work?

e.g:

Code:

Create Window_A;
Create Opengl Context (Context_A) from Window_A;
Create Window_B;
Render Window_A (SDL_GL_MakeCurrent)
Render Window_B (SDL_GL_MakeCurrent)


Sometime later destroy Window_A (SDL_DestroyWindow)
**** Is Context_A still valid after Window_A is destroyed? i.e. can Window_B still continue to use Context_A via SDL_GL_MakeCurrent? ****

regards
[/code]

That’s tricky. I know on Windows you can use one context to render to two
different windows if they have the exact same pixel format, and I’m fairly
certain an analogous situation occurs on X windows (I haven’t explicitly
tried, but two windows with the same X visual probably would work), but I
can’t comment on OS X.

If you’re doing GPGPU, why not give OpenCL a look?On Wed, Feb 8, 2012 at 10:44 AM, mercurio7891 wrote:

**
Hi, I am trying to use opengl for General purpose computation (GPGPU), on
multiple windows.

Thus I was trying to decouple the context from the window as windows can
be created and disappear at anytime

Anyway if the context is tied to the window, I was wondering if the opengl
context are transferable to other windows? (All windows are rendered on the
main thread)

Suppose the scenario below will it work?

e.g:

Code:

Create Window_A;
Create Opengl Context (Context_A) from Window_A;
Create Window_B;
Render Window_A (SDL_GL_MakeCurrent)
Render Window_B (SDL_GL_MakeCurrent)


Sometime later destroy Window_A (SDL_DestroyWindow)
**** Is Context_A still valid after Window_A is destroyed? i.e. can
Window_B still continue to use Context_A via SDL_GL_MakeCurrent? ****

regards
[/code]


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I have no idea if it’s officially supported, but I’m successfully rendering two windows on OS X with a single context. Haven’t tried destroying just the parent window though.

I would second looking in to OpenCL for this, what I’ve seen of it doesn’t look very difficult to implement.–
Wim Looman
@Wim_Looman

On 9/02/2012, at 6:02 AM, Patrick Baggett wrote:

That’s tricky. I know on Windows you can use one context to render to two different windows if they have the exact same pixel format, and I’m fairly certain an analogous situation occurs on X windows (I haven’t explicitly tried, but two windows with the same X visual probably would work), but I can’t comment on OS X.

If you’re doing GPGPU, why not give OpenCL a look?

On Wed, Feb 8, 2012 at 10:44 AM, mercurio7891 wrote:
Hi, I am trying to use opengl for General purpose computation (GPGPU), on multiple windows.

Thus I was trying to decouple the context from the window as windows can be created and disappear at anytime

Anyway if the context is tied to the window, I was wondering if the opengl context are transferable to other windows? (All windows are rendered on the main thread)

Suppose the scenario below will it work?

e.g:

Code:

Create Window_A;
Create Opengl Context (Context_A) from Window_A;
Create Window_B;
Render Window_A (SDL_GL_MakeCurrent)
Render Window_B (SDL_GL_MakeCurrent)


Sometime later destroy Window_A (SDL_DestroyWindow)
**** Is Context_A still valid after Window_A is destroyed? i.e. can Window_B still continue to use Context_A via SDL_GL_MakeCurrent? ****

regards
[/code]


SDL mailing list
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

You can set it up to render to a HBITMAP / X pixmap

http://www.opengl.org/wiki/Platform_specifics:_Windows#PFD_DRAW_TO_BITMAP
http://www.opengl.org/sdk/docs/man/xhtml/glXCreateGLXPixmap.xml------------------------
EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/

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

i would love to give opencl a try. Unfortunately, my old macbook pro does not allow it.

However i too have no idea if it is safe to assume the context remains valid after the initial window is destroyed.

I was womdering if i create my own opengl context using glxCreateGLXPixmap etc, how do I tie it to a SDL opengl context??

regardsfrom my understanding, i think it is true sdl allowing sharing of context if the pixel format are the same.

You want to make a child window and then destroy the parent? I’m pretty
sure it’s universal that a child may not live after the parent dies because
there is no point to it. Thats not to say that the data could not be used
to generate a new parent that mirrors all thte data of that child except
the original relationship to the dead parent. You could even manipulate the
data to emulate the context in a conditional way without an active context
which would be beyond weird. If you said like Im doing this and this
happens I could wrap my head around the issue better.On Wed, Feb 8, 2012 at 7:49 PM, mercurio7891 wrote:

**
i would love to give opencl a try. Unfortunately, my old macbook pro does
not allow it.

from my understanding, i think it is true sdl allowing sharing of context
if the pixel format are the same.

However i too have no idea if it is safe to assume the context remains
valid after the initial window is destroyed.

I was womdering if i create my own opengl context using glxCreateGLXPixmap
etc, how do I tie it to a SDL opengl context??

regards


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Since OpenGL 3.x (or if GLX_ARB_create_context/WGL_ARB_create_context is supported) you can use an OpenGL context without a window resp. drawable by calling glxMakeCurrent with drawable = None, but you still need a window to create the context.

With older OpenGL you have to bind the context to a pixmap or pbuffer, which aren’t supported by SDL, so you have to use the platform-specific functions.

But if you create your context with glx functions anyway, why do you want to tie it to SDL ? Just make it current in your thread using the glx functions and use it.

On Mac, I don’t believe it is required to have a window to create an
OpenGL context. (But I don’t know if SDL can be made to work with this
without modification.)

There are multiple ways to create an OpenGL context on Mac, none of
them actually deal at the window level. NSOpenGLView is the highest
level API which contains a NSOpenGLContext. You can instantiate the
latter yourself if you don’t want to go through the NSOpenGLView
class. Nowhere do these APIs necessarily require you to create an
instance of NSWindow.

At the lowest level, you can also create a CGLContextObh via CGLCreateContext.

Somewhere in between the two is newer alternative offshoot is
CAOpenGLLayer. It deals more directly with CGLContextObj.

In all cases, you may need to declare the *PixelFormat to use
offscreen renderers when creating the context.On 2/15/12, mbentrup <matthias.bentrup at googlemail.com> wrote:

Since OpenGL 3.x (or if GLX_ARB_create_context/WGL_ARB_create_context is
supported) you can use an OpenGL context without a window resp. drawable by
calling glxMakeCurrent with drawable = None, but you still need a window to
create the context.

With older OpenGL you have to bind the context to a pixmap or pbuffer, which
aren’t supported by SDL, so you have to use the platform-specific functions.

But if you create your context with glx functions anyway, why do you want to
tie it to SDL ? Just make it current in your thread using the glx functions
and use it.


Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/