# sdl12-compat: video: SDL\_VideoModeOK shouldn't require exact dimensions.

**URL:** <https://discourse.libsdl.org/t/sdl12-compat-video-sdl-videomodeok-shouldnt-require-exact-dimensions/39104>\
**Category:** SDL Commits\
**Created:** [October 4, 2022, 12:44am UTC](https://discourse.libsdl.org/t/sdl12-compat-video-sdl-videomodeok-shouldnt-require-exact-dimensions/39104 "2022-10-04T00:44:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [October 4, 2022, 12:44am UTC](https://discourse.libsdl.org/t/sdl12-compat-video-sdl-videomodeok-shouldnt-require-exact-dimensions/39104/1 "2022-10-04T00:44:02Z")

</div>

> <https://github.com/libsdl-org/sdl12-compat/commit/e9131f26205a539f35fd5dbdcc9678c031374f1f>
>
> 1.2 (on many video backends) would allow smaller surfaces that it would
> center i…n a larger mode, so emulate that here.
> 
> Reference Issue #228.

```diff
From e9131f26205a539f35fd5dbdcc9678c031374f1f Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 3 Oct 2022 20:41:04 -0400
Subject: [PATCH] video: SDL_VideoModeOK shouldn't require exact dimensions.

1.2 (on many video backends) would allow smaller surfaces that it would
center in a larger mode, so emulate that here.

Reference Issue #228.
---
 src/SDL12_compat.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index a2c1aadd..75dd2da8 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -5117,16 +5117,21 @@ SDL_VideoModeOK(int width, int height, int bpp, Uint32 sdl12flags)
         return 0;
     }
 
+ /* if the 1.2 video backend could center a surface in a larger mode, it
+ would accept the size. Since we scale things, we will, too, even
+ without an exact width/height match. */
+
     if (!(sdl12flags & SDL12_FULLSCREEN)) {
         SDL_DisplayMode mode;
         SDL20_GetDesktopDisplayMode(VideoDisplayIndex, &mode);
- actual_bpp = SDL_BITSPERPIXEL(mode.format);
+ if ((mode.w >= width) && (mode.h >= height)) {
+ actual_bpp = SDL_BITSPERPIXEL(mode.format);
+ }
     } else {
         for (i = 0; i < VideoModesCount; ++i) {
             VideoModeList *vmode = &VideoModes[i];
             for (j = 0; j < vmode->nummodes; ++j) {
- if (vmode->modeslist12[j].w == width && vmode->modeslist12[j].h == height)
- {
+ if (vmode->modeslist12[j].w >= width && vmode->modeslist12[j].h >= height) {
                     if (!vmode->format) {
                         return bpp;
                     }

```
