mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-24 08:15:50 +00:00
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
if (modes) {
for (i = 0; i < num_modes; ++i) {
SDL_DisplayMode *mode = modes[i];
SDL_Log("Display %" SDL_PRIu32 " mode %d: %dx%d@%gHz, %d%% scale\n",
display, i, mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f));
}
SDL_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
This commit is contained in:
@@ -339,12 +339,13 @@ int video_getWindowFlags(void *arg)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests the functionality of the SDL_GetNumDisplayModes function
|
||||
* @brief Tests the functionality of the SDL_GetFullscreenDisplayModes function
|
||||
*/
|
||||
int video_getNumDisplayModes(void *arg)
|
||||
int video_getFullscreenDisplayModes(void *arg)
|
||||
{
|
||||
SDL_DisplayID *displays;
|
||||
int result;
|
||||
const SDL_DisplayMode **modes;
|
||||
int count;
|
||||
int i;
|
||||
|
||||
/* Get number of displays */
|
||||
@@ -354,9 +355,11 @@ int video_getNumDisplayModes(void *arg)
|
||||
|
||||
/* Make call for each display */
|
||||
for (i = 0; displays[i]; ++i) {
|
||||
result = SDL_GetNumDisplayModes(displays[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i);
|
||||
SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result);
|
||||
modes = SDL_GetFullscreenDisplayModes(displays[i], &count);
|
||||
SDLTest_AssertPass("Call to SDL_GetFullscreenDisplayModes(%" SDL_PRIu32 ")", displays[i]);
|
||||
SDLTest_AssertCheck(modes != NULL, "Validate returned value from function; expected != NULL; got: %p", modes);
|
||||
SDLTest_AssertCheck(count >= 0, "Validate number of modes; expected: >= 0; got: %d", count);
|
||||
SDL_free(modes);
|
||||
}
|
||||
SDL_free(displays);
|
||||
}
|
||||
@@ -365,18 +368,15 @@ int video_getNumDisplayModes(void *arg)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution
|
||||
* @brief Tests the functionality of the SDL_GetClosestFullscreenDisplayMode function against current resolution
|
||||
*/
|
||||
int video_getClosestDisplayModeCurrentResolution(void *arg)
|
||||
{
|
||||
int result;
|
||||
SDL_DisplayID *displays;
|
||||
const SDL_DisplayMode **modes;
|
||||
SDL_DisplayMode current;
|
||||
SDL_DisplayMode target;
|
||||
SDL_DisplayMode closest;
|
||||
SDL_DisplayMode *dResult;
|
||||
int i;
|
||||
int variation;
|
||||
const SDL_DisplayMode *closest;
|
||||
int i, num_modes;
|
||||
|
||||
/* Get number of displays */
|
||||
displays = SDL_GetDisplays(NULL);
|
||||
@@ -388,35 +388,22 @@ int video_getClosestDisplayModeCurrentResolution(void *arg)
|
||||
SDLTest_Log("Testing against display: %" SDL_PRIu32 "", displays[i]);
|
||||
|
||||
/* Get first display mode to get a sane resolution; this should always work */
|
||||
result = SDL_GetDisplayMode(displays[i], 0, ¤t);
|
||||
SDLTest_AssertPass("Call to SDL_GetDisplayMode()");
|
||||
SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
|
||||
if (result != 0) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Set the desired resolution equals to current resolution */
|
||||
SDL_zero(target);
|
||||
target.pixel_w = current.pixel_w;
|
||||
target.pixel_h = current.pixel_h;
|
||||
for (variation = 0; variation < 8; variation++) {
|
||||
/* Vary constraints on other query parameters */
|
||||
target.format = (variation & 1) ? current.format : 0;
|
||||
target.refresh_rate = (variation & 2) ? current.refresh_rate : 0.0f;
|
||||
target.driverdata = (variation & 4) ? current.driverdata : 0;
|
||||
modes = SDL_GetFullscreenDisplayModes(displays[i], &num_modes);
|
||||
SDLTest_AssertPass("Call to SDL_GetDisplayModes()");
|
||||
SDLTest_Assert(modes != NULL, "Verify returned value is not NULL");
|
||||
if (num_modes > 0) {
|
||||
SDL_memcpy(¤t, modes[0], sizeof(current));
|
||||
|
||||
/* Make call */
|
||||
dResult = SDL_GetClosestDisplayMode(displays[i], &target, &closest);
|
||||
SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation);
|
||||
SDLTest_Assert(dResult != NULL, "Verify returned value is not NULL");
|
||||
closest = SDL_GetClosestFullscreenDisplayMode(displays[i], current.pixel_w, current.pixel_h, current.refresh_rate);
|
||||
SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=current)");
|
||||
SDLTest_Assert(closest != NULL, "Verify returned value is not NULL");
|
||||
|
||||
/* Check that one gets the current resolution back again */
|
||||
SDLTest_AssertCheck(closest.pixel_w == current.pixel_w, "Verify returned width matches current width; expected: %d, got: %d", current.pixel_w, closest.pixel_w);
|
||||
SDLTest_AssertCheck(closest.pixel_h == current.pixel_h, "Verify returned height matches current height; expected: %d, got: %d", current.pixel_h, closest.pixel_h);
|
||||
/* NOLINTBEGIN(clang-analyzer-core.NullDereference): Checked earlier for NULL */
|
||||
SDLTest_AssertCheck(closest.pixel_w == dResult->pixel_w, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_w, dResult->pixel_w);
|
||||
SDLTest_AssertCheck(closest.pixel_h == dResult->pixel_h, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_h, dResult->pixel_h);
|
||||
/* NOLINTEND(clang-analyzer-core.NullDereference) */
|
||||
if (closest) {
|
||||
SDLTest_AssertCheck(closest->pixel_w == current.pixel_w, "Verify returned width matches current width; expected: %d, got: %d", current.pixel_w, closest->pixel_w);
|
||||
SDLTest_AssertCheck(closest->pixel_h == current.pixel_h, "Verify returned height matches current height; expected: %d, got: %d", current.pixel_h, closest->pixel_h);
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_free(displays);
|
||||
@@ -426,13 +413,12 @@ int video_getClosestDisplayModeCurrentResolution(void *arg)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution
|
||||
* @brief Tests the functionality of the SDL_GetClosestFullscreenDisplayMode function against random resolution
|
||||
*/
|
||||
int video_getClosestDisplayModeRandomResolution(void *arg)
|
||||
{
|
||||
SDL_DisplayID *displays;
|
||||
SDL_DisplayMode target;
|
||||
SDL_DisplayMode closest;
|
||||
int i;
|
||||
int variation;
|
||||
|
||||
@@ -451,12 +437,11 @@ int video_getClosestDisplayModeRandomResolution(void *arg)
|
||||
SDL_zero(target);
|
||||
target.pixel_w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
|
||||
target.pixel_h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
|
||||
target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
|
||||
target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f;
|
||||
|
||||
/* Make call; may or may not find anything, so don't validate any further */
|
||||
SDL_GetClosestDisplayMode(displays[i], &target, &closest);
|
||||
SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);
|
||||
SDL_GetClosestFullscreenDisplayMode(displays[i], target.pixel_w, target.pixel_h, target.refresh_rate);
|
||||
SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=random/variation%d)", variation);
|
||||
}
|
||||
}
|
||||
SDL_free(displays);
|
||||
@@ -466,31 +451,22 @@ int video_getClosestDisplayModeRandomResolution(void *arg)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowDisplayMode
|
||||
* @brief Tests call to SDL_GetWindowFullscreenMode
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowDisplayMode
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowFullscreenMode
|
||||
*/
|
||||
int video_getWindowDisplayMode(void *arg)
|
||||
{
|
||||
SDL_Window *window;
|
||||
const char *title = "video_getWindowDisplayMode Test Window";
|
||||
SDL_DisplayMode mode;
|
||||
int result;
|
||||
|
||||
/* Invalidate part of the mode content so we can check values later */
|
||||
mode.pixel_w = -1;
|
||||
mode.pixel_h = -1;
|
||||
mode.refresh_rate = -1.0f;
|
||||
const SDL_DisplayMode *mode;
|
||||
|
||||
/* Call against new test window */
|
||||
window = createVideoSuiteTestWindow(title);
|
||||
if (window != NULL) {
|
||||
result = SDL_GetWindowDisplayMode(window, &mode);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode()");
|
||||
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
|
||||
SDLTest_AssertCheck(mode.pixel_w > 0, "Validate mode.w content; expected: >0, got: %d", mode.pixel_w);
|
||||
SDLTest_AssertCheck(mode.pixel_h > 0, "Validate mode.h content; expected: >0, got: %d", mode.pixel_h);
|
||||
SDLTest_AssertCheck(mode.refresh_rate > 0.0f, "Validate mode.refresh_rate content; expected: >0, got: %g", mode.refresh_rate);
|
||||
mode = SDL_GetWindowFullscreenMode(window);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowFullscreenMode()");
|
||||
SDLTest_AssertCheck(mode == NULL, "Validate result value; expected: NULL, got: %p", mode);
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
@@ -519,43 +495,18 @@ static void checkInvalidWindowError()
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowDisplayMode with invalid input
|
||||
* @brief Tests call to SDL_GetWindowFullscreenMode with invalid input
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowDisplayMode
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowFullscreenMode
|
||||
*/
|
||||
int video_getWindowDisplayModeNegative(void *arg)
|
||||
{
|
||||
const char *expectedError = "Parameter 'mode' is invalid";
|
||||
char *lastError;
|
||||
SDL_Window *window;
|
||||
const char *title = "video_getWindowDisplayModeNegative Test Window";
|
||||
SDL_DisplayMode mode;
|
||||
int result;
|
||||
|
||||
/* Call against new test window */
|
||||
window = createVideoSuiteTestWindow(title);
|
||||
if (window != NULL) {
|
||||
result = SDL_GetWindowDisplayMode(window, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(...,mode=NULL)");
|
||||
SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
|
||||
if (lastError != NULL) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, expectedError) == 0,
|
||||
"SDL_GetError(): expected message '%s', was message: '%s'",
|
||||
expectedError,
|
||||
lastError);
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
destroyVideoSuiteTestWindow(window);
|
||||
const SDL_DisplayMode *mode;
|
||||
|
||||
/* Call against invalid window */
|
||||
result = SDL_GetWindowDisplayMode(NULL, &mode);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(window=NULL,...)");
|
||||
SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
|
||||
mode = SDL_GetWindowFullscreenMode(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowFullscreenMode(window=NULL)");
|
||||
SDLTest_AssertCheck(mode == NULL, "Validate result value; expected: NULL, got: %p", mode);
|
||||
checkInvalidWindowError();
|
||||
|
||||
return TEST_COMPLETED;
|
||||
@@ -1748,7 +1699,7 @@ int video_setWindowCenteredOnDisplay(void *arg)
|
||||
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
|
||||
|
||||
/* Enter fullscreen desktop */
|
||||
result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
result = SDL_SetWindowFullscreen(window, SDL_TRUE);
|
||||
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
|
||||
|
||||
/* Check we are filling the full display */
|
||||
@@ -1763,7 +1714,7 @@ int video_setWindowCenteredOnDisplay(void *arg)
|
||||
SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y);
|
||||
|
||||
/* Leave fullscreen desktop */
|
||||
result = SDL_SetWindowFullscreen(window, 0);
|
||||
result = SDL_SetWindowFullscreen(window, SDL_FALSE);
|
||||
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
|
||||
|
||||
/* Check window was restored correctly */
|
||||
@@ -1832,7 +1783,7 @@ static const SDLTest_TestCaseReference videoTest5 = {
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference videoTest6 = {
|
||||
(SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED
|
||||
(SDLTest_TestCaseFp)video_getFullscreenDisplayModes, "video_getFullscreenDisplayModes", "Use SDL_GetFullscreenDisplayModes function to get number of display modes", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference videoTest7 = {
|
||||
|
||||
@@ -32,7 +32,8 @@ print_mode(const char *prefix, const SDL_DisplayMode *mode)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_DisplayID *displays;
|
||||
SDL_DisplayMode mode;
|
||||
const SDL_DisplayMode **modes;
|
||||
const SDL_DisplayMode *mode;
|
||||
int num_displays, i;
|
||||
|
||||
/* Enable standard application logging */
|
||||
@@ -51,13 +52,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
for (i = 0; i < num_displays; i++) {
|
||||
SDL_DisplayID dpy = displays[i];
|
||||
const int num_modes = SDL_GetNumDisplayModes(dpy);
|
||||
SDL_Rect rect = { 0, 0, 0, 0 };
|
||||
float ddpi, hdpi, vdpi;
|
||||
int m;
|
||||
int m, num_modes = 0;
|
||||
|
||||
SDL_GetDisplayBounds(dpy, &rect);
|
||||
SDL_Log("%" SDL_PRIu32 ": \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);
|
||||
modes = SDL_GetFullscreenDisplayModes(dpy, &num_modes);
|
||||
SDL_Log("%" SDL_PRIu32 ": \"%s\" (%dx%d, (%d, %d)), %d fullscreen modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);
|
||||
|
||||
if (SDL_GetDisplayPhysicalDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DPI: failed to query (%s)\n", SDL_GetError());
|
||||
@@ -65,27 +66,26 @@ int main(int argc, char *argv[])
|
||||
SDL_Log(" DPI: ddpi=%f; hdpi=%f; vdpi=%f\n", ddpi, hdpi, vdpi);
|
||||
}
|
||||
|
||||
if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)\n", SDL_GetError());
|
||||
mode = SDL_GetCurrentDisplayMode(dpy);
|
||||
if (mode) {
|
||||
print_mode("CURRENT", mode);
|
||||
} else {
|
||||
print_mode("CURRENT", &mode);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)\n", SDL_GetError());
|
||||
}
|
||||
|
||||
if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DESKTOP: failed to query (%s)\n", SDL_GetError());
|
||||
mode = SDL_GetDesktopDisplayMode(dpy);
|
||||
if (mode) {
|
||||
print_mode("DESKTOP", mode);
|
||||
} else {
|
||||
print_mode("DESKTOP", &mode);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DESKTOP: failed to query (%s)\n", SDL_GetError());
|
||||
}
|
||||
|
||||
for (m = 0; m < num_modes; m++) {
|
||||
if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " MODE %d: failed to query (%s)\n", m, SDL_GetError());
|
||||
} else {
|
||||
char prefix[64];
|
||||
(void)SDL_snprintf(prefix, sizeof prefix, " MODE %d", m);
|
||||
print_mode(prefix, &mode);
|
||||
}
|
||||
char prefix[64];
|
||||
(void)SDL_snprintf(prefix, sizeof prefix, " MODE %d", m);
|
||||
print_mode(prefix, modes[i]);
|
||||
}
|
||||
SDL_free(modes);
|
||||
|
||||
SDL_Log("\n");
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
int i, done;
|
||||
SDL_DisplayMode mode;
|
||||
const SDL_DisplayMode *mode;
|
||||
SDL_Event event;
|
||||
Uint64 then, now;
|
||||
Uint32 frames;
|
||||
@@ -293,8 +293,10 @@ int main(int argc, char *argv[])
|
||||
swap_interval = 0;
|
||||
}
|
||||
|
||||
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
|
||||
SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode.format));
|
||||
mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
|
||||
if (mode) {
|
||||
SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode->format));
|
||||
}
|
||||
|
||||
ret_interval = SDL_GL_GetSwapInterval(&interval);
|
||||
if (ret_interval < 0) {
|
||||
|
||||
@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
int i, done;
|
||||
SDL_DisplayMode mode;
|
||||
const SDL_DisplayMode *mode;
|
||||
SDL_Event event;
|
||||
Uint32 then, now, frames;
|
||||
int status;
|
||||
@@ -187,9 +187,11 @@ int main(int argc, char *argv[])
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
}
|
||||
|
||||
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
|
||||
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
|
||||
SDL_Log("\n");
|
||||
mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
|
||||
if (mode) {
|
||||
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode->format));
|
||||
SDL_Log("\n");
|
||||
}
|
||||
SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR));
|
||||
SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER));
|
||||
SDL_Log("Version : %s\n", glGetString(GL_VERSION));
|
||||
|
||||
@@ -615,7 +615,7 @@ int main(int argc, char *argv[])
|
||||
int fsaa, accel, threaded;
|
||||
int value;
|
||||
int i;
|
||||
SDL_DisplayMode mode;
|
||||
const SDL_DisplayMode *mode;
|
||||
Uint64 then, now;
|
||||
int status;
|
||||
shader_data *data;
|
||||
@@ -714,10 +714,12 @@ int main(int argc, char *argv[])
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
}
|
||||
|
||||
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
|
||||
mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
|
||||
SDL_Log("Threaded : %s\n", threaded ? "yes" : "no");
|
||||
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
|
||||
SDL_Log("\n");
|
||||
if (mode) {
|
||||
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode->format));
|
||||
SDL_Log("\n");
|
||||
}
|
||||
SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR));
|
||||
SDL_Log("Renderer : %s\n", ctx.glGetString(GL_RENDERER));
|
||||
SDL_Log("Version : %s\n", ctx.glGetString(GL_VERSION));
|
||||
|
||||
@@ -434,7 +434,7 @@ int main(int argc, char *argv[])
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
int i;
|
||||
SDL_DisplayMode mode;
|
||||
const SDL_DisplayMode *mode;
|
||||
Uint64 then, now;
|
||||
int status;
|
||||
shader_data *data;
|
||||
@@ -602,9 +602,11 @@ int main(int argc, char *argv[])
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
}
|
||||
|
||||
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
|
||||
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
|
||||
SDL_Log("\n");
|
||||
mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
|
||||
if (mode) {
|
||||
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode->format));
|
||||
SDL_Log("\n");
|
||||
}
|
||||
SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR));
|
||||
SDL_Log("Renderer : %s\n", ctx.glGetString(GL_RENDERER));
|
||||
SDL_Log("Version : %s\n", ctx.glGetString(GL_VERSION));
|
||||
|
||||
@@ -1080,7 +1080,7 @@ static SDL_bool render(void)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int done;
|
||||
SDL_DisplayMode mode;
|
||||
const SDL_DisplayMode *mode;
|
||||
SDL_Event event;
|
||||
Uint64 then, now;
|
||||
Uint32 frames;
|
||||
@@ -1104,8 +1104,10 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode);
|
||||
SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode.format));
|
||||
mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
|
||||
if (mode) {
|
||||
SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode->format));
|
||||
}
|
||||
SDL_GetWindowSize(state->windows[0], &dw, &dh);
|
||||
SDL_Log("Window Size : %d,%d\n", dw, dh);
|
||||
SDL_GetWindowSizeInPixels(state->windows[0], &dw, &dh);
|
||||
|
||||
@@ -54,11 +54,10 @@ quit(int rc)
|
||||
static void
|
||||
draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
const SDL_DisplayMode **modes;
|
||||
char text[1024];
|
||||
const int lineHeight = 10;
|
||||
const SDL_DisplayID displayID = SDL_GetDisplayForWindow(window);
|
||||
const int num_modes = SDL_GetNumDisplayModes(displayID);
|
||||
int i;
|
||||
int column_chars = 0;
|
||||
int text_length;
|
||||
@@ -83,7 +82,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
|
||||
|
||||
y += lineHeight;
|
||||
|
||||
SDL_strlcpy(text, "Click on a mode to set it with SDL_SetWindowDisplayMode", sizeof text);
|
||||
SDL_strlcpy(text, "Click on a mode to set it with SDL_SetWindowFullscreenMode", sizeof text);
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDLTest_DrawString(renderer, x, y, text);
|
||||
y += lineHeight;
|
||||
@@ -100,15 +99,13 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
|
||||
highlighted_mode = -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < num_modes; ++i) {
|
||||
modes = SDL_GetFullscreenDisplayModes(displayID, NULL);
|
||||
for (i = 0; modes[i]; ++i) {
|
||||
SDL_FRect cell_rect;
|
||||
|
||||
if (0 != SDL_GetDisplayMode(displayID, i, &mode)) {
|
||||
return;
|
||||
}
|
||||
const SDL_DisplayMode *mode = modes[i];
|
||||
|
||||
(void)SDL_snprintf(text, sizeof text, "%d: %dx%d@%gHz",
|
||||
i, mode.pixel_w, mode.pixel_h, mode.refresh_rate);
|
||||
i, mode->pixel_w, mode->pixel_h, mode->refresh_rate);
|
||||
|
||||
/* Update column width */
|
||||
text_length = (int)SDL_strlen(text);
|
||||
@@ -141,6 +138,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
|
||||
column_chars = 0;
|
||||
}
|
||||
}
|
||||
SDL_free(modes);
|
||||
}
|
||||
|
||||
void loop()
|
||||
@@ -208,12 +206,13 @@ void loop()
|
||||
SDL_Window *window = SDL_GetMouseFocus();
|
||||
if (highlighted_mode != -1 && window != NULL) {
|
||||
SDL_DisplayID displayID = SDL_GetDisplayForWindow(window);
|
||||
SDL_DisplayMode mode;
|
||||
if (0 != SDL_GetDisplayMode(displayID, highlighted_mode, &mode)) {
|
||||
SDL_Log("Couldn't get display mode");
|
||||
} else {
|
||||
SDL_SetWindowDisplayMode(window, &mode);
|
||||
int num_modes;
|
||||
const SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(displayID, &num_modes);
|
||||
if (highlighted_mode < num_modes) {
|
||||
SDL_memcpy(&state->fullscreen_mode, modes[highlighted_mode], sizeof(state->fullscreen_mode));
|
||||
SDL_SetWindowFullscreenMode(window, modes[highlighted_mode]);
|
||||
}
|
||||
SDL_free(modes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user