Multiple monitors

Hi

I’m sure this has been asked before, but is there a way to setup multiple monitors in SDL, and not just multiple windows?

I am working on system where I have no control over the config of the hardware, so I can’t just extend the desktop and place the window accordingly. I need to be able to setup two windows, running full screen.

If SDL can’t do this, can anyone suggest a method as to how I can do it? Can I setup the devices with directx and then render to the screen with SDL? I would rather not have to learn to use directx if at all possible…I like SDL too much :slight_smile:

Thanks in advance,

Ed

Alright, so, on a bit more investigation, it looks like it might already work. I have some code which sets up multiple displays and gets the supported display modes.

That’s all fine, and gives me the display modes for both monitors, but I can’t seem to figure out how to “put” a window onto the 2nd display. Has anyone tried?

Thanks
Ed

Can you move one window over before making it fullscreen? I’m not sure how
your OS handles it, but it might just need one window to be beyond the
bounds of the first display (e.g. x=1000 on a 800x600 display).

Jonny DOn Tue, Oct 5, 2010 at 8:40 AM, ebyard <e_byard at yahoo.co.uk> wrote:

Alright, so, on a bit more investigation, it looks like it might already
work. I have some code which sets up multiple displays and gets the
supported display modes.

That’s all fine, and gives me the display modes for both monitors, but I
can’t seem to figure out how to “put” a window onto the 2nd display. Has
anyone tried?

Thanks
Ed


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

Hi

The target system is actually running Windows XP Embedded, I think (!).

I have no control over the target hardware whatsoever. It’s like a kiosk system. I can change the screen resolution and that’s it, then when my app finishes it must reset back to the original resolution before the system’s kernel takes over again.

Basically, all I need to do is to be able to initialise two fullscreen windows, one on each monitor.

Thanks
Ed

Can you e_byard post your code??? I want to add a new feature (multiple monitors support) in my game a your code could be a good start.

Thanks in advance.
Jorge Vega
El 05/10/2010, a las 15:40, Jonathan Dearborn escribi?:> Can you move one window over before making it fullscreen? I’m not sure how your OS handles it, but it might just need one window to be beyond the bounds of the first display (e.g. x=1000 on a 800x600 display).

Jonny D

On Tue, Oct 5, 2010 at 8:40 AM, ebyard <e_byard at yahoo.co.uk> wrote:
Alright, so, on a bit more investigation, it looks like it might already work. I have some code which sets up multiple displays and gets the supported display modes.

That’s all fine, and gives me the display modes for both monitors, but I can’t seem to figure out how to “put” a window onto the 2nd display. Has anyone tried?

Thanks
Ed


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

Sure, I’ll post the code when I get multi monitors working properly.

SDL 1.3 looks great it just needs a LOT more documentation, as I said, I’m happy to write as much as I can but I’m a novice at this stuff, really…

OK, so, it doesn’t actually work after all.

The problem is, with multiple devices (monitors), SDL doesn’t seem to recognise each device independantly.

Here’s the code. It should open 2 windows, 1 on each monitor, centered, and display a graphic (just use any old 1024x768 png for now). On my system it doesn’t display the 2nd window at all (though I can see it from the Windows 7 taskbar mouse-over) and if I remove the SDL_WINDOWPOS_CENTERED then it’ll display waaay off the right of my 2nd monitor.

I have no idea what is going on but if others can test, I’d be grateful.

Code:

#include “SDL.h”
#include “SDL_image.h”
#include <stdio.h>

using namespace System;
using namespace System::Text;
using namespace System::IO;

int wmain(int argc, char *argv[])
{
int numdisplays, defaultdisplay, i;
int nummodes, j;
int * scalemode;

SDL_Surface *testImg;
SDL_Rect srcRect,dstRect;
SDL_Texture *testTxu;

SDL_DisplayMode mode;

if (SDL_Init(SDL_INIT_VIDEO) != 0) 
{
	printf("Error initializing SDL: ");
	return 1;
}

IMG_Init(IMG_INIT_PNG);
testImg = IMG_Load("test.png");
if (testImg == NULL)
{
	printf("Error loading file %s",IMG_GetError());
	return 1;
}
SDL_DisplayFormat(testImg);

atexit(SDL_Quit);

SDL_SelectVideoDisplay(0);
SDL_Window *window1 = SDL_CreateWindow("Window 1",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,1024,768,SDL_WINDOW_SHOWN|SDL_WINDOW_MAXIMIZED);
SDL_CreateRenderer(window1,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_SINGLEBUFFER|SDL_RENDERER_ACCELERATED);
SDL_SelectRenderer(window1);

testTxu = SDL_CreateTextureFromSurface(0,testImg);
SDL_RenderClear(); /* clear the screen */
SDL_RenderCopy(testTxu,NULL,NULL); /* render the area of the texture defined by textureRegion (use NULL for the full thing)

to the area of the screen defined by screenRegion (use NULL for the full screen) NOTE: the texture API performs scaling automatically. Make sure you want the texture to be stretched to fit the specified region!/
SDL_RenderPresent(); /
update the screen */

SDL_SelectVideoDisplay(1);
SDL_Window *window2 = SDL_CreateWindow("Window 2",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,1024,768,SDL_WINDOW_SHOWN|SDL_WINDOW_MAXIMIZED);

SDL_CreateRenderer(window2,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_SINGLEBUFFER|SDL_RENDERER_ACCELERATED);
SDL_SelectRenderer(window2);

testTxu = SDL_CreateTextureFromSurface(0,testImg);
SDL_RenderClear(); /* clear the screen */
SDL_RenderCopy(testTxu,NULL,NULL); /* render the area of the texture defined by textureRegion (use NULL for the full thing)

to the area of the screen defined by screenRegion (use NULL for the full screen) NOTE: the texture API performs scaling automatically. Make sure you want the texture to be stretched to fit the specified region!/
SDL_RenderPresent(); /
update the screen */

numdisplays = SDL_GetNumVideoDisplays();
defaultdisplay = SDL_GetCurrentVideoDisplay();
printf("Currently using display %d.\n", defaultdisplay);

for (i = 0; i < numdisplays; ++i) 
{
	printf("\nEnumerating modes for display %d\n", i);
	nummodes = SDL_GetNumDisplayModes();
	for (j = 0; j < nummodes; ++j) 
	{
		SDL_GetDisplayMode(j, &mode);
		printf("  Mode %d:  %dx%d %dHz %d bpp\n", j, mode.w, mode.h, mode.refresh_rate, SDL_BITSPERPIXEL(mode.format));
	}
	printf("  %d modes.\n", nummodes);
}
SDL_FreeSurface(testImg);

IMG_Quit();
SDL_SelectVideoDisplay(defaultdisplay);
SDL_DestroyWindow(window1);
SDL_DestroyWindow(window2);
return 0;

}

Update: Passing a negative window X position moves the window a bit further left on the 2nd monitor (which is physically positioned to the right of my 1st monitor) but using anything more than minus half the screen width results in the window being positioned 2/3rds on the 1st monitor and the remaining 1/3 on the 2nd monitor.

Confused? Me too. :frowning: