Proper use of SDL_SetWindowSize

Hello,

I am trying to change the window size of my game after the initial window has already been created.

I’ve looked at a couple examples and I found and tried to use SDL_SetWindowSize(window, 640, 360) to set the window size.
The window size changes but the renderer fails to update at this point. The video freezes at this point and looks like this:

Are there additional steps I need to take after using SDL_SetWindowSize()?

All I am trying to do is resize the window and then I am scaling the previous image x2 to fit the doubled window size.

I found a post saying to try to destroy and remake any textures using SDL_TEXTUREACCESS_TARGET after you do this to fix this issue. I tried this, but it did not help.
[/url]

http://wiki.libsdl.org/SDL_RenderSetLogicalSizeOn Wed, Jan 1, 2014 at 7:50 AM, ronkrepps wrote:

Hello,

I am trying to change the window size of my game after the initial window
has already been created.

I’ve looked at a couple examples and I found and tried to use
SDL_SetWindowSize(window, 640, 360) to set the window size.
The window size changes but the renderer fails to update at this point.
The video freezes at this point and looks like this:

http://i.imgur.com/raWNndM.png

Are there additional steps I need to take after using SDL_SetWindowSize()?

All I am trying to do is resize the window and then I am scaling the
previous image x2 to fit the doubled window size.

I found a post saying to try to destroy and remake any textures using
SDL_TEXTUREACCESS_TARGET after you do this to fix this issue. I tried this,
but it did not help.
[/url]


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

Ivan Rubinson wrote:

http://wiki.libsdl.org/SDL_RenderSetLogicalSize (http://wiki.libsdl.org/SDL_RenderSetLogicalSize)

  Hello,

I am trying to change the window size of my game after the initial window has already been created.

I’ve looked at a couple examples and I found and tried to use SDL_SetWindowSize(window, 640, 360) to set the window size.
The window size changes but the renderer fails to update at this point. The video freezes at this point and looks like this:

http://i.imgur.com/raWNndM.png (http://i.imgur.com/raWNndM.png)

Are there additional steps I need to take after using SDL_SetWindowSize()?

All I am trying to do is resize the window and then I am scaling the previous image x2 to fit the doubled window size.

I found a post saying to try to destroy and remake any textures using SDL_TEXTUREACCESS_TARGET after you do this to fix this issue. I tried this, but it did not help.
[/url]


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

I tried adding this but it made no change.

SDL_SetWindowSize(mWindow, 640, 360);
SDL_RenderSetLogicalSize(mRenderer, 640, 360);> On Wed, Jan 1, 2014 at 7:50 AM, ronkrepps <@ronkrepps (@ronkrepps)> wrote:

SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window = SDL_CreateWindow(“SDL App”, SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 640, 360, SDL_WINDOW_RESIZABLE);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);
SDL_SetHint(SDL_HINT_RENDERER_SCALE_QUALITY, “linear”);
SDL_RenderSetLogicalSize(renderer, 640, 360);On Wed, Jan 1, 2014 at 10:31 AM, ronkrepps wrote:

Ivan Rubinson wrote:

http://wiki.libsdl.org/SDL_RenderSetLogicalSize

On Wed, Jan 1, 2014 at 7:50 AM, ronkrepps <> wrote:

Quote:

Hello,

I am trying to change the window size of my game after the initial window
has already been created.

I’ve looked at a couple examples and I found and tried to use
SDL_SetWindowSize(window, 640, 360) to set the window size.
The window size changes but the renderer fails to update at this point.
The video freezes at this point and looks like this:

http://i.imgur.com/raWNndM.png

Are there additional steps I need to take after using SDL_SetWindowSize()?

All I am trying to do is resize the window and then I am scaling the
previous image x2 to fit the doubled window size.

I found a post saying to try to destroy and remake any textures using
SDL_TEXTUREACCESS_TARGET after you do this to fix this issue. I tried this,
but it did not help.
[/url]


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I tried adding this but it made no change.

SDL_SetWindowSize(mWindow, 640, 360);
SDL_RenderSetLogicalSize(mRenderer, 640, 360);


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

PS: This is initialization code. Don’t change it later. When the window is
resized, the renderer will take care of the rest implicitly.On Wed, Jan 1, 2014 at 4:09 PM, Ivan Rubinson <@Ivan_Rubinson> wrote:

SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window = SDL_CreateWindow(“SDL App”, SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 640, 360, SDL_WINDOW_RESIZABLE);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);
SDL_SetHint(SDL_HINT_RENDERER_SCALE_QUALITY, “linear”);
SDL_RenderSetLogicalSize(renderer, 640, 360);

On Wed, Jan 1, 2014 at 10:31 AM, ronkrepps wrote:

Ivan Rubinson wrote:

http://wiki.libsdl.org/SDL_RenderSetLogicalSize

On Wed, Jan 1, 2014 at 7:50 AM, ronkrepps <> wrote:

Quote:

Hello,

I am trying to change the window size of my game after the initial window
has already been created.

I’ve looked at a couple examples and I found and tried to use
SDL_SetWindowSize(window, 640, 360) to set the window size.
The window size changes but the renderer fails to update at this point.
The video freezes at this point and looks like this:

http://i.imgur.com/raWNndM.png

Are there additional steps I need to take after using SDL_SetWindowSize()?

All I am trying to do is resize the window and then I am scaling the
previous image x2 to fit the doubled window size.

I found a post saying to try to destroy and remake any textures using
SDL_TEXTUREACCESS_TARGET after you do this to fix this issue. I tried this,
but it did not help.
[/url]


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I tried adding this but it made no change.

SDL_SetWindowSize(mWindow, 640, 360);
SDL_RenderSetLogicalSize(mRenderer, 640, 360);


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

Initialization:

SDL_Init(SDL_INIT_EVERYTHING);
IMG_Init(IMG_INIT_PNG);

SDL_Window window = SDL_CreateWindow(windowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, SDL_WINDOW_RESIZABLE);
SDL_Renderer
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, “linear”);
SDL_RenderSetLogicalSize(renderer, 640, 360);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);

Called every frame:

SDL_RenderClear(mRenderer);

//render the current screen
//just some SDL_RenderCopy() calls to get sprites, etc. to the screen
mScreenManager->Render();

SDL_RenderPresent(mRenderer);

This is the code I am using and unfortunately I am getting the same problem.
As soon as I resize the window, with either dragging the window border or programmatically using SDL_SetWindowSize() the video stops responding, even though I am still rendering frames and the program is still running fine otherwise.

Here’s a video I uploaded that hopefully makes it clearer:

Can I see mScreenmanager->Render()?On Thu, Jan 2, 2014 at 3:48 AM, ronkrepps wrote:

Initialization:

SDL_Init(SDL_INIT_EVERYTHING);
IMG_Init(IMG_INIT_PNG);

SDL_Window window = SDL_CreateWindow(windowName, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, SDL_WINDOW_RESIZABLE);
SDL_Renderer
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, “linear”);
SDL_RenderSetLogicalSize(renderer, 640, 360);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);

Called every frame:

SDL_RenderClear(mRenderer);

//render the current screen
//just some SDL_RenderCopy() calls to get sprites, etc. to the screen
mScreenManager->Render();

SDL_RenderPresent(mRenderer);

This is the code I am using and unfortunately I am getting the same
problem.
As soon as I resize the window, with either dragging the window border or
programmatically using SDL_SetWindowSize() the video stops responding, even
though I am still rendering frames and the program is still running fine
otherwise.

Here’s a video I uploaded that hopefully makes it clearer:

http://www.youtube.com/watch?v=QPMse8GdCAI


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

The mScreenManager->Render() calls all of the render functions for the current screen.
On the title screen it is:

Code:
if(mAnimated)
{
RenderSprite(“BeachTop”, BG_TOP_X, BG_TOP_Y);
RenderSprite(“BeachBottom”, BG_BOTTOM_X, BG_BOTTOM_Y);
mWaves->Render();

	std::vector< Cloud* >::iterator cloudIt;

	for (cloudIt = mClouds.begin(); cloudIt != mClouds.end(); ++cloudIt)
	{
		(*cloudIt)->Render();
	}
}
else
	RenderSprite("BeachNonAnimated", BG_TOP_X, BG_TOP_Y);

if(mMenu == OPTMENU_TITLE)
{
	RenderSprite("TextBackground", TEXT_BACKGROUND1_X, TEXT_BACKGROUND1_Y);
	RenderSprite("TextBackground", TEXT_BACKGROUND2_X, TEXT_BACKGROUND2_Y);
	RenderSprite("TextBackground", TEXT_BACKGROUND3_X, TEXT_BACKGROUND3_Y);
	RenderSprite("TextBackground", TEXT_BACKGROUND4_X, TEXT_BACKGROUND4_Y);
}
else if(mMenu == OPTMENU_GAMEMODE || mMenu == OPTMENU_NORMAL)
{
	RenderSprite("HeaderBackground", HEADER1_X, HEADER1_Y);

	if (!mBackArrowIsHighlighted)
		RenderSprite("BackArrow", BACKBUTTON_X, BACKBUTTON_Y);
	else
		RenderSprite("BackArrowHighlighted", BACKBUTTON_X, BACKBUTTON_Y);

	if(mMenu == OPTMENU_GAMEMODE)
	{
		RenderSprite("TextBackground", OPTION1_X, OPTION1_Y);
		RenderSprite("TextBackground", OPTION2_X, OPTION2_Y);
		RenderSprite("TextBackground", OPTION3_X, OPTION3_Y);
		RenderSprite("Description", DESCRIPTION_X, DESCRIPTION_Y);
	}
	else if(mMenu == OPTMENU_NORMAL)
	{
		RenderSprite("TextBackground", OPTION1_X, OPTION1_Y);

		if (!mDecreaseLevel)
			RenderSprite("Decrease", OPTION1_DECREASE_X, OPTION1_DECREASE_Y);
		else
			RenderSprite("DecreasePushed", OPTION1_DECREASE_X, OPTION1_DECREASE_Y);

		if (!mIncreaseLevel)
			RenderSprite("Increase", OPTION1_INCREASE_X, OPTION1_INCREASE_Y);
		else
			RenderSprite("IncreasePushed", OPTION1_INCREASE_X, OPTION1_INCREASE_Y);

		RenderSprite("TextBackground", OPTION3_X, OPTION3_Y);
	}
}
else if(mMenu == OPTMENU_PUZZLECATEGORY)
{
	RenderSprite("HeaderBackground", HEADER1_X, HEADER1_Y);
	RenderSprite("CategoryBackground", PUZZLECATBG_X, PUZZLECATBG_Y);

	if (!mBackArrowIsHighlighted)
		RenderSprite("BackArrow", BACKBUTTON_X, BACKBUTTON_Y);
	else
		RenderSprite("BackArrowHighlighted", BACKBUTTON_X, BACKBUTTON_Y);

	if(!mPreviousCategory)
		RenderSprite("PreviousCategory", PUZZLECATLEFT_X, PUZZLECATLEFT_Y);
	else
		RenderSprite("PreviousCategoryPushed", PUZZLECATLEFT_X, PUZZLECATLEFT_Y);
	if(!mNextCategory)
		RenderSprite("NextCategory", PUZZLECATRIGHT_X, PUZZLECATRIGHT_Y);
	else
		RenderSprite("NextCategoryPushed", PUZZLECATRIGHT_X, PUZZLECATRIGHT_Y);

}
else if(mMenu == OPTMENU_PUZZLE)
{
	RenderSprite("HeaderBackground", HEADER1_X, HEADER1_Y);

	if (!mBackArrowIsHighlighted)
		RenderSprite("BackArrow", BACKBUTTON_X, BACKBUTTON_Y);
	else
		RenderSprite("BackArrowHighlighted", BACKBUTTON_X, BACKBUTTON_Y);

	RenderSprite("PuzzleListBackground", PUZZLELIST_X, PUZZLELIST_Y);

	if(!mDecreaseLevel)
		RenderSprite("PuzzleListUp", PUZZLELISTUP_X, PUZZLELISTUP_Y);
	else
		RenderSprite("PuzzleListUpPushed", PUZZLELISTUP_X, PUZZLELISTUP_Y);
	if(!mIncreaseLevel)
		RenderSprite("PuzzleListDown", PUZZLELISTDOWN_X, PUZZLELISTDOWN_Y);
	else
		RenderSprite("PuzzleListDownPushed", PUZZLELISTDOWN_X, PUZZLELISTDOWN_Y);

	for(int i = 0; i < PUZZLE_LINE_COUNT; i++)
	{
		if(mScreenManager->CheckPuzzleStatus((mCurrentPuzzleLine - 1) + i) == CATSTAT_PERFECT)
			RenderSprite("Checkmark", mPuzzleEntryCheckmarkLoc[i].x, mPuzzleEntryCheckmarkLoc[i].y);
	}

	RenderSprite("TextBackground", START_X, START_Y);
}
else if(mMenu == OPTMENU_OPTIONS)
{
	if (!mBackArrowIsHighlighted)
		RenderSprite("BackArrow", BACKBUTTON_X, BACKBUTTON_Y);
	else
		RenderSprite("BackArrowHighlighted", BACKBUTTON_X, BACKBUTTON_Y);

	RenderSprite("HeaderBackground", HEADER1_X, HEADER1_Y);
	RenderSprite("TextBackground", OPTION1_X, OPTION1_Y);

	if (!mDecreaseSound)
		RenderSprite("Decrease", OPTION1_DECREASE_X, OPTION1_DECREASE_Y);
	else
		RenderSprite("DecreasePushed", OPTION1_DECREASE_X, OPTION1_DECREASE_Y);

	if (!mIncreaseSound)
		RenderSprite("Increase", OPTION1_INCREASE_X, OPTION1_INCREASE_Y);
	else
		RenderSprite("IncreasePushed", OPTION1_INCREASE_X, OPTION1_INCREASE_Y);

	RenderSprite("TextBackground", OPTION4_X, OPTION4_Y);
	RenderSprite("TextBackground", OPTION5_X, OPTION5_Y);
	RenderSprite("TextBackground", OPTION6_X, OPTION6_Y);

	RenderSprite("TextBackground", OPTION7_X, OPTION7_Y);
	RenderSprite("TextBackground", OPTION8_X, OPTION8_Y);
	RenderSprite("TextBackground", OPTION9_X, OPTION9_Y);
}
else if(mMenu == OPTMENU_SCORES)
{
	RenderSprite("HeaderBackground", HEADER1_X, HEADER1_Y);

	RenderSprite("ScoresTextBackground", HIGHSCORE_TEXTBG_X, HIGHSCORE_TEXTBG_Y);

	if(!mGameOver)
	{
		if (!mBackArrowIsHighlighted)
			RenderSprite("BackArrow", BACKBUTTON_X, BACKBUTTON_Y);
		else
			RenderSprite("BackArrowHighlighted", BACKBUTTON_X, BACKBUTTON_Y);
	}
	else
	{
		if (mNewScore > -1)
			RenderSprite("ScoresHighlight", mScoreHightlightLocs[mNewScore].x, mScoreHightlightLocs[mNewScore].y);

		RenderSprite("TextBackground", HIGHSCORE_OPTION1_X, HIGHSCORE_OPTION1_Y);
		RenderSprite("TextBackground", HIGHSCORE_OPTION2_X, HIGHSCORE_OPTION2_Y);
	}
}

mTextManager->Render(0);

if(mAnimated)
{
	std::vector< Bubble* >::iterator bubbleIt;

	for (bubbleIt = mBubbles.begin(); bubbleIt != mBubbles.end(); ++bubbleIt)
	{
		(*bubbleIt)->Render();
	}
}

if(mMenu == OPTMENU_TITLE)
	RenderSprite("TitleScreenText", TITLE_TEXT_X, TITLE_TEXT_Y);

RenderSprite():

Code:

SDL_Rect s;
SetSpriteSourceRect(spriteReference, &s);

SDL_Rect d;
d.x = x;
d.y = y;
d.w = s.w;
d.h = s.h;

SDL_RenderCopy(mRenderer, GetTexture(TextureType_Sprite, spriteReference), &s, &d);

Do you need me to go deeper and post more functions?

If there’s nothing apparent that I am doing incorrectly I can make a new project and cut out everything unnecessary and see if it’s still not working. Then post that.

Your code is very messy, I’ll give you that.
I think you should make a test-case. If it works in the test-case, you’ll
know that the problem is somewhere in your code. Then it’s a simple matter
of pin-pointing the cause.On Thu, Jan 2, 2014 at 8:09 AM, ronkrepps wrote:

If there’s nothing apparent that I am doing incorrectly I can make a new
project and cut out everything unnecessary and see if it’s still not
working. Then post that.


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

After going through line by line I found the problem. It’s the SDL_TEXTUREACCESS_TARGET flag that I read about in the other posts. In order to get it to work I need to not ever create a texture with this flag.

I tried the workaround earlier (which is to destroy the textures and remake them after changing the window size) and it doesn’t work. Going to work on this and see if I can come up with a different solution. Thanks for your help though and I’m open to any other workarounds for this that you know of.

You need to do things in this order
(a) ResizeWindow
(b) Destroy RenderAccess Textures
© Reset Video Device
(d) Re-create textures

Steps (a) & (b) can be interchanged.
Let me know of your progress on this.On 1/2/2014 3:29 PM, ronkrepps wrote:

After going through line by line I found the problem. It’s the
SDL_TEXTUREACCESS_TARGET flag that I read about in the other posts. In
order to get it to wohinrk I need to not ever create a texture with
this flag.

I tried the workaround earlier (which is to destroy the textures and
remake them after changing the window size) and it doesn’t work. Going
to work on this and see if I can come up with a different solution.
Thanks for your help though and I’m open to any other workarounds for
this that you know of.


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


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming

Pallav Nawani wrote:

You need to do things in this order
(a) ResizeWindow
(b) Destroy RenderAccess Textures
© Reset Video Device
(d) Re-create textures

Steps (a) & (b) can be interchanged.
Let me know of your progress on this.

Okay I understand everything except “Reset Video Device” can I do this with SDL?

The SDL renderer tries to reset the video device when you try to render
with it. So to reset the video device try:

SDL_RenderPresent(aRenderer);
SDL_RenderClear(aRenderer);On 1/3/2014 5:51 PM, ronkrepps wrote:

Pallav Nawani wrote:
You need to do things in this order
(a) ResizeWindow
(b) Destroy RenderAccess Textures
© Reset Video Device
(d) Re-create textures

Steps (a) & (b) can be interchanged.
Let me know of your progress on this.

Okay I understand everything except “Reset Video Device” can I do this
with SDL?


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


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming

Pallav Nawani wrote:

The SDL renderer tries to reset the video device when you try to render
with it. So to reset the video device try:

SDL_RenderPresent(aRenderer);
SDL_RenderClear(aRenderer);

Worked like a charm. I just had to do the RenderClear, RenderPresent once before recreating the textures, like you said.
The only thing is once I’ve changed the window size all no alpha rendering works.

ronkrepps wrote:

Pallav Nawani wrote:

The SDL renderer tries to reset the video device when you try to render
with it. So to reset the video device try:

SDL_RenderPresent(aRenderer);
SDL_RenderClear(aRenderer);

Worked like a charm. I just had to do the RenderClear, RenderPresent once before recreating the textures, like you said.
The only thing is once I’ve changed the window size all no alpha rendering works.

Found a patched DLL in this thread that works to fix this issue:
forums.libsdl.org/viewtopic.php?t=9406
I’d imagine this might be fixed in the 2.0.1 SDL code that I don’t have yet.

Thanks for your help.