Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualbelfegor

Posted 29 May 2013 - 03:47 AM

You know how to read/write to binary files?

 

Here is simple example with reading from actual texture file then using D3DXCreateTextureFromFileInMemory or you could use Ex version (its the same):

:

 

std::ifstream is("texture.dds", std::ios::binary);
    is.seekg (0, is.end);
    auto length = is.tellg();
    is.seekg (0, is.beg);
    std::vector<char> vFile(length);
    is.read((char*)&vFile[0], vFile.size());
    is.close();
    hr = D3DXCreateTextureFromFileInMemory(d3d9device, (LPCVOID)&vFile[0], vFile.size(), &texture);
    if(FAILED(hr))
    {
        MessageBox(0, TEXT("D3DXCreateTextureFromFileInMemory() failed!"), 0, 0);
    }

 

If you were pack bunch of textures in 1 binary, you could write some info that you need (offset to specific texture, dimensions, names, lenght in bytes...), and then you could read for eample:

 

 

std::ifstream is("packed_textures.bin", std::ios::binary);
... //find offset to specific texture
    is.seekg (...); // put cursor to that postion
UINT_t len;
is.read( (char*)&len, sizeof(UINT));
std::vector<char> vFile(len);
is.read((char*)&vFile[0], vFile.size());
hr = D3DXCreateTextureFromFileInMemory(d3d9device, (LPCVOID)&vFile[0], vFile.size(), &texture);
...

#1belfegor

Posted 29 May 2013 - 03:44 AM

You know how to read/write to binary files?

 

Here is simple example with reading from actual texture file then using D3DXCreateTextureFromFileInMemory or you could use Ex version (its the same):

:

std::ifstream is("texture.dds", std::ios::binary);
    is.seekg (0, is.end);
    auto length = is.tellg();
    is.seekg (0, is.beg);
    std::vector<char> vFile(length);
    is.read((char*)&vFile[0], vFile.size());
    is.close();
    hr = D3DXCreateTextureFromFileInMemory(d3d9device, (LPCVOID)&vFile[0], vFile.size(), &texture);
    if(FAILED(hr))
    {
        MessageBox(0, TEXT("D3DXCreateTextureFromFileInMemory() failed!"), 0, 0);
    }

 

If you were pack bunch of textures in 1 binary, you could write some info that you need (offset to specific texture, dimensions, lenght in bytes...), and then you could read for eample:

 

std::ifstream is("packed_textures.bin", std::ios::binary);
... //find offset to specific texture
    is.seekg (...); // put cursor to that postion
UINT_t len;
is.read( (char*)&len, sizeof(UINT));
std::vector<char> vFile(len);
is.read((char*)&vFile[0], vFile.size());
hr = D3DXCreateTextureFromFileInMemory(d3d9device, (LPCVOID)&vFile[0], vFile.size(), &texture);
...

PARTNERS