Skip to main content
GameDev.net gamedev.net
🔒 Locked

Textures

Started by adam17 Dec 22, 2002 at 1:27 AM 2 replies 250+ views
Original Post
adam17
adam17
Can someone point me in the right direction for loading a dynamic number of textures into my program? Basically what i want to do is take a given list of textures, with their names, and then from that list load the textures into memory. it sounds simple but i am not at all familiar with reading files or lists.
LockePick
LockePick
I assume you''re using NeHe''s code at the moment?

All his code does is return an int which is used to tell OpenGL which texture you want. To use a dynamic amount of textures, you just need to use something which can dynamically resize to hold data. An std::vector would work fine.

------------
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
"It''s all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."
adam17
adam17
could you be a little more descriptive about the std::vector thing. is that just a generalization or what?
CodeFish
CodeFish
A standard library vector is just a fancy array of sorts. What you need are two things. 1) a way of opening a file, and parsing through it for the texture names and 2) a way to store those texture ID''s once you have them loaded. Opening a file is very easy (in windows anyway). Looking into fopen() and fread(). For storing them, it depends on how you want to use them, and if you will ever know exactly how many. For example, if you are loading all the textures in one text file, you could parse through the text file, see how many textures are there, and then create an array of that size to hold all their ID''s. Or, depending on how complicated you want to get, take it one step further and include a small amount of header information in the text file indicating how many textures are contained within it. If you need some sort of dynamic way of handling them, then I''d recommend making your own dynamic array or linked list, depending on the usage. If it''s something that you''re going to be randomly accessing all the time, you don''t want the extra expense of parsing a linked list. However if you''re just doing syncronous lookups, a linked list with an iterator would do fine.

Hope that helps, feel free to email me directly if you have any other questions about it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.