Archived

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

Valcar

Custom Graphic Resource File: how to?

Recommended Posts

Valcar    122
I''ve been working a lot lately with textures, and every time I load a texture from a file I grit my teeth a little bit. I know that eventually I''m not going to want to load every graphic in the game from a file (.bmp, .tga, etc.). So I wanted to create a Texture Handler, which has a list of all the textures(in texture form) that was in a resource file, that was loaded at the game''s start up. That way I could also do some encryption to keep prying eyes out of the graphics file, if I so desired. I am fairly certain how to save multiple graphics into a single file, and how to load the pixel information from the file into memory, but my question is what is the best way to get it from memory into a texture. I have written a function in the past, that blitted from 1 texture to another texture using memcpy, but it was problematic because it didn''t work on every system. Texture1->LockRect(0, &SrcRect, &SrcBltArea, D3DLOCK_READONLY|D3DLOCK_NOSYSLOCK ); Texture2->LockRect(0, &DestRect, NULL, 0 ); byte *src = (byte *)SrcRect.pBits; byte *dest = (byte *)DestRect.pBits; for (int i = 0; i < 64; i++) { memcpy(dest, src, 64*4); src += SrcRect.Pitch; dest += DestRect.Pitch; } Texture2->UnlockRect(0); Texture1->UnlockRect(0); I figured that that, was because I was assuming the size of the memory on all video cards, which is what I''m trying to avoid on this new project. If you can offer any input on this subject, or know of any informative tutorials I''m all ears. Thank you for reading. I understand it may be difficult to understand what I''m asking for, so basically: A way to safely write information to a texture from memory either in a bitmap struct, or even a simple array. And any suggestions on how you would store the graphics in a file to be loaded.

Share this post


Link to post
Share on other sites
Corrosive    122
Hi, i think maybe you should try to use more dinamycally your code, dont use constants like 64, by the way i dont know what 64 means.. for further development its better to typedef this type of constants.. and try to make a function to retrieve the memory available and things like that, this way your program will handle with every case since its not confined to a constant size.

I hope it helps a little. I dont know DirectX very well yet to put some code here...

To code is to make things come to life

Share this post


Link to post
Share on other sites
Corrosive    122
Hi, i think maybe you should try to use more dinamycally your code, dont use constants like 64, by the way i dont know what 64 means.. for further development its better to typedef this type of constants.. and try to make a function to retrieve the memory available and things like that, this way your program will handle with every case since its not confined to a constant size.

I hope it helps a little. I dont know DirectX very well yet to put some code here...

One more thing, Blt or BltFast isnt faster than memcpy? just a guess...

To code is to make things come to life

Share this post


Link to post
Share on other sites
Valcar    122
Sorry, to clarify 64 would be the width of the texture, and 4 would be the bytes required for the DWORD ARGB color of each pixel on that texture.
On that note, part of this question isn''t DirectX specific, part of it asks if anyone sees any reason that the following code shouldn''t work on all video cards (Simi-DirectX specific) And the other part of the question asks for the best suggestion as to the best way to create a custom resource file, meaning a file that has several graphics all in 1 file, and then is parsed at run time and loaded into all the textures the game needs.

Share this post


Link to post
Share on other sites