Texture Array Issue (C++ 2008)

Started by
2 comments, last by programci_84 12 years, 2 months ago
I'm trying to load a texture through a function using an array:


LPDIRECT3DTEXTURE9 Texture[6];

void Load_Texture(LPDIRECT3DTEXTURE9 *Texture, char *File_Path, int Transparency_Color)
{
D3DXCreateTextureFromFileEx(Device, File_Path, 512, 512, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_FILTER_POINT, D3DX_FILTER_POINT, Transparency_Color, NULL, NULL, &Texture);
}


Now this works great using just one texture thats not an array, but when I load a texture that is an array....

Load_Texture(Texture[0], "front.png", D3DCOLOR_XRGB(0, 0, 0));


I end up with these 2 errors:

- : error C2664: 'D3DXCreateTextureFromFileExA' : cannot convert parameter 14 from 'LPDIRECT3DTEXTURE9 **' to 'LPDIRECT3DTEXTURE9 *'
- : error C2665: 'Load_Texture' : none of the 2 overloads could convert all the argument types

I was wondering, what is the correct way of doing this is? I know I'm messing up somewhere with the pointers. Thanks in advance
Advertisement
Try to pass it as &Texture[ n ] to D3DXCreateTextureFromFileEx method giving Load_Texture an index in the array. Second option i guess is passing to the Load_Texture method *Texture[ n ] instead of Texture[ n ]
The variable Texture in the method Load_Texture is not the same variable as the Texture[n] array I have. So instead let's call it T.


void Load_Texture(LPDIRECT3DTEXTURE9 *T, char *File_Path, int Transparency_Color)
{
D3DXCreateTextureFromFileEx(Device, File_Path, 512, 512, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_FILTER_POINT, D3DX_FILTER_POINT, Transparency_Color, NULL, NULL, T);
}


And I tried using this:

Load_Texture(*Texture[0], "front.png", D3DCOLOR_XRGB(0, 0, 0));


But once again I got the error:
(error C2664: 'D3DXCreateTextureFromFileExA' : cannot convert parameter 14 from 'LPDIRECT3DTEXTURE9 **' to 'LPDIRECT3DTEXTURE9 *').

Then I did an experiment. I created a variable called Test:


LPDIRECT3DTEXTURE9 Test;


Added an address operator '&' to T in Load_Texture:

void Load_Texture(LPDIRECT3DTEXTURE9 *T, char *File_Path, int Transparency_Color)
{
D3DXCreateTextureFromFileEx(Device, File_Path, 512, 512, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_FILTER_POINT, D3DX_FILTER_POINT, Transparency_Color, NULL, NULL, &T);
}



Ran it through Load_Texture and managed to duplicate the 'LPDIRECT3DTEXTURE9 **' to 'LPDIRECT3DTEXTURE9 *' error:

Load_Texture(Test, "front.png", D3DCOLOR_XRGB(0, 0, 0));


It turns out I can't use an address operator on T. I then changed the variable Test to the array I wanted to apply the texture to and vwola! It worked. Problem self resolved lol.
Look at your last parameter of D3DXCreateTextureFromFileEx(). You are passing a LPDIRECT3DTEXTURE9*, but you're trying to get LPDIRECT3DTEXTURE9**.

Change the function code to this:
void Load_Texture(LPDIRECT3DTEXTURE9 *T, char *File_Path, int Transparency_Color)
{
D3DXCreateTextureFromFileEx(Device, File_Path, 512, 512, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_FILTER_POINT, D3DX_FILTER_POINT, Transparency_Color, NULL, NULL, &(*T));
}


And call your function like this:

LPDIRECT3DTEXTURE9 myTextureArray [NUM_OF_TEXTURES];
LPCSTR file_name [NUM_OF_TEXTURES] = {"front.png", "back.png", "whoa.png", "blah_blah_blah.png", ... };
int transparency [NUM_OF_TEXTURES] = _WHO_CARES_;
for (UINT i = 0; i < NUM_OF_TEXTURES; i++)
Load_Texture (&myTextureArray, file_name, transparency);


hth.
-R
There's no "hard", and "the impossible" takes just a little time.

This topic is closed to new replies.

Advertisement