• Advertisement
Sign in to follow this  

Question about loading Textures?

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

Before I start getting into coding my game, I want to make sure I am not doing anything wrong. I am planning to have a class Character that is an abstract class that will be overriden for all types of game characters whether enemy or player character. I am planning on encapsulating the loading of textures into each class that is new class take this for example. class Dwarf : public Character { public: LPDIRECT3DTEXTURE9 enemy_image_walk; LPDIRECT3DTEXTURE9 enemy_image_attack; LPDIRECT3DTEXTURE9 enemy_image_talk; LPDIRECT3DTEXTURE9 enemy_image_run; LPDIRECT3DTEXTURE9 enemy_image_hit; } There will be a lot more than that, but if say I want to create 5 dwarfs each time enemy_image_walk in the class will be loaded with the same texture. I believe I read that DirectX makes sure a texture isn't loaded twice, but I'm not sure. I don't want to waste a lot of memory especially in this RTS which could have 100 or more enemies on screen at once. Also say for example my Dwarf has individual images for every possible animation, so I am hoping to combine them into one big image. I've done it before on my computer, but I know it use to be a problem with some graphics card not being able to load bigger than 256 x 256, is this problem fairly rare now, or should I load all the small sprites and not worry about combining them. For example the Dwarf has about 400 individual frames of animation and are 96 x 96 in size. I am hoping to combine these into similar textures so for example I would take the 50 sprites related to walking and combine them into one large texture.

Share this post


Link to post
Share on other sites
Advertisement
D3D will not make sure the texture is only loaded once. You'll have to do that yourself. The 256x256 texture limit is ancient and really doesn't apply any more. I think it was only the Voodoo 1 series that had that limit. It's usually safe to aim for 1024x1024 or greater (Which I belive is available on GeForce 2+). To fit 400 96x96 frames of animation, you'd need a texture 1920x1920 (So 2048x2048 is the closest power of two). Or you could use 4 1024x1024 textures.

Share this post


Link to post
Share on other sites
The texture size part will make things a lot easier :)

Now I have to figure out how to make sure all the textures are loaded only once. Maybe I will create a global header file that declares all of the Texture names and then have a function that is called upon the game loading that loads all of the textures.

Thanks for the help, I'm glad I asked that question now instead of a month from now when I am tring to figure out why the game is only running at 3 fps :)

Share this post


Link to post
Share on other sites
Quote:
Original post by adam23
Now I have to figure out how to make sure all the textures are loaded only once. Maybe I will create a global header file that declares all of the Texture names and then have a function that is called upon the game loading that loads all of the textures.
The usual way is to have a resource manager (Or just a texture manager). Instead of directly loading the resource, you request it from the manager. The manager will load the resource if needed, and add it to an internal array (usually a std::map). Subsequent requests for that resource will just return the same one, instead of loading new versions.

If you're going for that, it's advisible to make a wrapper class around resources, or at least increment / decrement reference counts on the underlying interface (IDirect3DTexture9 in this case), just to make sure that the texture isn't released early and pulled out from under the feet of objects that are referencing it.

Share this post


Link to post
Share on other sites
Yeah your right, I should probably try and implement a ResourceManager class and have that handle the loading of all my textures. Thanks for the help :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement