Set materials and lighting in d3d

Source: Internet
Author: User

//-----------------------------------------------------------------------------
// Desc: Set materials and lights
//-----------------------------------------------------------------------------
Void setlight ()
{
// Set the material.
D3dmaterial9 mtrl;
Zeromemory (& mtrl, sizeof (d3dmaterial9 ));
Mtrl. Diffuse. r = mtrl. Ambient. r = 1.0f;
Mtrl. Diffuse. G = mtrl. Ambient. G = 1.0f;
Mtrl. Diffuse. B = mtrl. Ambient. B = 0.0f;
Mtrl. Diffuse. A = mtrl. Ambient. A = 1.0f;
G_pd3ddevice-> setmaterial (& mtrl );

// Set the light
D3dxvector3 vecdir;
D3dlight9 light;
Zeromemory (& Light, sizeof (d3dlight9 ));
Light. type = d3dlight_directional;
Light. Diffuse. r = 1.0f;
Light. Diffuse. G = 1.0f;
Light. Diffuse. B = 1.0f;
Vecdir = d3dxvector3 (cosf (timegettime ()/3500000f ),
1.0f,
Sinf (timegettime ()/3500000f ));
// Vecdir = d3dxvector3 (1.0f, 1.0f, 0.0f );
D3dxvec3normalize (d3dxvector3 *) & Light. Direction, & vecdir );
Light. range = 1000.0f;
G_pd3ddevice-> setlight (0, & Light );
G_pd3ddevice-> lightenable (0, true );
G_pd3ddevice-> setrenderstate (d3drs_lighting, true );

// Set the ambient light
G_pd3ddevice-> setrenderstate (d3drs_ambient, 0x00505050 );
}

 

By setting the orientation of the rotating light, you can also make people feel that the object is rotating.

The material settings make us see the color of the object. If the light is turned on without the material, the object we see is black,

By default, the material does not reflect any light.

Change the color of g_pd3ddevice-> setrenderstate (d3drs_ambient, 0xff000000 );

Feel the difference between ambient light and a direction light source.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.