1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[D3D9] Point Light not working

Discussion in 'C++' started by C4L, Aug 31, 2010.

  1. C4L

    C4L New Member

    Aug 31, 2010
    Likes Received:
    Trophy Points:
    Hi everyone!

    I wanted to make this message longer, but for some reason couldn't post... so I lost it... so I had to rewrite it... so I'm gonna make it shorter... here it goes. :D

    As the title states I'm having problems creating lights in D3D9.
    I initialize it and turn it on but nothing happens. In fact, no object is visible anymore.
    Though when I use directional light, the objects are visible.

    I researched on Google a lot, but unfortunately, I found no answer of use.

    Here is the function that initializes the lights and materials:

    void initLight(void){    
            // these two variables are initialized
                    //D3DLIGHT9 light;    
                    //D3DMATERIAL9 material;     
        ZeroMemory(&light, sizeof(light));    // clear out the struct for use
        light.Type = D3DLIGHT_POINT;    // make the light type 'directional light'
            // control light's color through numpad
            if(keystate[DIK_NUMPAD7] & 0x80) lightR -= 0.05f;
            if(keystate[DIK_NUMPAD9] & 0x80) lightR += 0.05f;
            if(keystate[DIK_NUMPAD4] & 0x80) lightG -= 0.05f;
            if(keystate[DIK_NUMPAD6] & 0x80) lightG += 0.05f;
            if(keystate[DIK_NUMPAD1] & 0x80) lightB -= 0.05f;
            if(keystate[DIK_NUMPAD3] & 0x80) lightB += 0.05f;
            if(lightR < 0.0f) lightR = 0.0f;
            else if(lightR > 1.0f) lightR = 1.0f;
            if(lightG < 0.0f) lightG = 0.0f;
            else if(lightG > 1.0f) lightG = 1.0f;
            if(lightB < 0.0f) lightB = 0.0f;
            else if(lightB > 1.0f) lightB = 1.0f;
        light.Diffuse = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
        light.Position = D3DXVECTOR3(0.0f, -1.0f, 0.0f);
        light.Range = 50.0f;    // this should be enough
        light.Attenuation0 = 0.0f;     // no constant inverse attenuation
        light.Attenuation1 = 0.5f;  // 5 inverse attenuation
        light.Attenuation2 = 0.0f;   // no square inverse attenuation
        d3ddev->SetLight(0, &light);    // send the light struct properties to light #0
        d3ddev->LightEnable(0, TRUE);    // turn on light #0
            // initialize materials
            // well... a window's material... 
        ZeroMemory(&wndMaterial, sizeof(D3DMATERIAL9));
        wndMaterial.Diffuse.r = wndMaterial.Ambient.r = 0.60f;
        wndMaterial.Diffuse.g = wndMaterial.Ambient.g = 0.75f;
        wndMaterial.Diffuse.b = wndMaterial.Ambient.b = 1.0f;
        wndMaterial.Diffuse.a = wndMaterial.Ambient.a = 1.0f;
            // wood material ( used for walls )
            ZeroMemory(&woodMaterial, sizeof(D3DMATERIAL9));
            woodMaterial.Diffuse.r = woodMaterial.Ambient.r = 1.0f;
            woodMaterial.Diffuse.g = woodMaterial.Ambient.g = 0.75f;
            woodMaterial.Diffuse.b = woodMaterial.Ambient.b = 0.75f;
            woodMaterial.Diffuse.a = woodMaterial.Ambient.a = 1.0f;
            // concrete material ( used for floor )
            ZeroMemory(&cncrtMaterial, sizeof(D3DMATERIAL9));
            cncrtMaterial.Diffuse.r = cncrtMaterial.Ambient.r = 0.5f;
            cncrtMaterial.Diffuse.g = cncrtMaterial.Ambient.g = 0.5f;
            cncrtMaterial.Diffuse.b = cncrtMaterial.Ambient.b = 0.5f;
            cncrtMaterial.Diffuse.a = cncrtMaterial.Ambient.a = 1.0f;
    Yes, I did turn lighting on ( ambient lighting too ).
    If needed, I can post the rest of the code too.
    Would anyone give me any tips as of why my light is not working?

    Thanks anticipated!

    P.S. Sorry for my english, I'm not a native english speaker.

Share This Page