JeZ-l-Lee | 14 Aug 15:42 2013
Picon

[SDL2]-SDL_RenderSetLogicalSize-Disable Letterboxing?

[SDL2]-SDL_RenderSetLogicalSize-Disable Letterboxing?

Hi,

SDL_RenderSetLogicalSize can be used to scale the SDL window to resized window dimensions.
The default action of SDL_RenderSetLogicalSize is to scale with letterboxing. (maintaining an aspect ration)

Is there some way to disable letterboxing in SDL_RenderSetLogicalSize and tell SDL2 to fill entire resized screen?
Thanks!



JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft(R)
Video Game Design Studio
www.16BitSoft.com
_______________________________________________
SDL mailing list
SDL <at> lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
JeZ-l-Lee | 16 Aug 01:03 2013
Picon

Re: [SDL2]-SDL_RenderSetLogicalSize-Disable Letterboxing?








JeZ-l-Lee wrote:
[SDL2]-SDL_RenderSetLogicalSize-Disable Letterboxing?

Hi,

SDL_RenderSetLogicalSize can be used to scale the SDL window to resized window dimensions.
The default action of SDL_RenderSetLogicalSize is to scale with letterboxing. (maintaining an aspect ration)

Is there some way to disable letterboxing in SDL_RenderSetLogicalSize and tell SDL2 to fill entire resized screen?
Thanks!
Hi,

There is no way to disable letterboxing when using SDL_RenderSetLogicalSize() ?
I need the above function to fill entire window whether resized or maximized.

I figured out a way to scale image and text textures to fill the window even if resized
but the text outline does not look right.

There must be a way?
Thanks!



JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft(R)
Video Game Design Studio
www.16BitSoft.com
_______________________________________________
SDL mailing list
SDL <at> lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Ryan C. Gordon | 16 Aug 02:12 2013

Re: [SDL2]-SDL_RenderSetLogicalSize-Disable Letterboxing?


> There is no way to disable letterboxing when using
> SDL_RenderSetLogicalSize() ?
> I need the above function to fill entire window whether resized or
> maximized.

You'd have to specify a logical size with the same aspect ratio as the 
display. Otherwise, we have to letterbox it to make it work as 
requested. If the aspect ratio matches, we'll use the whole display 
without letterboxing.

--ryan.
JeZ-l-Lee | 16 Aug 03:10 2013
Picon

Re: [SDL2]-SDL_RenderSetLogicalSize-Disable Letterboxing?

Hi,

Here is my sprite drawing function(scales properly with window resize):







Code:
//-------------------------------------------------------------------------------------------------
void Visuals::DrawSpriteOntoScreenBuffer(Uint16 index)
{
SDL_Rect destinationRect;
int windowWidth;
int windowHeight;
Uint32 textureFormat;
int textureAccess;
int textureWidth;
int textureHeight;

    SDL_GetWindowSize(Window, &windowWidth, &windowHeight);

    SDL_QueryTexture(Sprites[index].Texture, &textureFormat, &textureAccess, &textureWidth, &textureHeight);

    float winWidthFixed = (float)windowWidth / 640;
    float winHeightFixed = (float)windowHeight / 480;

    destinationRect.x = ( Sprites[index].ScreenX * (winWidthFixed) )
                        - (  ( (textureWidth * Sprites[index].ScaleX) * (winWidthFixed) ) / 2  );
    destinationRect.y = ( Sprites[index].ScreenY * (winHeightFixed) )
                        - (  ( (textureHeight * Sprites[index].ScaleY) * (winHeightFixed) ) / 2  );
    destinationRect.w = textureWidth * Sprites[index].ScaleX * (winWidthFixed);
    destinationRect.h = textureHeight * Sprites[index].ScaleY * (winHeightFixed);

    SDL_SetTextureColorMod(Sprites[index].Texture, Sprites[index].RedHue, Sprites[index].GreenHue, Sprites[index].BlueHue);
    SDL_SetTextureAlphaMod(Sprites[index].Texture, Sprites[index].Transparency);
/*
    if (Sprites[index].Smooth == false)
        SDL_SetTextureBlendMode(Sprites[index].Texture, SDL_BLENDMODE_NONE);
    else if (Sprites[index].Smooth == true)
        SDL_SetTextureBlendMode(Sprites[index].Texture, SDL_BLENDMODE_BLEND);
*/
    if (Sprites[index].FlipX == false && Sprites[index].FlipY == false)
    {
        SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, Sprites[index].RotationDegree
                         , NULL, SDL_FLIP_NONE);
    }
    else if (Sprites[index].FlipX == true && Sprites[index].FlipY == false)
    {
        SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, Sprites[index].RotationDegree
                         , NULL, SDL_FLIP_HORIZONTAL);
    }
    else if (Sprites[index].FlipX == false && Sprites[index].FlipY == true)
    {
        SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, Sprites[index].RotationDegree
                         , NULL, SDL_FLIP_VERTICAL);
    }
    else if (Sprites[index].FlipX == true && Sprites[index].FlipY == true)
    {
        double flipHorizontallyAndVerticallyDegreeFix = Sprites[index].RotationDegree+180;

        SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, flipHorizontallyAndVerticallyDegreeFix
                         , NULL, SDL_FLIP_NONE);
    }
