Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Using same textures for different things  (Read 2103 times)

0 Members and 1 Guest are viewing this topic.

MrOnlineCoder

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Using same textures for different things
« 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?

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Using same textures for different things
« Reply #1 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.

man'O'war

  • Newbie
  • *
  • Posts: 46
  • What needs to be done is done by those capable.
    • View Profile
Re: Using same textures for different things
« Reply #2 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);
 

MrOnlineCoder

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: Using same textures for different things
« Reply #3 on: August 22, 2016, 09:44:59 pm »
Thanks, that helped me.