Need a little help.. think my lighting is messed up...

Started by
2 comments, last by TransformedBG 12 years ago
So programming calls go like so:

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?
Advertisement
Have you ever tried to use PIX? It will help you find whats happening...

The problem might be caused by incorrect vertex/index buffers, incorrect view/projection matrix, incorrect lighting, etc, etc.

Where is your draw call?
Never really used PIX... But i know that the texture is being set... Im looking at it and im about 99% sure its a lighting issue..

Granted it could be the fact that i have my Z cords on my asteroid set to 80? i dont know... i can change a texture to a Material color and it works fine.
So far this is what i have now... I just got the light to light up the asteroids loading a texture into it.. However the texture doenst quite show.. It comes out brown instead of white... So i know there is a texture loading

This topic is closed to new replies.

Advertisement