Sign in to follow this  

How to store images?

Recommended Posts

skwee    337
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
Bob Janova    769
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
nemesisgeek    139
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:

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this