Sign in to follow this  
Psychopathetica

Texture Array Issue (C++ 2008)

Recommended Posts

I'm trying to load a texture through a function using an array:

[code]
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);
}
[/code]

Now this works great using just one texture thats not an array, but when I load a texture that is an array....
[code]
Load_Texture(Texture[0], "front.png", D3DCOLOR_XRGB(0, 0, 0));
[/code]

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

Share this post


Link to post
Share on other sites
DgekGD    374
Try to pass it as [i]&Texture[ n ] to [i]D3DXCreateTextureFromFileEx[/i] [/i]method giving[i][i] Load_Texture[/i][/i] an index in the array[i]. [/i]Second option i guess is passing to the[i] Load_Texture[/i] method [i]*Texture[ n ][/i] instead of [i]Texture[ n ][/i]

Share this post


Link to post
Share on other sites
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.

[code]
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);
}
[/code]

And I tried using this:
[code]
Load_Texture(*Texture[0], "front.png", D3DCOLOR_XRGB(0, 0, 0));
[/code]

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:

[code]
LPDIRECT3DTEXTURE9 Test;
[/code]

Added an address operator '&' to T in Load_Texture:
[code]
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);
}

[/code]

Ran it through Load_Texture and managed to duplicate the 'LPDIRECT3DTEXTURE9 **' to 'LPDIRECT3DTEXTURE9 *' error:
[code]
Load_Texture(Test, "front.png", D3DCOLOR_XRGB(0, 0, 0));
[/code]

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.

Share this post


Link to post
Share on other sites
programci_84    336
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:
[code]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));
}[/code]

And call your function like this:
[code]
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[i], file_name[i], transparency[i]);
[/code]

hth.
-R

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