-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Game video output not recognizing scaled displays. #884
Comments
What happens if you try 1024x768 (or some other low resolution) in full screen? |
A little nuance here. To get the properly sized display, I have to get the display resolution from a website that checks this sort of thing, and that says my display size is 3200x1800. If I have to make a new screen resolution for every scaling factor, the amount of resolutions in the config file becomes a little cumbersome. So, it is a different problem than the full screen not being scaled to the full monitor in fullscreen mode. |
OK. See if you can find a reference in SDL as well as a discussion or code snippet to implement this. If you can find it, I'll implement this. Contingent on approval by @BenjamenMeyer. |
I asked ChatGPT about it, and here is the response: 1. Detect Available Screen ResolutionsSDL provides a function to get the available display modes for each connected monitor. You can query the modes and then allow the user to select the preferred resolution. Here’s an example of how to detect the available screen resolutions: #include <SDL2/SDL.h>
#include <stdio.h>
void listAvailableResolutions(int displayIndex) {
int numDisplayModes = SDL_GetNumDisplayModes(displayIndex);
if (numDisplayModes < 0) {
printf("SDL_GetNumDisplayModes failed: %s\n", SDL_GetError());
return;
}
printf("Available resolutions for display %d:\n", displayIndex);
for (int i = 0; i < numDisplayModes; i++) {
SDL_DisplayMode mode;
if (SDL_GetDisplayMode(displayIndex, i, &mode) != 0) {
printf("SDL_GetDisplayMode failed: %s\n", SDL_GetError());
continue;
}
printf("%d x %d @ %dHz\n", mode.w, mode.h, mode.refresh_rate);
}
}
int main() {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("SDL_Init Error: %s\n", SDL_GetError());
return 1;
}
int numDisplays = SDL_GetNumVideoDisplays();
if (numDisplays < 0) {
printf("SDL_GetNumVideoDisplays failed: %s\n", SDL_GetError());
return 1;
}
// List available resolutions for each display
for (int i = 0; i < numDisplays; i++) {
listAvailableResolutions(i);
}
SDL_Quit();
return 0;
} This code initializes SDL, retrieves the available resolutions for each display, and prints them out. You can select a resolution from this list and apply it later. 2. Set Display ModeOnce you've selected a resolution, you can set the SDL window to that resolution. Here’s how you do it: void setDisplayMode(int displayIndex, int width, int height) {
SDL_Window *window = SDL_CreateWindow("Game Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_FULLSCREEN_DESKTOP);
if (!window) {
printf("SDL_CreateWindow failed: %s\n", SDL_GetError());
return;
}
SDL_DisplayMode displayMode;
if (SDL_GetCurrentDisplayMode(displayIndex, &displayMode) != 0) {
printf("SDL_GetCurrentDisplayMode failed: %s\n", SDL_GetError());
} else {
SDL_SetWindowDisplayMode(window, &displayMode);
}
// Game loop and rendering goes here...
SDL_DestroyWindow(window);
} Here, 3. Handle Scaled DisplaysIf you are working with different resolutions, SDL provides an easy way to render at a consistent resolution, regardless of the screen size, using the Example for handling scaling: void setLogicalScaling(SDL_Renderer *renderer, int logicalWidth, int logicalHeight) {
SDL_RenderSetLogicalSize(renderer, logicalWidth, logicalHeight);
}
int main() {
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Init(SDL_INIT_VIDEO);
// Create window at some base resolution, here 1920x1080
window = SDL_CreateWindow("Game Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1080, SDL_WINDOW_SHOWN);
// Create renderer
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
// Set logical size to scale rendering to 1920x1080 regardless of window resolution
setLogicalScaling(renderer, 1920, 1080);
// Rendering loop
int running = 1;
SDL_Event event;
while (running) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
running = 0;
}
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
// Your game rendering logic here...
SDL_RenderPresent(renderer);
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
} 4. Fullscreen and Windowed Mode HandlingTo switch between fullscreen and windowed modes dynamically, you can use void toggleFullscreen(SDL_Window *window) {
Uint32 fullscreenFlag = SDL_WINDOW_FULLSCREEN_DESKTOP;
int isFullscreen = SDL_GetWindowFlags(window) & fullscreenFlag;
SDL_SetWindowFullscreen(window, isFullscreen ? 0 : fullscreenFlag);
} Summary:
By combining these techniques, your game engine can detect and adapt to various screen resolutions and handle proper scaling across different display setups. |
OK. That looks good. |
|
That's a good point. I wasn't about to plug this in as is anyhow. However, I did not consider this as I've been out of a job for a while now. No doubt my old job would have had a training session regarding this.
The big block here is the GUI. I don't want to tackle any GUI development using the home-grown stuff they wrote. Once we figure out something else, this should be reasonably easy.
I'm running the game in windowed 2k and the fonts are tiny. I just live with it until we can get to the GUI side of things. |
Yeah, my current employer introduced me to sum of the intricacies of this. I have a Copilot licences for work; but the liability for the license only extends to who paid for it. There's also not much protection on it from cross-using licenses so...I'll start a separate discussion on the topic. |
One of my monitors is fairly high resolution, and so it is scaled so that it is usable.
Unfortunately this causes issues with VegaStrike which is strictly pixel based.
SDL has a fairly straightforward way of dealing with this that should not impact non-scaled displays:
https://wiki.libsdl.org/SDL2/SDL_HINT_WINDOWS_DPI_SCALING
The text was updated successfully, but these errors were encountered: