Jump to content
  • Advertisement
Sign in to follow this  

How to store images?

This topic is 4096 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

Hello. I'm using SDL and i got a problem. I have textures that i need to store somewhere. Now its 3 but later i think ill get something like 200-300 textures. I can't create variable for each texture so i tried to store them in an array but i got some strange error so I'm looking for alternative way to store images. I made a class of "block" and each block had his own picture. Can be more then one class with the same picture so i need to load the pictures first and then give each block an address of necessary picture. Suggestions?

Share this post


Link to post
Share on other sites
Advertisement
John has given you a good pointer (hehe :P) there.
std::map<std::string, SDLTexture*> textures;
class TexturableObject { // I think this is your 'Block'?
private: std::string texture; // texture name
... // etc
}


You can use an integer key (hash the string in some way) if string lookups become too slow.

I think there is an SDLTexture class or similar, though I've no experience with SDL so I can't go into any detail.

Share this post


Link to post
Share on other sites
I use MFC in my game engine (strange but true) and get good results with my CTextureMgr class. Right now it's basically a wrapper around a CMap of strings to CTextureObjects, but it also supports some garbage collection and other more advanced stuff.

I actually use a three-level hierarchy in my resource IDs, such as "t-engine.effects.def_particle". (If this sounds a bit like Unreal, you're right - that's what gave me the idea.) The first part ("t-engine") is the package name, the second ("effects") is the category, and "def_particle" is the name of this texture.

To use a texture with my class, I just do this:
g_pEngine->m_textures["t-engine.effects.def_particle"].Bind();

I have similar resource managers for 3DS models and OpenAL audio buffers, and will be creating one for shaders very soon.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!