/*
    SDL_SetTextureBlendMode(Sprites[index].Texture, SDL_BLENDMODE_NONE);
    SDL_SetTextureAlphaMod(Sprites[index].Texture, 255);
    SDL_SetTextureColorMod(Sprites[index].Texture, 255, 255, 255);
*/
}

//-------------------------------------------------------------------------------------------------


Here is my text drawing function(outline does not look correct when window is resized):







Code:
//-------------------------------------------------------------------------------------------------
void Visuals::DrawTextOntoScreenBuffer(const char *textToDisplay, TTF_Font *font, int posX, int posY
                                       , Uint8 XJustification, Uint8 textRed, Uint8 textGreen, Uint8 textBlue
                                       , Uint8 outlineRed, Uint8 outlineGreen, Uint8 outlineBlue)
{
SDL_Color textColor = { textRed, textGreen, textBlue, 255 };
SDL_Color outlineColor = { outlineRed, outlineGreen, outlineBlue, 255 };
SDL_Surface *text;
SDL_Surface *textOutline;
SDL_Texture *textTexture;
SDL_Texture *textOutlineTexture;
SDL_Rect destinationRect;
SDL_Rect destinationOutlineRect;
int windowWidth;
int windowHeight;

    SDL_GetWindowSize(Window, &windowWidth, &windowHeight);

    text = TTF_RenderText_Blended(font, textToDisplay, textColor);
    textOutline = TTF_RenderText_Solid(font, textToDisplay, outlineColor);

    if (XJustification == JustifyLeft)
    {
        posX = posX + (text->w / 2);
    }
    else if (XJustification == JustifyCenter)
    {
        posX = (640 / 2);
    }
    else if (XJustification == JustifyRight)
    {
        posX = (640 - posX) - (text->w / 2);
    }
    else if (XJustification == JustifyCenterOnPoint)
    {
        posX = posX;
    }

    textTexture = SDL_CreateTextureFromSurface(Renderer, text);
    textOutlineTexture = SDL_CreateTextureFromSurface(Renderer, textOutline);

    float winWidthFixed = (float)windowWidth / 640;
    float winHeightFixed = (float)windowHeight / 480;

    destinationRect.x = ( posX * (winWidthFixed) ) - (  ( (text->w) * (winWidthFixed) ) / 2  );
    destinationRect.y = ( posY * (winHeightFixed) ) - (  ( /*(text->h) * */(winHeightFixed) ) / 2  ) + 3;
    destinationRect.w = text->w * (winWidthFixed);
    destinationRect.h = text->h * (winHeightFixed);

    destinationOutlineRect.x = destinationRect.x;
    destinationOutlineRect.y = destinationRect.y;
    destinationOutlineRect.w = destinationRect.w;
    destinationOutlineRect.h = destinationRect.h;

    for (Sint16 y = -3; y     {
        for (Sint16 x = -3; x         {
            destinationOutlineRect.x = destinationRect.x + (x);// * winWidthFixed);
            destinationOutlineRect.y = destinationRect.y + (y);// * winHeightFixed);
            SDL_RenderCopyEx(Renderer, textOutlineTexture, NULL, &destinationOutlineRect, 0, NULL, SDL_FLIP_NONE);
        }
    }

    SDL_RenderCopyEx(Renderer, textTexture, NULL, &destinationRect, 0, NULL, SDL_FLIP_NONE);

    SDL_DestroyTexture(textOutlineTexture);
    SDL_DestroyTexture(textTexture);
    SDL_FreeSurface(text);
    SDL_FreeSurface(textOutline);
}

//-------------------------------------------------------------------------------------------------


No ability to turn off letterboxing makes me have to use above solution.
I'll hit the text drawing function with a hammer some more and see if I can fix the outline problem on window resize.

Thanks!



JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft(R)
Video Game Design Studio
www.16BitSoft.com
_______________________________________________
SDL mailing list
SDL <at> lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
neoaggelos | 16 Aug 07:55 2013
Picon

Re: [SDL2]-SDL_RenderSetLogicalSize-Disable Letterboxing?

Even though I haven't test it, you could try to reset the viewport everytime you get a resize event.

PS. a sarcastic thank you for flooding the mailing list with almost 100-150 lines of code -- you made my day



C is the God's Programming Language
_______________________________________________
SDL mailing list
SDL <at> lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Ryan C. Gordon | 16 Aug 20:59 2013

Re: [SDL2]-SDL_RenderSetLogicalSize-Disable Letterboxing?


> No ability to turn off letterboxing makes me have to use above solution.
> I'll hit the text drawing function with a hammer some more and see if I
> can fix the outline problem on window resize.

Ok, the problem is that if we didn't letterbox, then the game written to 
run at 640x480 is going to distort if we use a whole 1920x1200 display.

You have a few options:
- Don't use the logical size API, and render at the full size of the window.
- Force the window to be a certain aspect ratio (don't let the user 
resize it by dragging the window frame, give a list of resolutions they 
can use, that match the monitor's aspect ratio, in a menu somewhere).
- Use the logical size API, and adjust your rendering to take aspect 
ratio into account.

In a perfect world, Option #1 is your best choice, but it takes more 
work. The logical size API is meant to say "I absolutely need a grid of 
WxH pixels, my game can't function in any other way, can you figure out 
how to make this work right?"  ...it's absolutely a lifesaver in 
moderning older games, but if you're doing new code, consider if you 
shouldn't just take advantage of all available pixels.

Anyhow, those are the options as I see them.

That being said (and having not examined your code), the problem you're 
having doesn't sound like the letterboxing, but rather the some part of 
the rendering...scaling _shouldn't_ affect some piece of the rendering 
and not others, so there's probably a bug somewhere (either in SDL or 
your app).

--ryan.
Gabriel Jacobo | 16 Aug 21:04 2013
Picon

Re: [SDL2]-SDL_RenderSetLogicalSize-Disable Letterboxing?




2013/8/16 Ryan C. Gordon <icculus <at> icculus.org>

No ability to turn off letterboxing makes me have to use above solution.
I'll hit the text drawing function with a hammer some more and see if I
can fix the outline problem on window resize.

Ok, the problem is that if we didn't letterbox, then the game written to run at 640x480 is going to distort if we use a whole 1920x1200 display.

You have a few options:
- Don't use the logical size API, and render at the full size of the window.
- Force the window to be a certain aspect ratio (don't let the user resize it by dragging the window frame, give a list of resolutions they can use, that match the monitor's aspect ratio, in a menu somewhere).
- Use the logical size API, and adjust your rendering to take aspect ratio into account.

In a perfect world, Option #1 is your best choice, but it takes more work. The logical size API is meant to say "I absolutely need a grid of WxH pixels, my game can't function in any other way, can you figure out how to make this work right?"  ...it's absolutely a lifesaver in moderning older games, but if you're doing new code, consider if you shouldn't just take advantage of all available pixels.

Anyhow, those are the options as I see them.

That being said (and having not examined your code), the problem you're having doesn't sound like the letterboxing, but rather the some part of the rendering...scaling _shouldn't_ affect some piece of the rendering and not others, so there's probably a bug somewhere (either in SDL or your app).

--ryan.


You can also probably solve this by using Render Targets. If you are fixed on 640x480 (you shouldn't, but who knows...), you can render everything to a  640x480 texture (a back buffer of sorts), and when you want to show this to the screen you SDL_RenderCopy a cropped version of it to the full screen (sort of like "flipping" the texture to the front).

 
--
Gabriel.
_______________________________________________
SDL mailing list
SDL <at> lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Mason Wheeler | 17 Aug 02:38 2013
Picon

Re: [SDL2]-SDL_RenderSetLogicalSize-Disable Letterboxing?

I figure I ought to weigh in on this, since I came up with the basic idea of the API and pushed to get it included.  And what's in SDL right now is a big, complicated mess that looks very different from what I originally set up.

The idea behind a logical size is that no matter what size the SDL_Window is, you have a consistent-sized array of pixels to render to that will fill that entire window.  (This does mean stretching to fit, if necessary.)  I originally implemented it with a simple call to glOrtho.

What's in there now takes the idea I had and adds all sorts of complications that get in the way more than they help, such as letterboxing and the addition of scaling constants behind the scenes.  The scaling really bugs me; it means that the coordinate system I'm drawing into in SDL is different from the one I'm drawing into if I use OpenGL calls directly!  And since I'm doing about 98% of my rendering with SDL, but I also have some important things to draw that are too complex for the render API, that makes problems for me.

SDL_RenderSetLogicalSize really should simply set the number of drawable pixels in the window equal to the value you passed in, and leave it at that.  Can we fix the current broken implementation please?

Mason

From: Ryan C. Gordon <icculus <at> icculus.org>
To: sdl <at> lists.libsdl.org
Sent: Friday, August 16, 2013 11:59 AM
Subject: Re: [SDL] [SDL2]-SDL_RenderSetLogicalSize-Disable Letterboxing?


> No ability to turn off letterboxing makes me have to use above solution.
> I'll hit the text drawing function with a hammer some more and see if I
> can fix the outline problem on window resize.

Ok, the problem is that if we didn't letterbox, then the game written to
run at 640x480 is going to distort if we use a whole 1920x1200 display.

You have a few options:
- Don't use the logical size API, and render at the full size of the window.
- Force the window to be a certain aspect ratio (don't let the user
resize it by dragging the window frame, give a list of resolutions they
can use, that match the monitor's aspect ratio, in a menu somewhere).
- Use the logical size API, and adjust your rendering to take aspect
ratio into account.

In a perfect world, Option #1 is your best choice, but it takes more
work. The logical size API is meant to say "I absolutely need a grid of
WxH pixels, my game can't function in any other way, can you figure out
how to make this work right?"  ...it's absolutely a lifesaver in
moderning older games, but if you're doing new code, consider if you
shouldn't just take advantage of all available pixels.

Anyhow, those are the options as I see them.

That being said (and having not examined your code), the problem you're
having doesn't sound like the letterboxing, but rather the some part of
the rendering...scaling _shouldn't_ affect some piece of the rendering
and not others, so there's probably a bug somewhere (either in SDL or
your app).

--ryan.


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


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

Gmane