#### Archived

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

# Displaying Polys with no texture in DX8?

## Recommended Posts

MarkO    122
I have been displaying meshes using textures for a while now and before that i did make some simple polys using FVF code like D3DFVF_CPOLYVERTEX ( D3DFVF_XYZ | D3DFVF_DIFFUSE). The problem i am facing now is when i try to display a simple poly using just a vertex color component after rendering polys which use textures all i get is a black poly. Since i am passing in a RGBA color i can also have it alpha blend the poly except it still does use the color from the vertex but rather it still fades into black. I have been trying to set different renderstates but all to no avail. Anyone have any idea what i could be doing wrong? i can post whatever bits of code might be causing the problem. Any Help would be appreciated Thanks MarkO

##### Share on other sites
Mark Duffill    156
I had a similar problem which was caused by enabling lighting but not setting any ambient value.

DXDisplay->SetRenderState(D3DRS_AMBIENT , 0xffffffff);

DXDisplay->SetRenderState( D3DRS_LIGHTING, TRUE );

A better solution I found was to set the ambient source to use the vertex diffuse instead of the global ambient as follows:-

DXDisplay->SetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1 );

Hope this fixes it!

[The views stated herein do not necessarily represent the view of the company Eurocom ]

Eurocom Entertainment Software
www.Eurocom.co.uk

The Jackal

##### Share on other sites
MarkO    122
O.K. Now i am completely confused
I currently have these lines of code in my game affecting lighting
  Device->SetRenderState(D3DRS_AMBIENT,0xffffffff);// Device->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1 );Device->SetLight (0, &light);Device->LightEnable (0, 1);void CreatePointLight(){ D3DXVECTOR3 vecDir; ZeroMemory (&light, sizeof(D3DLIGHT8)); light.Type = D3DLIGHT_POINT; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; vecDir = D3DXVECTOR3 (0.0f, 0.0f, 0.0f); D3DXVec3Normalize ((D3DXVECTOR3*)&light.Direction, &vecDir); light.Position=D3DXVECTOR3(0.0f,50.0f,0.0f); light.Range = 1000.0f; light.Attenuation0=1.0f;}

o.k. without the ambient light code in there my pointlight works fine..my objects are shadowed correctly etc.
the default diffuse value for all my models is 0xFFFFFFFF as i havnt gotten around to playing with that end of things yet
all those models have normal textures and do fine with normal lighting
However my simple poly which i wanted to use the diffuse values to color it with ( D3DFVF_XYZ | D3DFVF_DIFFUSE) shows up black as i posted originally.
With the advice posted above i added the second line of ambient light code..now my simple poly works great...the colors show properly etc. However my main models are now Fully lighted with the ambient light.
What confuses me is that to get any ambient light i must have both lines of code in my program, with just one or the other i dont get any ambient light.
Anyone know why this would be?
Very Confused
MarkO

##### Share on other sites
Mark Duffill    156
Right I see what you are trying to do now.

I''m pretty sure you have to define D3DFVF_NORMAL in you vert structure for dynamic lights to work, but I''m not 100% sure on this. What you do have to do is set the material up so it works right with lights an ambient values.

firstly decalare a material somewhere and set it all to zero.

D3DMATERIAL8 Material;
memset( &Material, 0 ,sizeof(Material) );

Then set the diffuse members to full on.

Material.Diffuse.r = 1.0f; Material.Diffuse.g = 1.0f;
Material.Diffuse.b = 1.0f; Material.Diffuse.a = 1.0f;

The diffuse represents how much of the dynamic light will be "reflected" off your object. Setting all components to full will mean a red light will be red, a green one green etc. In you case a white light.

Then set the ambient member to an approprate value:-

Material.Ambient.r = 0.5f;
Material.Ambient.g = 0.5f;
Material.Ambient.b = 0.5f;

The ambient represents how much of the DXDisplay->SetRenderState(D3DRS_AMBIENT , 0xffffffff) Will be "relflected". If these are all set to 1 the ambient will "wash out" you dynamic light.

Then set the material with DXDisplay->SetMaterial( &Material ).

You only have to call this when you change the settings.

I hope this helps, I know the "fun" of the lighting and materials in DX. To get the effect you want requires a lot of playing around with the material values.

[The views stated herein do not necessarily represent the view of the company Eurocom ]

Eurocom Entertainment Software
www.Eurocom.co.uk

The Jackal