SDL limitations and window management

Hi,

I’ve been using SDL for some time, but now there are some limitations, that
I don’t know how to overcome.

For example, I’d like to create a hided window with an OpenGL context, load
some stuff in the background and once everything is ready, hide the splash
screen and show the main window (and change display mode if necessary).
Something similar is what most comercial games do, since a black window
during a long time doesn’t look very good.

Another issue is that SDL may initialize a software only OpenGL context. In
that case I would like to try with different pixelformat, and if nothing
works just throw an error. On windows you determine if the current gl
context is accelerated by looking into the flags returned by
DescribePixelFormat. However, SDL does not provide how to do that.

I think that there are two ways of solving this:
1.- I can propose some changes in the API, and implement them on win32, and
hoppe they ‘get accepted’ and implemented on the other platforms. (I don’t
have too much experience with other OSs).
2.- Do my own window management and opengl initialization on the platforms I
know, falling back to SDL in the other cases. I would still like to use SDL
input and events, because some important parts of my code depend on them,
and I don’t know if it’s possible to just create the window and let SDL
control it.

Any other ideas? What’s the proper way to go?

Ignacio Casta?o
@Ignacio_Castano_______________________________________________________________
Yahoo! Messenger
Nueva versi?n: Webcam, voz, y mucho m?s ?Gratis!
Desc?rgalo ya desde http://messenger.yahoo.es

AFAIK you can’t have two windows in SDL, and it shouldn’t be changed (how could
you imagine 2 windows on framebuffer or svgalib?).
If you need to draw title screen then do something in background - just don’t
SDL_GL_SwapBuffers() until picture will be done.On Tue, Nov 12, 2002 at 12:41:29AM +0100, Ignacio Casta?o wrote:

For example, I’d like to create a hided window with an OpenGL context, load
some stuff in the background and once everything is ready, hide the splash
screen and show the main window

Jacek Pop?awski wrote:

AFAIK you can’t have two windows in SDL, and it shouldn’t be changed (how
could
you imagine 2 windows on framebuffer or svgalib?).
If you need to draw title screen then do something in background - just
don’t
SDL_GL_SwapBuffers() until picture will be done.

No, that’s not what I meant. I only want one SDL window, but I would like to
create it hided, and show it later. I don’t know of other systems, but in
windows you can create the window without the SW_SHOW flag and when you have
finished the initialization you do:

ShowWindow( hwnd, SW_SHOW );

It would be nice to have a flag in SDL_SetVideoMode to create a hided window,
and two new functions SDL_WM_ShowWindow and SDL_WM_HideWindow.

And why do I want a hided window? Because I’ll be uploading textures,
compiling shaders, etc. during initialization. Ok, this is just matter of
taste, I can load a simple texture, and display it while the other stuff gets
loaded.

But that’s only one of the problems, the main one, is that I cannot query for
OpenGL acceleration in SDL. On windows thats done with the pixelformat flags,
and SDL does not expose them. It would be nice to have a portable way of
determining if OpenGL acceleration is available.

In windows that would be done by checking the pixel format flags, and
checking the glDriver name.

So, here is my proposal:

Add a new SDL_GLattr called:

SDL_GL_DRIVER

that can take the following values:

SDL_GL_DRIVER_SOFTWARE = 0x01
SDL_GL_DRIVER_ICD = 0x02
SDL_GL_DRIVER_MCD = 0x04
SDL_GL_DRIVER_HARDWARE = 0x06
SDL_GL_DRIVER_ANY = 0x07

and by default would be SDL_GL_DRIVER_ANY.

you can change the value before SetVideoMode with SDL_GL_SetAttribute, to
force the existence of an accelerated driver, for example, you set it to
SDL_GL_DRIVER_HARDWARE, and if a software driver is found, then the window is
not shown and SetVideoMode returns an error.

After window creation, you can checkout the type of driver loaded using
SDL_GL_GetAttribute.

As I said, if you find this is usefull I will contribute a patch for win32.

Ignacio Casta?o
@Ignacio_Castano_______________________________________________________________
Yahoo! Messenger
Nueva versi?n: Webcam, voz, y mucho m?s ?Gratis!
Desc?rgalo ya desde http://messenger.yahoo.es

AFAIK you can’t have two windows in SDL, and it shouldn’t be changed
(how could
you imagine 2 windows on framebuffer or svgalib?).

