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;
}