How to store images?

Started by
3 comments, last by nemesisgeek 17 years, 1 month ago
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?

I would love to change the world, but they won’t give me the source code.

Advertisement
Using an array is going in the right direction, but it is probably not sufficient. Look up std::vector and std::map (assuming C++).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Ok thanks i'll check. Any more suggestions?

I would love to change the world, but they won’t give me the source code.

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.
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.
hackerkey://v4sw7+8CHS$hw6+8ln6pr8O$ck4ma4+9u5Lw7VX$m0l5Ri8ONotepad++/e3+8t3b8AORTen7+9a17s0r4g8OP

This topic is closed to new replies.

Advertisement