[SDL] Multiple windows hack?

Andrew Straw andrew.straw at adelaide.edu.au
Thu Jul 11 08:29:01 PDT 2002


> Gabriele Greco wrote:
>
> There is an hack I can use to have multiple windows?

I've been poking around in the source, and it looks like the original 
author(s) (Sam?) of the video section have thought about the basic 
issue, becuase the display is wrapped in a variable called "this" which 
is (currently the only) instance of a display structure/object.  So, 
support for multiscreen/multiwindow seems like it would involve grafting 
a modified API for the window/screen open code, and then of course 
writing the platform specific bits for your favorite platforms, but it 
does not look terrible.  And I for one would be very grateful! :)  I'm 
probably not able to devote the time to delving in any deeper.  There's 
another email about multiscreen from last month, I believe.  If you 
don't see why I keep writing on and on about multiscreen when all you 
asked about was multiwindow, it's because I personally equate 
multiscreen with multiwindows with respect to SDL. If you want OpenGL 
acceleration on multiple windows (which is what I use SDL with, and I 
think a lot of others do as well), especially with the possibility those 
windows are on  open on another display, you want to make sure you can 
configure your graphics mode to one that you and your card both like, at 
least if your system allows it.

> There is an hack I can use to have multiple windows?
>
> Obviously every SDL context should be run on a different (and unique) 
> thread.

I'm not positive, but at least with OpenGL you'd want just a single 
rendering thread because a video card is  a state machine, and to save 
all those state variables and switch to another context would be 
expensive, so the best thing would probably be to render your contexts 
in a serial manner.

> Actually I can think only about building a mini SDL with the functions 
> I need and a slightly modified API with multiwin support :)

It's been suggested before (by me for one:), but when I actually looked 
at the code, I thought that it wouldn't be that difficult to do the 
Right Way. Hence my decision not to "hack and destroy".

> The problem I have is that I'd like to be able to run multiple 
> instances of the plugin in the same web page or in different windows 
> but explorer always use the same OCX and not multiple copies of it and 
> so the dataspace is always the same and I cannot run multiple SDL 
> windows. Is there a hack I can use to have multiple windows? Something 
> like to have multiple copies of a DLL and to dinamically swaps function 
> pointers to the SDL API functions to refer to the functions with the 
> correct display/event global variables.

I have a very OpenGL-centric understanding, but I think for the reasons 
I wrote above (OpenGL being a state machine) you'd be better off to do 
it all from a single copy of the library loaded. For non-OpenGL, I don't 
know if SDL gets a lock on low-level system resources.  I wonder what 
happens with two graphics cards? Could the cards each run their own 
instance of the library simultaneously? Hmm... maybe all you need is a 
new card for each window you want to open! :)

Anyhow, good luck!
Andrew





More information about the SDL mailing list