Direct3D (DirectX 9.0) Code Samples - Page 6

Lighting
 

This sample demonstrates the three basic types of lights that are available in Direct3D: directional, spot, and point. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: SetLight, SetRenderState, LightEnable, D3DXMatrixTranslation, D3DXMatrixRotationZ, D3DXToRadian, D3DXMatrixLookAtLH, D3DXMatrixInverse, D3DXCreateSphere, D3DXCreateCylinder, D3DRS_LIGHTING, D3DLIGHT_DIRECTIONAL, D3DLIGHT_SPOT, D3DLIGHT_POINT, D3DRS_AMBIENT, D3DLIGHT9, D3DMATERIAL9, Diffuse, Ambient, Type, Direction, Position, Theta, Phi, Falloff, Attenuation0, and Attenuation1.

 

Materials
 

Demonstrates how to use materials with lighting to produce different surface effects. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: SetMaterial, SetRenderState, D3DLIGHT_DIRECTIONAL, SetLight, LightEnable, D3DMATERIAL9, D3DRS_DIFFUSEMATERIALSOURCE, D3DRS_SPECULARMATERIALSOURCE, D3DRS_AMBIENTMATERIALSOURCE, D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL, D3DLIGHT9, Diffuse, Ambient, Specular, Power, D3DRS_COLORVERTEX, D3DRS_AMBIENT, and D3DCOLOR_COLORVALUE.

 

Lost Device Recovery
 

This sample demonstrates how to recover from a lost device. A device can become "lost" when an event, such as the loss of keyboard focus in a full-screen application, causes rendering to become impossible. The lost state is characterized by the silent failure of all rendering operations, which means that the rendering methods can return success codes even though the rendering operations fail. In this situation, the error code D3DERR_DEVICELOST is returned by IDirect3DDevice9::Present.

Relevant Keywords: Present, TestCooperativeLevel, D3DERR_DEVICELOST, D3DERR_DEVICENOTRESET, Reset, BackBufferWidth, BackBufferHeight, and Release.

 

Resizing DirectX 9.0 Window
 

This sample demonstrates how to respond to the app's window getting resized by resizing the front and back buffers of the Direct3D device to match it. If you don't do this, Direct3D will be forced to perform a stretch blit when the window is enlarged and everything rendered will appear course and blocky. For example, if the initial window size and Direct3D device are set to 640x480 and you enlarge the window to be 1024x768, the Direct3D device will continue to render at 640x480 unless its front back buffers are resized accordingly.

Relevant Keywords: WM_SIZE, Reset, BackBufferWidth, BackBufferHeight, and Release.


Point Sprites
 

This sample demonstrates how to use point sprites with Direct3D. Point sprites are hardware-accelerated billboards, which are capable of being textured. Point sprites are ideal for creating high-performance particle systems because you only have to send a single vertex point or point sprite for each particle instead of four vertices for a regular billboarded quad. Point sprites also do all the math involved in view aligning the final quad on the GPU instead of the CPU. See the Particle System sample below for a more complex example of their usage. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: SetRenderState, D3DUSAGE_DYNAMIC, D3DUSAGE_POINTS, D3DUSAGE_WRITEONLY, D3DFVFCAPS_PSIZE, D3DRS_POINTSPRITEENABLE, D3DRS_POINTSIZE, D3DRS_POINTSIZE_MIN, D3DRS_POINTSCALE_A, D3DRS_POINTSCALE_B, D3DRS_POINTSCALE_C, D3DLOCK_DISCARD, D3DPT_POINTLIST, D3DRS_ALPHABLENDENABLE, D3DBLEND_ONE, D3DRS_ZWRITEENABLE, D3DLOCK_DISCARD, and FVFCaps.