Sign in to follow this  
The Lion King

Loading Textures from PAK File

Recommended Posts

The Lion King    115
How do I load textures from a PAK File? Using a simple function like D3DXCreateTextureFromFileInMemory()? I have a temporary BYTE Buffer and TextBuffer at the same time in the same function. I decrypt the data and write it to a file. (Writing to the file is for testing purposes to check wether I have the valid data in TextBuffer or not) File is OK. And I can load it form that file. But I want to do it all in memory. BYTE* FilePointer = NULL; FilePointer = new BYTE [CurrentFileTable->FileSize]; char *TxtBuffer = new char [CurrentFileTable->FileSize]; So If I dont want to write my TxtBuffer to the file ... instead I just want to copy that to FilePointer so that it can be used by D3DXCreateTextureFromFileInMemory() to load texture, how would I do that? Any hints? D3DXCreateTextureFromFileInMemory (Data.GFXDevice, FilePointer, CurrentFileTable->FileSize, &Texture->Object); Currently it is giving me D3DERR_INVALIDCALL error ... so I assume I am not copying data from TxtBuffer to FilePointer in a correct way. What will be the correct way? I am doing it with this: memcpy (FilePointer, &TxtBuffer, CurrentFileTable->FileSize);

Share this post


Link to post
Share on other sites
IFooBar    906
memcpy (FilePointer, TxtBuffer, CurrentFileTable->FileSize);

The second parameter you were passing a pointer to a pointer. So the data being operated on is completely not what you'd expect it to be. Since TxtBuffer contains contigious image data, the address of the Memory location "TxtBuffer" is where you are copying data from.

Share this post


Link to post
Share on other sites
The Lion King    115
Quote:
Original post by IFooBar
memcpy (FilePointer, TxtBuffer, CurrentFileTable->FileSize);

The second parameter you were passing a pointer to a pointer. So the data being operated on is completely not what you'd expect it to be. Since TxtBuffer contains contigious image data, the address of the Memory location "TxtBuffer" is where you are copying data from.

Yes! I tried that earlier too. Even after that I got D3DERR_INVALIDCALL from D3DXCreateTextureFromFileInMemory(). Not sure why?

I can easily get the original file from the char pointer array:

fwrite (TxtBuffer, CurrentFileTable->FileSize, 1, WriteStream);

If I try to use it this way:

D3DXCreateTextureFromFileInMemory (Data.GFXDevice, TxtBuffer, CurrentFileTable->FileSize, &Texture->Object);

I get Invalid Call error. If I copy the TxtBuffer to the FilePointer and then use it in the same way:

D3DXCreateTextureFromFileInMemory (Data.GFXDevice, FilePointer, CurrentFileTable->FileSize, &Texture->Object);

I get the same error. :(

Share this post


Link to post
Share on other sites
The Lion King    115
Thanks for the help IFooBar ... but I guess the problem was not what I though it was. That whole piece of code which consists of encrypting a file out of PAK File was OK! I realize that D3DXCreateTextureFromFileInMemory() was returning an Invalid CALL error not Invalid DATA error. My D3DDevice was OK since I was getting the other things on the window. I created a dummy texture right inside the function and the result was D3D_OK!

That was a stupid mistake ... but I am glad that I learned a lot of lessons from it ... especially that I wasted a whole week on this mistake.

This is my function prototype:

bool LoadTexture (char* TextureName, cTexture* Texture);

Here is cTexture:

cTexture
{
LPDIRECT3DTEXTURE9 Object;
};

This is the root of the problem. So one more question ... how do I set the function in such a way that I can get the boolean value out that wether the function the was success or a failure and can get the texture too ?

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