SFML community forums

Help => General => Topic started by: MrOnlineCoder on August 22, 2016, 07:56:36 pm

Title: Using same textures for different things
Post by: MrOnlineCoder on August 22, 2016, 07:56:36 pm
Hello. In what way should I organize my code to make reusable things? For example, I have level browser, where every level icon is drawn on texture-background. How to make it easy to make and use both for me and PC CPU/GPU?
Title: Re: Using same textures for different things
Post by: Mr_Blame on August 22, 2016, 09:10:00 pm
I do not understand you... N amount of different graphics entity can reference same to the texture.
Title: Re: Using same textures for different things
Post by: man'O'war on August 22, 2016, 09:15:58 pm
Hi,

I can't really see through your text ... but i am answering according to your question.

You can use a Resource Manager in order to load resource and keep track of them through an id. ( for reuse purpose )

A resource manager loads a resource ( ex: sf::Texture ) and binds it to an id. generally in map container. O(1) complexity
any time you want to use the resource. you can ask the resource manager for it and get it through its id

an example would be.
ResourceManager rm;
rm.load(2, texture1);
rm.load(1, texture2);

sf::Sprite sprt;
sprt.loadFromTexture( rm.get(2) );

// further. you can deallocate an unused ressource
rm.unload(2);
 
Title: Re: Using same textures for different things
Post by: MrOnlineCoder on August 22, 2016, 09:44:59 pm
Thanks, that helped me.