Tuesday, 10 September 2013

Multiple displays in SDL2

Multiple displays in SDL2

I am writing a program that displays an animation that is dependent on the
size of the display. In order to get this to work with multiple displays,
I have an array of display_data objects:
struct display_data
{
SDL_Rect bounds;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;
//...
};
and initialize these for each display:
int numdisplays = SDL_GetNumVideoDisplays();
for( int i = 0 ; i < numdisplays ; ++i )
{
SDL_GetDisplayBounds( i, &( screens[ i ].bounds ) );
screens[ i ].window
= SDL_CreateWindow( "Display", screens[ i ].bounds.x,
screens[ i ].bounds.y, screens[ i ].bounds.w,
screens[ i ].bounds.h, SDL_WINDOW_FULLSCREEN );
screens[ i ].renderer = SDL_CreateRenderer( screens[ i ].window, -1, 0 );
SDL_SetRenderDrawColor( screens[ i ].renderer, 0, 0, 0, 255 );
SDL_RenderClear( screens[ i ].renderer );
SDL_RenderPresent( screens[ i ].renderer );
screens[ i ].texture = SDL_CreateTexture( screens[ i ].renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
screens[ i ].bounds.w,
screens[ i ].bounds.h );
//...
}
This works fine as long as my mouse cursor is in the primary display, but
if I start the program with the cursor in the secondary display, it will
draw both windows in the secondary display, resulting in only the second
window being visible. This behavior seems to depend only on the location
of the cursor and not the terminal window from which I run the program.
I have verified that the same display numbers and bounds are found
regardless of the cursor location, so I am perplexed by the variation in
the program behavior. Is this the intended behavior of SDL2, or a bug? In
either case, could anyone suggest a workaround?
I am using XFCE4 on Debian Sid, in case that makes a difference. I have
not had the chance to test this on any other systems or desktop
environments, or with more than 2 monitors.

No comments:

Post a Comment