Hello! I’ve been messing around with trying to get SDL3 to render on both the top and bottom screen, but I can’t find out how to get it to render on even just the bottom screen.
Looking at the video driver, it looks like it is possible, and looks like I should just be able to create a top and bottom screen using
mTopWindow = SDL_CreateWindow("Top Screen", GSP_SCREEN_HEIGHT_TOP, GSP_SCREEN_WIDTH, 0);
mBottomWindow = SDL_CreateWindow("Bottom Screen", GSP_SCREEN_HEIGHT_BOTTOM, GSP_SCREEN_WIDTH, 0);
(Error checking and other fluff removed)
However, no matter what I try, it doesn’t want to work. I’ve tried moving the window positions, taking them out of fullscreen, trying to set the displayID of the window, etc.
Does anyone know what I am doing wrong here, or how to properly create a top and bottom screen window, or if I should I even be making two windows for this?
Ideally, I’d like to render to both the left and right upper screen as well (Stereoscopic).
Thanks!
For anyone reading this looking for an answer, I solved the first part:
The trick is to create the window with properties, not setting properties after the fact. Here is example code:
int num_displays;
SDL_DisplayID *displays = SDL_GetDisplays(&num_displays);
for (int i = 0; i < num_displays; i++) {
SDL_Rect rect;
if (!SDL_GetDisplayBounds(displays[i], &rect))
continue;
const char *name = SDL_GetDisplayName(displays[i]);
SDL_Window **targetWindow = nullptr;
SDL_Renderer **targetRenderer = nullptr;
if (strcmp(name, "N3DS top screen") == 0)
{
targetWindow = &mTopWindow;
targetRenderer = &mTopRenderer;
}
else if (strcmp(name, "N3DS bottom screen") == 0)
{
targetWindow = &mBottomWindow;
targetRenderer = &mBottomRenderer;
}
else
continue;
if (targetWindow && targetRenderer)
{
SDL_PropertiesID props = SDL_CreateProperties();
if (!props)
throw std::runtime_error("Failed to create screen properties: " + std::string(SDL_GetError()));
// Set properties
SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, name);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, rect.x);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, rect.y);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, rect.w);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, rect.h);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_FULLSCREEN_BOOLEAN, true);
*targetWindow = SDL_CreateWindowWithProperties(props);
if (!*targetWindow)
throw std::runtime_error("Failed to create window: " + std::string(SDL_GetError()));
*targetRenderer = SDL_CreateRenderer(*targetWindow, nullptr);
if (!*targetRenderer)
throw std::runtime_error("Failed to create renderer: " + std::string(SDL_GetError()));
}
}
SDL_free(displays);
Still haven’t figured out how to do stereoscopy yet. I’m not seeing anything in the code that says it is supported, I might have to make a patch and see if I can get that submitted.
Apparently stereoscopy rendering isn’t part of the of the SDL codebase yet. I’ve added a PR here for anyone looking for that functionality: (N3DS) Add support for 3D stereoscopy rendering by FelixWolf · Pull Request #11480 · libsdl-org/SDL · GitHub