Sign in to follow this  
TransformedBG

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

Recommended Posts

So programming calls go like so:
[CODE]
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);
}
}
[/CODE]

Next i Create an asteroid in my message loop:
[CODE]
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;
}
[/CODE]

I have a struct for an asteroid:
[CODE]
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;
};
[/CODE]

I build a matrix of asteroids that i want to texture
[CODE]
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[i].Location = asteroid_matrix[i];

asteroids[i].Texture = texture; //<- texture set
asteroids[i].z = 80;

asteroids[i].x = 20.0f - (rand()%60);
if(asteroids[i-1].x <= asteroids[i].x + 20) asteroids[i].x = 20.0f - (rand()%60);
asteroids[i].y = 20.0f - (rand()%60);
if(asteroids[i-1].y <= asteroids[i].y + 20) asteroids[i].y = 20.0f - (rand()%60);
}
return true;
}
[/CODE]

next i move and render the asteroids :this is my recursive loop:
[CODE]
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;
}
[/CODE]

which movement is just moving cords no big deal then re render the object:
[CODE]
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);
}
[/CODE]

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?

Share this post


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

Share this post


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

Share this post


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

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