Archived

This topic is now archived and is closed to further replies.

eric_sun

after adding a light everything is green

Recommended Posts

eric_sun    122
hi there, im new in dx9 programming, so i have a stupid question i have a scene with flying planets, after adding a point light, everything is green!? so i think my direct3d settings are wrong... this are my current settings. i have a geforce4 mx440. i also have examples with light, so i know my card can do it... PresentParams.BackBufferWidth = 640; PresentParams.BackBufferHeight = 480; PresentParams.BackBufferFormat = D3DFMT_X8R8G8B8; PresentParams.BackBufferCount = 1; PresentParams.MultiSampleType = D3DMULTISAMPLE_NONE; PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD; PresentParams.hDeviceWindow = hWindow; PresentParams.Windowed = TRUE; PresentParams.EnableAutoDepthStencil = TRUE; PresentParams.AutoDepthStencilFormat = D3DFMT_D24X8; PresentParams.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL; PresentParams.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; PresentParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &PresentParams, &m_pD3DDevice))) { return FALSE; } can anyone help me? maze

Share this post


Link to post
Share on other sites
JoeyBlow2    100
You didn''t provide any information about the lights or materials (please do so)

But to answer your question, you need to make sure the material properties are all white, then setup the light as the color you desire.

If you haven''t set any of this, its likely that DirectX (or whatever was in that memory location at the time) defaulted it to green.


Share this post


Link to post
Share on other sites
eric_sun    122
thats the light
ZeroMemory(&PointLight, sizeof(D3DLIGHT9));
PointLight.Type = D3DLIGHT_POINT;PointLight.Diffuse = seColor(1.0f, 1.0f, 0.75f);
PointLight.Ambient = seColor(1.0f, 1.0f, 0.75f);
PointLight.Position = g_aPlanet[0].vPosition;
PointLight.Range = 1000.0f;
PointLight.Attenuation0 = 1.0f;
PointLight.Attenuation1 = 0.0f;
PointLight.Attenuation2 = 0.0f;
g_pD3DDevice->SetLight(0, &PointLight);
g_pD3DDevice->LightEnable(0, TRUE);

thats a excample material
Material.Diffuse = seColor(1.0f, 1.0f, 1.0f);
Material.Ambient = seColor(0.25f, 0.25f, 0.25f);
Material.Emissive = seColor(0.0f, 0.0f, 0.0f);


the problem is, that my code is copied from an working excample!
after compiling and starting with my own direct3d settings everything is green. my objects and so on have textures, but all in green now.

Share this post


Link to post
Share on other sites
Pothead    130
I''m having the same problem.. If I try to use any material with my textures, they all turn green.
so, I''m stuck to texturing without materials.. crap for designing lights.

Share this post


Link to post
Share on other sites
Painless    126
Make sure that:
- The vertex format for the object you''re rendering includes a normal
- The normals are correct
- You have lighting set (D3DRS_LIGHTING -> TRUE)

Share this post


Link to post
Share on other sites
Pothead    130
ah. ok. my problem is a bit different.
I can add lights & textures and everything looks nice but if I use any material all turns green. no matter what rgb values I use..

Share this post


Link to post
Share on other sites
eric_sun    122
my vertex format looks like this:
D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1

i tried it without materials, but all is green
and
a loaded mesh with white material and no texture, a light at the same position, its green...

Share this post


Link to post
Share on other sites
beehorf    122
May be you are writing to an adress that u shouldnt because
of wrong pointer usage.
Also

-I think you should check your material if it is set correctly by GetMaterial.
-do it to the light you added.
-Also check if you enabled the light ( with ->LightEnable)

Share this post


Link to post
Share on other sites
Painless    126
quote:
Original post by eric_sun
my vertex format looks like this:
D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1




Did you actually read my reply or are you just posting randomly? You need a normal in the vertex for lighting to work. Also, it''ll just ignore that per-vertex diffuse color by default unless you set some renderstate (forgot which).

Share this post


Link to post
Share on other sites
eric_sun    122
@Painless
no its not randomly, i have red your message and i will try it, but im not at home at this time so i just wanted to show you my current settings.

@beehorf
im just using one material variable for all objects i need. dont know if this is good or bad. the light is set correctly
but i will try the getmaterial, maybe i can find something

Share this post


Link to post
Share on other sites