[SDL2]-“SDL_GetWindowSize” On Resize Not Working?
Hi,
“SDL_GetWindowSize” does not seem to recognize when the SDL2 window is resized manually?
It works fine when the SDL2 window is maximized but not on a manual resize?
Here is my code to draw a sprite:
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);
destinationRect.x = ( Sprites[index].ScreenX * (windowWidth/640) ) - ( ( (textureWidth * Sprites[index].ScaleX) * (windowWidth/640) ) / 2 );
destinationRect.y = ( Sprites[index].ScreenY * (windowHeight/480) ) - ( ( (textureHeight * Sprites[index].ScaleY) * (windowHeight/480) ) / 2 );
destinationRect.w = textureWidth * Sprites[index].ScaleX * (windowWidth/640);
destinationRect.h = textureHeight * Sprites[index].ScaleY * (windowHeight/480);
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_RenderPresent(Renderer); // temporary...
SDL_SetTextureBlendMode(Sprites[index].Texture, SDL_BLENDMODE_NONE);
SDL_SetTextureAlphaMod(Sprites[index].Texture, 255);
SDL_SetTextureColorMod(Sprites[index].Texture, 255, 255, 255);
}
//-------------------------------------------------------------------------------------------------
Any help would be appreciated, thanks!------------------------
JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com