dandago
2017-01-05 17:20:57 UTC
This is a snippet from a game I'm developing:
Code:
void BottomRightView::Render()
{
auto renderer = this->GetRenderer();
SDL_DestroyTexture(this->fontTexture);
SDL_FreeSurface(this->fontSurface);
std::string linesStr;
this->player->GetPlayerStateSummary(linesStr);
// TODO recreating these every time seems very inefficient
this->fontSurface = TTF_RenderText_Blended_Wrapped(font, linesStr.c_str(), this->fontColour, 300);
this->fontTexture = SDL_CreateTextureFromSurface(renderer, fontSurface);
SDL_Rect dstrect = { 504, 336, 0, 0 };
SDL_QueryTexture(fontTexture, NULL, NULL, &dstrect.w, &dstrect.h);
SDL_RenderCopy(renderer, this->fontTexture, NULL, &dstrect);
}
Since the player state that I'm drawing to the screen may change at any time, I'm having to create a new surface and texture every frame.
This seems really wasteful. Is there a more efficient way to do this?
------------------------
Daniel D'Agostino
http://gigi.nullneuron.net/gigilabs/
Code:
void BottomRightView::Render()
{
auto renderer = this->GetRenderer();
SDL_DestroyTexture(this->fontTexture);
SDL_FreeSurface(this->fontSurface);
std::string linesStr;
this->player->GetPlayerStateSummary(linesStr);
// TODO recreating these every time seems very inefficient
this->fontSurface = TTF_RenderText_Blended_Wrapped(font, linesStr.c_str(), this->fontColour, 300);
this->fontTexture = SDL_CreateTextureFromSurface(renderer, fontSurface);
SDL_Rect dstrect = { 504, 336, 0, 0 };
SDL_QueryTexture(fontTexture, NULL, NULL, &dstrect.w, &dstrect.h);
SDL_RenderCopy(renderer, this->fontTexture, NULL, &dstrect);
}
Since the player state that I'm drawing to the screen may change at any time, I'm having to create a new surface and texture every frame.
This seems really wasteful. Is there a more efficient way to do this?
------------------------
Daniel D'Agostino
http://gigi.nullneuron.net/gigilabs/