IDirect3DTexture9* my_texture; //make a texture
void setupTexture() //set up the texture
{
//D3DXCreateTextureFromFile(Device,"ast.jpg",&my_texture);
if(FAILED(D3DXCreateTextureFromFile(Device,"ast.jpg",&my_texture)))
{
::MessageBox(0, "Tex - FAILED", 0, 0);
}
}
Next i Create an asteroid in my message loop:
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
{
main_instance = hinstance;
if(!d3d::InitD3D(hinstance, Width, Height, true, D3DDEVTYPE_HAL, &Device))
{
::MessageBox(0, "InitD3D() - FAILED", 0, 0);
return 0;
}
if(!Setup())
{
::MessageBox(0, "Setup() - FAILED", 0, 0);
return 0;
}
createAsteroid(Device,Height,Width, my_texture); //create asteroid
d3d::EnterMsgLoop(Display);
Cleanup();
Device->Release();
return 0;
}
I have a struct for an asteroid:
struct ASTEROID
{
LPD3DXMESH Mesh;
D3DMATERIAL9 Mtrl;
D3DXMATRIX Location;
IDirect3DTexture9* Texture;
float x; // Asteriod X Posistion
float y; // Asteriod Y Posistion
float z;
float raduis;
int hit;
int direction;
bool visible; // were we collide?
bool split;
};
I build a matrix of asteroids that i want to texture
bool createAsteroid(IDirect3DDevice9* device, const int Height, const int Width, IDirect3DTexture9* texture)
{
time_t now = time(0);
srand((unsigned int )&now);
for(int i = 0; i < TOTAL_ASTEROIDS + level; i++)
{
asteroids.Location = asteroid_matrix;
asteroids.Texture = texture; //<- texture set
asteroids.z = 80;
asteroids.x = 20.0f - (rand()%60);
if(asteroids[i-1].x <= asteroids.x + 20) asteroids.x = 20.0f - (rand()%60);
asteroids.y = 20.0f - (rand()%60);
if(asteroids[i-1].y <= asteroids.y + 20) asteroids.y = 20.0f - (rand()%60);
}
return true;
}
next i move and render the asteroids :this is my recursive loop:
bool render(IDirect3DDevice9* device, const int Height, const int Width)
{
if(!device)return false;
moveAsteroids(device, Height, Width);
device->BeginScene();
renderAsteroids(device);
device->EndScene();
return true;
}
which movement is just moving cords no big deal then re render the object:
void renderAsteroids(IDirect3DDevice9* device)
{
D3DLIGHT9 light;
ZeroMemory(&light,sizeof(light));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse = d3d::WHITE;
light.Direction = D3DXVECTOR3(-1.0f, -0.3f, -1.0f);
device->SetLight(0,&light);
device->LightEnable(0,true);
light.Direction = D3DXVECTOR3(1.0f,0.3f,1.0f);
device->SetLight(1,&light);
device->LightEnable(1,true);
//set light render states
device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
device->SetRenderState(D3DRS_SPECULARENABLE, false);
astroidNotHit(device);
}
Problem is the Texture is created (doesnt fail and prompt out) ... i can see that the value is being applied to my structure... but i can not see the asteroid on my screen.. i have a feeling the problem is my lighting.
Any suggestions?