Jump to content
  • Advertisement
Sign in to follow this  
Agreon

Loading Graphics with the help of extern files

This topic is 2109 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey,

I always create an huge enum in my project and one function where all the 'loadTexture' functions are called. I think its not the best way so i thougt i could easy read the img src from an extern file (url:foo.png name:TEXTURE_TREE).

The only problem is: I still have to declare the enum. ( In there are some values like 'TEXTURE_TREE' and so on that are called on orher places). Is there a way to automatically fill this enum, or do you have a better idea?

 

thanks,

 

Daniel

Share this post


Link to post
Share on other sites
Advertisement

Hey,

I always create an huge enum in my project and one function where all the 'loadTexture' functions are called. I think its not the best way so i thougt i could easy read the img src from an extern file (url:foo.png name:TEXTURE_TREE).

The only problem is: I still have to declare the enum. ( In there are some values like 'TEXTURE_TREE' and so on that are called on orher places). Is there a way to automatically fill this enum, or do you have a better idea?

 

thanks,

 

Daniel

Share this post


Link to post
Share on other sites

The only problem is: I still have to declare the enum.

No, you only think you do.

Try using an associative container such as map or unordered_map and refer to the textures as strings:
// load resources
map<string,texture> atlas;
for each ( line in file ) {
    atlas[line.name] = texture::load(line.uri);
}

// get resource
const texture& imgTree = atlas["TEXTURE_TREE"];

Share this post


Link to post
Share on other sites

Typically you would use an associative container (std::map or similar) to map the filename to an ID which is assigned sequentially by the texture loader, then you get the ID back after loading by looking it up in the map. You should only get the ID once and remember it in a variable though, to avoid doing the string to ID lookup all the time.

 

So

 

LoadTexture("TEXTURE_TREE"); // this loads the texture and automatically assigns the next available ID if it isn't already loaded and already got an ID

 

after loading

 

tex_tree_id = GetTextureID("TEXTURE_TREE");

 

and then use tex_tree_id wherever you would use the enum value. You can't use variables in switch statements, however, so you will need to refactor any code that does that.

 

And don't double post, ask a mod to delete your other thread.

Share this post


Link to post
Share on other sites

I made a reply similar to the above in the other identical thread in For Beginners. One of these threads needs to be deleted or they need to be merged. Don't double post threads in different forums.

Share this post


Link to post
Share on other sites

And don't double post, ask a mod to delete your other thread.

 

How to delete or merge a post?

Share this post


Link to post
Share on other sites

Dunno, the best way is not to do it in the first place ;)

 

You could PM rip-off who is a moderator and is on the forum right now, or you could report a post in this thread and ask for it to be closed, not sure if that is seen as a valid reason to report though. Or you could wait until a moderator sees the thread and closes one of them (probably this one since it only has my reply and discussion about double posting).

 

EDIT: Looks like it has been merged already. Now don't do it again!

Edited by Paradigm Shifter

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!