Я включил все важные файлы SDL (текст, изображение и т. Д.).Я знаю, что это работает, потому что когда я помещаю простой код из учебника (что-то вроде «все в основную» все еще работает).Но я пытаюсь поместить это в класс.Когда я использую отладчик, кажется, все в порядке.Но я не вижу текст на экране ...
class Text
{
/* ===Objects=== */
private:
SDL_Texture* textTexture;
SDL_Rect textRect;
/* ===Methods=== */
public:
void init(const std::string& fontPath, int fontSize, const std::string& message, const SDL_Color& color, const std::shared_ptr<SDL_Renderer>& renderer);
void display(const std::shared_ptr<SDL_Renderer>& renderer);
SDL_Texture* setText(const std::string& fontPath, int fontSize, const std::string& message, const SDL_Color& color, const std::shared_ptr<SDL_Renderer>& renderer);
void setPosition(const Vector2<float>& position);
};
#include "Text.hpp"
void Text::init(const std::string & fontPath, int fontSize, const std::string & message, const SDL_Color & color, const std::shared_ptr<SDL_Renderer>& renderer)
{
textTexture = setText(fontPath, fontSize, message, color, renderer);
SDL_QueryTexture(&*textTexture, nullptr, nullptr, &textRect.w, &textRect.h);
}
void Text::display(const std::shared_ptr<SDL_Renderer>& renderer)
{
SDL_RenderCopy(&*renderer, &*textTexture, nullptr, &textRect);
}
SDL_Texture* Text::setText(const std::string & fontPath, int fontSize, const std::string & message, const SDL_Color & color, const std::shared_ptr<SDL_Renderer>& renderer)
{
TTF_Font* font = TTF_OpenFont(fontPath.c_str(), fontSize);
auto textSurface = TTF_RenderText_Solid(font, message.c_str() , color);
auto tempTexture = SDL_CreateTextureFromSurface(&*renderer, textSurface);
SDL_FreeSurface(textSurface);
TTF_CloseFont(font);
return tempTexture;
}
void Text::setPosition(const Vector2<float>& position)
{
textRect.x = position.x - textRect.w / 2.f;
textRect.y = position.y - textRect.h / 2.f;
}
Может кто-нибудь представить меня, как я могу решить эту проблему?