[1.3] Serious resizing issue

Not sure what the point of the new Viewport stuff is, but it’s breaking resizing
pretty badly. When I take my TSdlFrame component and run the following, I get
exactly what you’d expect: a red box in the upper-left corner. (Yes, it’s my
own object and the API isn’t familiar. Assume everything does what it
intuitively looks like it should.)

begin
sdlFrame1.Clear;
sdlFrame1.DrawBox(rect(0, 0, 50, 50), COLOR_RED);
sdlFrame1.Flip;
end;

If I then execute a second routine,

begin
sdlFrame1.Height := round(sdlFrame1.Height * 0.9);
end;

the frame becomes a bit less tall. If I run the box-drawing routine again after
this, I’d expect to see the same thing as before: a red box in the upper-left
corner. But that’s not what I see. I get a red box drawn with the origin
slightly above the upper-left corner, so the top line is missing.

The problem seems to be coming from the following block in
SDL_RendererEventWatch:

        if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
            /* Try to keep the previous viewport centered */
            int w, h;
            SDL_Rect viewport;

            SDL_GetWindowSize(window, &w, &h);
            viewport.x = (w - renderer->viewport.w) / 2;
            viewport.y = (h - renderer->viewport.h) / 2;
            viewport.w = renderer->viewport.w;
            viewport.h = renderer->viewport.h;
            SDL_RenderSetViewport(renderer, &viewport);
        }

It tries to keep the viewport “centered”, but doesn’t do anything to ensure
proportionality or bounds checking. According to the inline documentation for
SDL_RenderSetViewport, “When the window is resized, the current viewport is
automatically centered within the new window size.” Unfortunately, there’s no
code there to handle the default case, “not using a viewport”.

This can be handled one of two ways. Either a SDL_Bool flag on the renderer
struct indicating whether a non-standard viewport has been set, or a pair of
floats describing the ratio between the heights and widths of the window and the
viewport to maintain proportionality. Whichever one is chosen needs to be taken
into account in SDL_RendererEventWatch.

This code is set up for people setting fullscreen modes and not handling the
window resize case. If you’re handling the resize, just reset the viewport
to NULL and you’re fine.

If this is tripping lots of people up, I’m open to changing it.On Sun, Apr 3, 2011 at 1:27 PM, Mason Wheeler wrote:

Not sure what the point of the new Viewport stuff is, but it’s breaking
resizing
pretty badly. When I take my TSdlFrame component and run the following, I
get
exactly what you’d expect: a red box in the upper-left corner. (Yes, it’s
my
own object and the API isn’t familiar. Assume everything does what it
intuitively looks like it should.)

begin
sdlFrame1.Clear;
sdlFrame1.DrawBox(rect(0, 0, 50, 50), COLOR_RED);
sdlFrame1.Flip;
end;

If I then execute a second routine,

begin
sdlFrame1.Height := round(sdlFrame1.Height * 0.9);
end;

the frame becomes a bit less tall. If I run the box-drawing routine again
after
this, I’d expect to see the same thing as before: a red box in the
upper-left
corner. But that’s not what I see. I get a red box drawn with the origin
slightly above the upper-left corner, so the top line is missing.

The problem seems to be coming from the following block in
SDL_RendererEventWatch:

       if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
           /* Try to keep the previous viewport centered */
           int w, h;
           SDL_Rect viewport;

           SDL_GetWindowSize(window, &w, &h);
           viewport.x = (w - renderer->viewport.w) / 2;
           viewport.y = (h - renderer->viewport.h) / 2;
           viewport.w = renderer->viewport.w;
           viewport.h = renderer->viewport.h;
           SDL_RenderSetViewport(renderer, &viewport);
       }

It tries to keep the viewport “centered”, but doesn’t do anything to ensure
proportionality or bounds checking. According to the inline documentation
for
SDL_RenderSetViewport, “When the window is resized, the current viewport is
automatically centered within the new window size.” Unfortunately, there’s
no
code there to handle the default case, “not using a viewport”.

This can be handled one of two ways. Either a SDL_Bool flag on the
renderer
struct indicating whether a non-standard viewport has been set, or a pair
of
floats describing the ratio between the heights and widths of the window
and the
viewport to maintain proportionality. Whichever one is chosen needs to be
taken
into account in SDL_RendererEventWatch.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

It also broke my custom Logical Size code pretty badly, and I spent all weekend
trying to figure out how to hack around it without disabling it completely.

What exactly is this supposed to do, anyway? Near as I can tell, it creates a
clipping rect within the SDL_Window that you can’t draw outside of. But what’s
the use case for that? It kinda feels to me like a solution in search of a
problem.________________________________
From: slouken@libsdl.org (slouken)
Subject: Re: [SDL] [1.3] Serious resizing issue

This code is set up for people setting fullscreen modes and not handling the
window resize case. If you’re handling the resize, just reset the viewport to
NULL and you’re fine.

If this is tripping lots of people up, I’m open to changing it.

On Sun, Apr 3, 2011 at 1:27 PM, Mason Wheeler <@Mason_Wheeler> wrote:

Not sure what the point of the new Viewport stuff is, but it’s breaking resizing

