I am making a C++ SDL game engine, where I am wrapping every SDL function into my…
- User
I am making a C++ SDL game engine, where I am wrapping every SDL function into my library and adding my own methods to it. Right now, I am finishing the Renderer class, and to do so I added the related classes like Point, Rect, Line, Circle, etc. and so far is going as I planned. The problem I found when reading the SDL_Renderer docs is that there is a function called SDL_RenderGeometry. And so far I think it has two functionalities into one, but I am not quite sure, since it has an optional texture param which I don't know what it is for. Another thing is that is has an SDL_Vertex class too, which I haven't created my own now. What should I do in this case, should I make it or this is not really needed? If so, I will have to create my own Vertex class, right?
- Assistant
- User
OK I will try to add it, but shouldn't I make two functions instead of one, one that uses a texture and one without or should I keep it like its original with one function and an optional texture? I created my own texture class and passing an object don't know if it can have a nullptr value
- Assistant
- User
Ok I ended up doing something but I don't know how can I deal with these many functions overloads: void RenderGeometry(const std::vector& vertices); void RenderGeometry(const std::vector& vertices, const std::vector& indices); void RenderGeometry(const std::vector& vertices, const Texture& texture); void RenderGeometry(const std::vector& vertices, const std::vector& indices, const Texture& texture);
each one call a different SDL_RenderGeometry alternative. Is correct to leave it like this or should I do something to avoid this many methods?
- Assistant
- User
OK I will keep it with the overloads as I want it to be clear and easy to use. Now my last function is RenderText, how can I do something like this using SDL:
void RenderText(const std::string& text, Font& font, const Color& color, const Point& position);
- Assistant
- User
OK this is what I need, I already have a resource manager that deals with surface, should I add a function there that get a text surface too?
public: Surface& GetSurface(const std::string& filePath);
private: std::unordered_map<std::string, Surface> surfaces;Surface& ResourceManager::GetSurface(const std::string& filePath) { auto it = surfaces.find(filePath); if (it == surfaces.end()) { try { auto result = surfaces.emplace(filePath, Surface(filePath)); it = result.first; } catch (const std::runtime_error& e) { SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to load surface: %s\n", e.what());
throw; } } return it->second;}
- Assistant
- User
OK you are correct, I don't want to cache the fonts, so I will just keep it in memory use them and free them in RenderText directly?
- Assistant
- User
OK I will try that, but first I need to define the Font class, I don't know if I should store the size or not, so far this is what I have:
#include <SDL_ttf.h>
class Font { public: Font(const std::string& filePath, int size); virtual ~Font(); int GetSize() const; TTF_Font* GetFont() const;
private: TTF_Font* font; int size;};
I know the color is related to the text not the font, right?
- Assistant
Yes, that's correct. The color is typically associated with the specific instance of rendered text, not with the font itself. The font object generally encapsulates the typeface and size information, whereas color is a parameter you use when rendering the text.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.