Hello, everyone!
i'm working on a little project, and im having some troubles texturing an object created with D3DXCreate*, at the moment, i have:
first, object structure:
struct hOBJECT
{
unsigned int ID;
ID3DXMesh *baseMesh;
D3DXMATRIX WorldMatrix;
D3DMATERIAL9 mtrl;
IDirect3DTexture9 *Tex;
bool Textured;
int texStage;
float xPos, yPos, zPos;
float xAng, yAng, zAng;
};
//..
//...
hOBJECT hCORE::MakeObjectSphere ( int ID )
{
for ( unsigned int i = 0; i < ObjectV.size(); i++ )
if ( ObjectV.ID == ID )
{
ObjectV.baseMesh->Release ( );
ObjectV.erase ( ObjectV.begin ( ) + i );
break;
}
hOBJECT outObj;
outObj.ID = ID;
outObj.xPos = outObj.yPos = outObj.zPos = outObj.xAng = outObj.yAng = outObj.zAng = 0.0f;
D3DXCreateSphere ( device, 2, 12, 12, &outObj.baseMesh, 0 );
D3DXCOLOR RandColor ( float(float((rand()%5))/10)+0.5, float(float((rand()%5))/10)+0.5, float(float((rand()%5))/10)+0.5, 1 );
outObj.mtrl.Ambient = RandColor;
outObj.mtrl.Diffuse = RandColor;
outObj.mtrl.Specular = RandColor;
outObj.mtrl.Emissive = D3DXCOLOR ( 0, 0, 0, 1 );
outObj.mtrl.Power = 5.0f;
outObj.Textured = false;
outObj.texStage = 0;
ObjectV.push_back ( outObj );
return outObj;
}
this creates a sphere, works perfectly, after that, i texture it using
void hCORE::TextureObject ( int ID, LPSTR Filename, int texStage )
{
for ( int i = 0; i < ObjectV.size(); i++ )
{
if ( ObjectV.ID == ID )
{
if ( FAILED ( D3DXCreateTextureFromFileA ( device, Filename, &ObjectV.Tex ) ) )
{
hERROR error;
error.active = true;
error.fatal = false;
error.Err = "TextureObject : unknown object ID";
ErrorLog.push_back ( error );
return;
}
ObjectV.texStage = texStage;
ObjectV.Textured = true;
return;
}
}
hERROR error;
error.active = true;
error.fatal = false;
error.Err = "TextureObject : unknown object ID";
ErrorLog.push_back ( error );
}
loading the texture works fine, i get no errors
but then, in the render, i just get a black object, why is that? this is the render:
device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, RGB ( 200, 20, 60 ), 1.0f, 0);
device->BeginScene();
for ( unsigned int i = 0; i < ObjectV.size(); i++ )
{
device->SetMaterial ( &ObjectV.mtrl );
if ( ObjectV.Textured )
device->SetTexture ( ObjectV.texStage, ObjectV.Tex );
else
device->SetTexture ( 0, 0 );
D3DXMATRIX mpos, mx, my, mz;
D3DXMatrixTranslation ( &mpos, ObjectV.xPos, ObjectV.yPos, ObjectV.zPos );
D3DXMatrixRotationX ( &mx, ObjectV.xAng );
D3DXMatrixRotationY ( &my, ObjectV.yAng );
D3DXMatrixRotationZ ( &mz, ObjectV.zAng );
ObjectV.WorldMatrix = ( mz * mx * my ) * mpos;
device->SetTransform(D3DTS_WORLD, &ObjectV.WorldMatrix);
ObjectV.baseMesh->DrawSubset(0);
}
device->EndScene();
device->Present(0, 0, 0, 0);
do i need to do some other stuff in order to get textures? or i am doing something wrong?
looking forward for a reply
thanks in advance
-Hassan
[Edited by - Hassanbasil on March 4, 2010 11:01:08 AM]