Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Making a texture manager (C++) (OpenGL)

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

Okay first off this is my first post here . Next, I''m thinking about making a texture manager for my Pong-Type game, in C++ using OpenGL. I''m looking for the best way to make one. I''m using many of the same textures over. But right now I have all my textures implanted into my class as in each block has it''s own texture. This is probably very inefficient. Now I want to make a texture manager but currently all my classes have Texture objects would Create say like 3 different textures at run-time and then assigning those to the classes'' texture object speed it up or not? Say something like this //Init the textures TextureOne.Load("texture1.bmp"); TextureTwo.Load("texture2.bmp"); TextureThree.Load("texture3.bmp"); //Assign the textures Block[1].Texture = TextureOne; Block[2].Texture = TextureOne; //and so on I haven''t studied much optimizing so I don''t know how I can make a efficient one, so please help. -GoldMage

Share this post

Link to post
Share on other sites
I use a fairly simple texture manager that uses an std::map to map texture filenames to OpenGL texture handles. Any time an object requests a texture to be loaded, the handler first checks to see if it has already been loaded, and returns the already loaded handle for use if so. If not, it loads the texture, creates a new map entry, and returns the handle. Each entry also tracks a reference count of the number of objects that have requested it, decrementing this count when it is released. When a texture''s reference count hits 0, that texture is unloaded.

With a system like this, it is easy to iterate through your map at program exit to see if any textures have not been properly released. Filenames can be printed to indicate which textures were not properly released, then the textures can be deleted to avoid memory leaks.

Blender--The Gimp--Python--Lua--SDL

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!