Oke.
I'm starting using SDL, and i need an optimized img loading function.
Currently in the new SDL2 there are Renderers, and i'm using the corrisppetivly library SDL_IMAGE to load other types other than BMP.
Now i came across a problem
The only function that convert's an SDL_Surface to a Texture is
SDL_CreateTextureFromSurface(SDL_Renderer*, SDL_Surface*)
I'm also using OOP, so in my Sprite class seems that i need to create a renderer.
I don't find this very appealing, since it's a waste of computational power and resource(yeah, i know, we are in the era of "4gb ram? You are such a pleasant".
Now, there is actually a better way to CreateATextureFromASurface?
Or is the Renderer thing actually, how do i say that "way of the programmer correct"?
1 2 3 4 5 6 7 8 9 10
|
void Sprite::LoadTexture(std::string path)
{
SDL_Surface *surface;
SDL_Renderer *renderer;
surface = IMG_LOAD(path.c_str());
texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
}
|
That not seem optimized.
And is fine to have a renderer, for each Entity?
EDIT.
I'm actually dumber than i thought:
|
void Sprite::LoadTexture(std::string path, SDL_Renderer *ren)
|
but still, it normal to have a renderer for each entity?