I think it would be great to allow the option of opening more than 1
SDL/OpenGL window and also the ability to position them on multiple
displays. I know some of this sort of functionality can be achieved by
opening a single, display-spanning window, but there are situations
where this will not work or will not be ideal. I gather that this won’t
be happening for SDL 1.2, though.

Several ways of hacking SDL to support multiple windows/screens have
been discussed other the years. I think the eventual interface should
be written from the point of view of a muti-monitor machine, as these
are increasingly common. SDL already reports (in the SDL_VideoInfo
structure) if a window manager is available. If SDL is to support
multiple-monitor systems, the application will need to specify which
display a surface is to be created on. After that is added, then
supporting multiple windows on the same screen is simply a matter of
telling SDL_SetVideoMode() if you’re modifying an existing window
(represented as a SDL_Surface*) or creating a new one… There is
definitely an issue as to what to do on systems without window managers
(ie. framebuffer or svgalib) but this can be handled in one of several
ways: The API can assume that the most recently created surface is
"active" until the application says to make another surface active.
Alternatively, creating a second “window” on a system w/o a window
manager could simply fail (although this seems to go against the SDL
philosophy of “support or emulate” (which I think makes it much more
appealing than DirectX). The third alternative is to actually emulate
windows… (I think this is advisable, but I believe this should
actually be in an external library.) The only three features remaining
are:

1) ability to query how surfaces are oriented relative to each other. 

(Many systems that support multi-monitor configurations have some
internal concept of how the monitors are physically positioned relative
to each other, so that the mouse can traverse multiple monitors in a
predictable fashion… A similar interface could be used to query where
different windows are in a windowing system… Similarly, events to
handle when a window moves, or changes from one monitor to another could
be added…

2) Once surface position is is queryable,  the ability to move windows

is a logical extension…

3) The only thing remaining seems to be the ability to close a window

without shutting down the video subsystem…

Comments? Suggestions?

-LorenOn Wed, 2002-11-13 at 18:58, Andrew Straw wrote:

AFAIK you can’t have two windows in SDL, and it shouldn’t be changed
(how could
you imagine 2 windows on framebuffer or svgalib?).

I think it would be great to allow the option of opening more than 1
SDL/OpenGL window and also the ability to position them on multiple
displays. I know some of this sort of functionality can be achieved by
opening a single, display-spanning window, but there are situations
where this will not work or will not be ideal. I gather that this won’t
be happening for SDL 1.2, though.

No, that’s not what I meant. I only want one SDL window, but I would like to
create it hided, and show it later. I don’t know of other systems, but in
windows you can create the window without the SW_SHOW flag and when you have
finished the initialization you do:

ShowWindow( hwnd, SW_SHOW );

It would be nice to have a flag in SDL_SetVideoMode to create a hided window,
and two new functions SDL_WM_ShowWindow and SDL_WM_HideWindow.

And why do I want a hided window? Because I’ll be uploading textures,
compiling shaders, etc. during initialization. Ok, this is just matter of
taste, I can load a simple texture, and display it while the other stuff gets
loaded.

But that’s only one of the problems, the main one, is that I cannot query for
OpenGL acceleration in SDL. On windows thats done with the pixelformat flags,
and SDL does not expose them. It would be nice to have a portable way of
determining if OpenGL acceleration is available.

In windows that would be done by checking the pixel format flags, and
checking the glDriver name.

So, here is my proposal:

Add a new SDL_GLattr called:

SDL_GL_DRIVER

that can take the following values:

SDL_GL_DRIVER_SOFTWARE = 0x01
SDL_GL_DRIVER_ICD = 0x02
SDL_GL_DRIVER_MCD = 0x04
SDL_GL_DRIVER_HARDWARE = 0x06
SDL_GL_DRIVER_ANY = 0x07

and by default would be SDL_GL_DRIVER_ANY.

you can change the value before SetVideoMode with SDL_GL_SetAttribute, to
force the existence of an accelerated driver, for example, you set it to
SDL_GL_DRIVER_HARDWARE, and if a software driver is found, then the window is
not shown and SetVideoMode returns an error.

After window creation, you can checkout the type of driver loaded using
SDL_GL_GetAttribute.

As I said, if you find this is usefull I will contribute a patch for win32.

Go ahead and write it and redistribute it with your code.
Since it looks like it won’t change the ABI, I’ll consider adding it to
the current SDL 1.2 branch, so go ahead and post a patch here.

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment