Jump to content
  • Advertisement
Sign in to follow this  

DX lighting test

This topic is 4848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here I am again, seeking help in cyberspace. I have created a application which creates a box and lightning. The box rotates but it gets "stuck" on the backround which creates an annoying effect. The code can be found here: http://codedump.nutextonline.com/view/88 Uses dx9. Edit: Link for the program itself(.rar). Here

Share this post

Link to post
Share on other sites
Your problem is that you're not clearing the backbuffer each frame. As a result, the contents of the previous frame are passed on to the next one, except where you draw over it.

You need to add a call to
g_pD3DDevice->Clear() every frame, right after BeginScene().

Hope this helps :).

Share this post

Link to post
Share on other sites
D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0);

I removed the D3DCLEAR_ZBUFFER and for some reason it worked :D

D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0);

Right before begin scene and that is done every frame but as you can see it does not help.

Share this post

Link to post
Share on other sites
ok thanks. I did the clear before the beginscene and it works :D. Well now I am trying to add ambient lighting as I see I need to work a bit more on lighting.
So I will pop another question.

I try to add ambient g_pD3DDevice->SetRenderState(D3DRS_AMBIENT,
D3DCOLOR_COLORVALUE(0.0f, 0.5f, 0.5f, 0.8f));

I add it on the line 176 but I can't see any changes, why?

And thanks for your quick answers, appreciate it very much.

Share this post

Link to post
Share on other sites
When you create your device if you did not request a ZBuffer then do not clear it.I think that you already know that and that is the reason you were getting the artifact but i would suggest you used the zbuffer otherwisew you will need to draw everything back to front and it can get kind of annoying especially when you have a bunch of Objects at Different Z locations.

Share this post

Link to post
Share on other sites
Ohh ok, learning dx so I guess I will come to that part. Thanks for the info.

I also tried to add a directional light but, well it just won't work.
here is the code:
D3DLIGHT9 Light;

ZeroMemory(&ALight, sizeof(ALight));

// Set the diffuse and ambient colors to yellow
ALight.Diffuse.r = ALight.Ambient.r = 1.0f;
ALight.Diffuse.g = ALight.Ambient.g = 1.0f;
ALight.Diffuse.b = ALight.Ambient.b = 0.0f;

D3DXVECTOR3 Dir = D3DXVECTOR3(0.0f, 500.0f, 0.0f);
D3DXVec3Normalize((D3DXVECTOR3*)&ALight.Direction, &Dir);

// Set and enable the light
g_pD3DDevice->SetLight(0, &Light);
g_pD3DDevice->SetLight(1, &ALight);
g_pD3DDevice->LightEnable(0, TRUE);
g_pD3DDevice->LightEnable(1, TRUE);

Shouldn't that enable both lights?

Share this post

Link to post
Share on other sites
Hi there Todilo,
How are you doing?

[The Problem]
Directional light problem?

[The Solution]
The directional light doesn't have a range.
Directional Light:
"Light is a directional light source. This is equivalent to using a point light source at an infinite distance."

So let's look at your code :)

Your light Direction
D3DXVECTOR3 Dir = D3DXVECTOR3(0.0f, 500.0f, 0.0f);
Change that to
D3DXVECTOR3 Dir = D3DXVECTOR3(0.0f, 1.0f, 0.0f); //Unit vector :)

Assign light to the device
g_pd3dDevice->SetLight( 0, &light );

The following code fragment enables the light by calling
g_pd3dDevice->LightEnable( 0, TRUE);

The following code fragment tells Direct3D to render lights by calling
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );

For testing purposes enable ambient lighting
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 );

For further reading on lights and materials, I would suggest the SDK docs which are pretty clear :)

Lights and Material

I hope this helps a bit :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!