First, the original code I am trying to modify, and that does work (I think most of it came from a tutorial).
LPDIRECT3DTEXTURE9 Dx_Manager::GetTexture(char* filename)
{
for (int i = 0; i < MAX_TEXTURES; ++i)
{
if (!d3d_texture.texture && d3d_texture.inuse)
{
continue;
}
d3d_texture.inuse = true;
d3d_texture.filename = filename;
D3DXCreateTextureFromFileA(d3d_device, d3d_texture.filename, &d3d_texture.texture);
return d3d_texture.texture;
}
return NULL;
}
Apparently "D3DXCreateTextureFromFileA" insists that graphics be sized to the power of 2 (2, 4, 8, 16, 32, etc), and while it can be dealt with, by making unused parts of the graphic transparent, I can foresee problems with scaling as well as interactive graphics elements overlapping each other. And on top of that there is the wasted memory for the larger than necessary graphic.
So I am thinking that using D3DXCreateTextureFromFileEx would be better. Here is what, I think, I need to replace line 12 (above) with:
D3DXIMAGE_INFO info;
HRESULT result = D3DXGetImageInfoFromFile(filename.c_str(), &info);
if (result != D3D_OK)
{
return NULL;
}
D3DXCreateTextureFromFileEx(
d3d_device,
filename.c_str(),
info.Width,
info.Height,
1,
D3DPOOL_DEFAULT,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
0xFF000000,
&info,
NULL,
&d3d_texture.texture
);
But in both the places that I use "filename.c_str()" I get this error
error C2228: left of '.c_str' must have class/struct/union
If take off the ".c_str()" I get errors similar to this
error C2664: 'D3DXGetImageInfoFromFileW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
I have tried changing the type of "filename" from "char*" to "WCHAR*", "TCHAR", "LPCWSTR", "LPCSTR" as well as looked up ways to convert "char*" to other types and all have failed to work. And really I am not even sure changing the type definition is the solution to the problem.
Any direction on this would be much appreciated.
Also in researching a solution, I read in one place that "D3DXCreateTextureFromFileA" is easier on graphics cards than "D3DXCreateTextureFromFileEx". So if there is a completely different approach I should be looking at let me know.