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 < 4; y+=1)
{
for (Sint16 x = -3; x < 4; x+=1)
{
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®
Video Game Design Studio
www.16BitSoft.com