Hi,
my application shell be able to deal with a one or two monitor setup with 1920x1080 pixel each. I could not find any working example. So my test code is:
int main(int argc, char* argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
int numdisplays = SDL_GetNumVideoDisplays();
std::vector< window_data > screens(numdisplays);
for (int i = 0; i < numdisplays; ++i)
{
SDL_GetDisplayBounds(i, &(screens[i].bounds));
std::cout << "window # " << i << " : x = " << screens[i].bounds.x
<< " y = " << screens[i].bounds.y
<< " w = " << screens[i].bounds.w
<< " h = " << screens[i].bounds.h << std::endl;
}
SDL_Window* windows[2];
SDL_GLContext contexts[2];
for (int i = 0; i != sizeof(windows) / sizeof(windows[0]); ++i)
{
char title[32];
snprintf(title, sizeof(title), “window%d”, i);
int w = 1920;
int h = 1080;
int pos = 1920 * i;
std::cout << "creating window " << w << “x” << h << " @ " << pos << “, 0” << std::endl;
windows[i] = SDL_CreateWindow(title, pos, 0, w, h, (SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS));
if (!windows[i])
{
fprintf(stderr, “SDL_CreateWindow error: %s\n”, SDL_GetError());
return 1;
}
contexts[i] = SDL_GL_CreateContext(windows[i]);
if (!contexts[i])
{
fprintf(stderr, “SDL_GL_CreateContext error: %s\n”, SDL_GetError());
return 1;
}
}
int running = 1;
do
{
SDL_Event ev;
while (SDL_PollEvent(&ev)) {
if (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_q)
{
running = 0;
break;
}
}
SDL_GL_MakeCurrent(windows[0], contexts[0]);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(windows[0]);
SDL_GL_MakeCurrent(windows[1], contexts[1]);
glClearColor(0, 1, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(windows[1]);
}while(1 == running);
SDL_Delay(3000);
SDL_Quit();
return 0;
}
The output on the console is:
xcb_connection_has_error() returned true
window # 0 : x = 0 y = 0 w = 1920 h = 1080
window # 1 : x = 1920 y = 0 w = 1920 h = 1080
creating window 1920x1080 @ 0, 0
creating window 1920x1080 @ 1920, 0
It is running on a raspberry pi 5 with the latest OS provided by the raspberry pi foundation.
I can see the both windows are rendered on the first montior, so it is flickering between green and red.
Did I miss anything? Is there any example which I couldn’t find and could try?
I also tried to use only one windows with the doubled width, but that does not work, either. In that case the window is rendered on the second monitor and the first monitor does not change any pixel.
Best regards,
MIchael