Hello all, I’ve been trying to implement a mutli-class system using SDL2
but I’ve run into a bit of a brick wall using SDL2’s renderer, window,
and texture structures and functions (using C++). What I’m trying to do is have two
seperate classes Entity
and Window
both share the renderer (as I’ve
assumed this is how the renderer is supposed to be used more or less).
I’ve tried setting the renderer globally and have them inherited to both
aEntity
and Window
and then use get functions for
these but I would end up with either multiple windows or entities. How
could/should I use renderer? (Sorry if my question is vague in detail or
if I sound like I should read a book on c++ and classes 101).
Example of a function of Entity:
int Entity::LoadSprite(const char *File)
{
opt = IMG_LoadTexture(`RENDERER NEEDED, File);
if (&opt == NULL) {
std::cout << "Could not load sprite\n";
std::cout << SDL_GetError() << "\n";
return (-1);
}
else if (&opt != NULL) {
std::cout << "Sprite " << File << " loaded\n";
std::cout << SDL_GetError() << "\n";
}
return 0;
}
void Entity::Draw()
{
SDL_RenderPresent(RENDERER NEEDED
);
}