Click to See Complete Forum and Search --> : TEXTURE STUPID PROBLEM - I believe...


_Comet_Keeper_
December 30th, 2005, 04:23 PM
Hi,

I'm writing to try solving a little strange (to me) problem with lights and textures.

See this:

When I use PositionNormalColored and lighting=true, all ok!
When I use PositionNormalTextured and lighting=true I see all black, when I set lighting=false I see all object right, but clearly without lights and shadows.

Does anyone know where could be the problem?

Thank you very much
_Comet_Keeper_ (from Italy)

The Wizard of Ogz
January 3rd, 2006, 03:25 AM
I was having the same problem, but found a solution here http://www.ureader.com/message/453935.aspx . Scroll about halfway down where new code is added to setup the device material properties. I hope that helps!

--Oops! The link is to C# code, but it illustrates the point. Here's some C++
Add this to your render method or initialization code, see if it helps.

D3DMATERIAL9 Material;
ZeroMemory(&Material, sizeof(D3DMATERIAL9));

// The ambient and diffuse colours for the material directly set the apparent colour of
// any primitives rendered with this material. They specify what colours this material reflects
// when light falls on them. For example, a blue light (0.0, 0.0, 1.0) shining on a material with
// diffuse (0.0, 0.0, 1.0) will make the primitives appear blue, because a blue material will
// reflect a blue light. However a red light (1.0, 0.0, 0.0) shining on the same material will
// make the primitive appear black, because there are no blue components in a red light, therefore
// nothing to reflect.
// It is normal for your material diffuse and ambient colours to be the same
// http://www.thehavok.co.uk/scene/32bits/tutorials/directx/thebasics3/source/dx9/lighting.cpp.html

// Set the Diffuse properties of the Material
Material.Diffuse.r = 1.0f;
Material.Diffuse.g = 1.0f;
Material.Diffuse.b = 1.0f;
Material.Diffuse.a = 1.0f;

// Set the Ambient properties of the Material
Material.Ambient.r = 1.0f;
Material.Ambient.g = 1.0f;
Material.Ambient.b = 1.0f;
Material.Ambient.a = 1.0f;

// Tell D3D to use our material
HRESULT rslt=g_pDevice->SetMaterial(&Material);
if(FAILED(rslt)) { return D3DError(rslt, __LINE__, __FILE__, "Could not set material."); }

_Comet_Keeper_
January 4th, 2006, 09:38 AM
Hi,

Ok, it's work right, but I notice a little problem. Because I'm very new to DirectX maybe it is something stupid, but maybe you... or someone else could help me.

Because I don't want to rotate World, but onliy the object I use something like this:

pos=verts[i].Position;
norm=verts[i].Normal;

pos.TransformCoordinates(....);
nrom.TransformCoordinates(....);

verts[i].Position=pos;
verts[i].Normal=norm;

Now, to make the rotation real I rotate the object 2 degree each render-time. At the end the object should be rotated by Pi/2.

When the process ends I notice that lights change refleciont change. So I checked if the calculation is right and I notice that the values of position and normal are not right. For example if I have a normal = 0,0,-1 when it is rotated by Pi/2 up (face up) the normal should be 0,1,0, but is something like 0,0.99999,-0.0004445. I think that this is some approximation problem using Math.Pi.

How cna solve this problem?

Thank you.
CometKeeper