pretty badly. When I take my TSdlFrame component and run the following, I get
exactly what you’d expect: a red box in the upper-left corner. (Yes, it’s my
own object and the API isn’t familiar. Assume everything does what it
intuitively looks like it should.)

begin
sdlFrame1.Clear;
sdlFrame1.DrawBox(rect(0, 0, 50, 50), COLOR_RED);
sdlFrame1.Flip;
end;

If I then execute a second routine,

begin
sdlFrame1.Height := round(sdlFrame1.Height * 0.9);
end;

the frame becomes a bit less tall. If I run the box-drawing routine again
after
this, I’d expect to see the same thing as before: a red box in the upper-left
corner. But that’s not what I see. I get a red box drawn with the origin
slightly above the upper-left corner, so the top line is missing.

The problem seems to be coming from the following block in
SDL_RendererEventWatch:

      if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
          /* Try to keep the previous viewport centered */
          int w, h;
          SDL_Rect viewport;

          SDL_GetWindowSize(window, &w, &h);
          viewport.x = (w - renderer->viewport.w) / 2;
          viewport.y = (h - renderer->viewport.h) / 2;
          viewport.w = renderer->viewport.w;
          viewport.h = renderer->viewport.h;
          SDL_RenderSetViewport(renderer, &viewport);
      }

It tries to keep the viewport “centered”, but doesn’t do anything to ensure
proportionality or bounds checking. According to the inline documentation for
SDL_RenderSetViewport, “When the window is resized, the current viewport is
automatically centered within the new window size.” Unfortunately, there’s no
code there to handle the default case, “not using a viewport”.

This can be handled one of two ways. Either a SDL_Bool flag on the renderer
struct indicating whether a non-standard viewport has been set, or a pair of
floats describing the ratio between the heights and widths of the window and
the
viewport to maintain proportionality. Whichever one is chosen needs to be
taken
into account in SDL_RendererEventWatch.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

It’s used for the SDL 1.2 API where fullscreen modes need to be centered
within the actual video mode if they don’t match, and I assumed this would
be a common use case for applications that don’t dynamically resize.

It’s also used for clipping of custom UI controls in certain circumstances.

Again though, if it’s tripping people up, the logic can be moved to the SDL
1.2 compat layer instead of generalized.On Mon, Apr 4, 2011 at 10:11 AM, Mason Wheeler wrote:

It also broke my custom Logical Size code pretty badly, and I spent all
weekend trying to figure out how to hack around it without disabling it
completely.

What exactly is this supposed to do, anyway? Near as I can tell, it creates
a clipping rect within the SDL_Window that you can’t draw outside of. But
what’s the use case for that? It kinda feels to me like a solution in search
of a problem.


From: Sam Lantinga <@slouken>
**Subject: Re: [SDL] [1.3] Serious resizing issue

This code is set up for people setting fullscreen modes and not handling
the window resize case. If you’re handling the resize, just reset the
viewport to NULL and you’re fine.

If this is tripping lots of people up, I’m open to changing it.

On Sun, Apr 3, 2011 at 1:27 PM, Mason Wheeler wrote:

Not sure what the point of the new Viewport stuff is, but it’s breaking
resizing
pretty badly. When I take my TSdlFrame component and run the following, I
get
exactly what you’d expect: a red box in the upper-left corner. (Yes, it’s
my
own object and the API isn’t familiar. Assume everything does what it
intuitively looks like it should.)

begin
sdlFrame1.Clear;
sdlFrame1.DrawBox(rect(0, 0, 50, 50), COLOR_RED);
sdlFrame1.Flip;
end;

If I then execute a second routine,

begin
sdlFrame1.Height := round(sdlFrame1.Height * 0.9);
end;

the frame becomes a bit less tall. If I run the box-drawing routine again
after
this, I’d expect to see the same thing as before: a red box in the
upper-left
corner. But that’s not what I see. I get a red box drawn with the origin
slightly above the upper-left corner, so the top line is missing.

The problem seems to be coming from the following block in
SDL_RendererEventWatch:

       if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
           /* Try to keep the previous viewport centered */
           int w, h;
           SDL_Rect viewport;

           SDL_GetWindowSize(window, &w, &h);
           viewport.x = (w - renderer->viewport.w) / 2;
           viewport.y = (h - renderer->viewport.h) / 2;
           viewport.w = renderer->viewport.w;
           viewport.h = renderer->viewport.h;
           SDL_RenderSetViewport(renderer, &viewport);
       }

It tries to keep the viewport “centered”, but doesn’t do anything to
ensure
proportionality or bounds checking. According to the inline documentation
for
SDL_RenderSetViewport, “When the window is resized, the current viewport
is
automatically centered within the new window size.” Unfortunately,
there’s no
code there to handle the default case, “not using a viewport”.

This can be handled one of two ways. Either a SDL_Bool flag on the
renderer
struct indicating whether a non-standard viewport has been set, or a pair
of
floats describing the ratio between the heights and widths of the window
and the
viewport to maintain proportionality. Whichever one is chosen needs to be
taken
into account in SDL_RendererEventWatch.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks