很好的几个Managed Directx 例子

2014/09/25

(转载自:http://www.codesampler.com/dx9src/dx9src_2.htm)





Direct3D (DirectX 9.0) Code Samples - Page 2

Primitive Types
 

This sample demonstrates how to use the 6 primitive types available under Direct3D: point list, line list, line strip, triangle list, triangle strip, and triangle fan.

Relevant C++ Keywords: CreateVertexBuffer, Lock, Unlock, SetStreamSource, SetTexture, SetFVF, DrawPrimitive, D3DPT_POINTLIST, D3DPT_LINELIST, D3DPT_LINESTRIP, D3DPT_TRIANGLELIST, D3DPT_TRIANGLESTRIP, D3DPT_TRIANGLEFAN, LPDIRECT3DVERTEXBUFFER9, LPDIRECT3DTEXTURE9, and D3DPOOL_DEFAULT.

Relevant C# Keywords: VertexBuffer, CustomVertex.PositionColored, CustomVertex.PositionColored.Format, Usage.Dynamic, Usage.WriteOnly, Pool.Default, Position, Color, SetData, VertexFormat, SetStreamSource, DrawPrimitives, PrimitiveType.PointList, PrimitiveType.LineList, PrimitiveType.LineStrip, PrimitiveType.TriangleList, PrimitiveType.TriangleStrip, and PrimitiveType.TriangleFan.

  •  Download (Last Updated: 06/06/05 - C++)
  •  Download (Last Updated: 06/15/05 - C#)

 

Vertex Data (Vertex Buffers)
 

Demonstrates how to use Vertex Buffers for the storage of model data. The sample creates a textured cube as an example. Check out the OpenGL source code page for a Vertex Array sample which is OpenGL's equivalent of Direct3D's Vertex Buffers.

Relevant C++ Keywords: CreateVertexBuffer, Lock, Unlock, SetStreamSource, SetTexture, SetFVF, DrawPrimitive, LPDIRECT3DVERTEXBUFFER9, LPDIRECT3DTEXTURE9, D3DPT_TRIANGLESTRIP, and D3DPOOL_DEFAULT.

Relevant C# Keywords: VertexFormats.Position. VertexFormats.Texture1, VertexBuffer, DateTime, TimeSpan, GraphicsStream, Lock, Write, Unlock, SetTexture, DrawPrimitives, SamplerState[0].MinFilter, SamplerState[0].MagFilter, TextureFilter.Linear, Texture, Bitmap, Bitmap.FromFile, Pool.Managed, and System.IO.Directory.SetCurrentDirectory.

  •  Download (Last Updated: 06/06/05 - C++)
  •  Download (Last Updated: 06/15/05 - C#)

 

Multiple Vertex Buffers
 

This sample demonstrates how to create 3D geometry with Direct3D by loading vertex data into multiple Vertex Buffers. Check out the OpenGL source code page for the OpenGL equivalent of this sample, which uses multiple Vertex Arrays.

Relevant Keywords: CreateVertexBuffer, Lock, Unlock, SetStreamSource, SetTexture, SetFVF, DrawPrimitive, CreateVertexDeclaration, SetVertexDeclaration, SetStreamSource, D3DDECL_END, LPDIRECT3DVERTEXDECLARATION9, D3DVERTEXELEMENT9, D3DDECLTYPE_FLOAT3, D3DDECLTYPE_D3DCOLOR, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, D3DDECLUSAGE_COLOR, D3DDECLUSAGE_TEXCOORD LPDIRECT3DVERTEXBUFFER9, LPDIRECT3DTEXTURE9, D3DPT_TRIANGLESTRIP, and D3DPOOL_DEFAULT.

Relevant C# Keywords: VertexBuffer, Texture, Color, ToArgb, Usage.Dynamic,  Usage.WriteOnly, Pool.Default, Lock, Unlock, VertexFormats.Position, VertexFormats.Diffuse, VertexFormats.Texture1, VertexElement, DeclarationType.Float3, DeclarationType.Float2, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Position, DeclarationUsage.Color, DeclarationUsage.TextureCoordinate, SetStreamSource, SetTexture, PrimitiveType.TriangleStrip, and DrawPrimitives.

  •  Download (Last Updated: 02/11/05 - C++)
  •  Download (Last Updated: 06/15/05 - C#)

 

Indexed Geometry
 

This sample demonstrates how to optimize performance by using indexed geometry. As a demonstration, the sample reduces the vertex count of a simple cube from 24 to 8 by redefining the cube’s geometry using an indices array. Check out the OpenGLsource code page for the OpenGL equivalent of this sample.

Relevant Keywords: CreateVertexBuffer, CreateVertexBuffer, Lock, Unlock, DrawIndexedPrimitive, DrawPrimitive, D3DPT_TRIANGLESTRIP, SetStreamSource, SetIndices, SetFVF, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, , and D3DPOOL_DEFAULT.

Relevant C# Keywords: VertexBuffer, IndexBuffer, Color, ToArgb, Usage.Dynamic,  Usage.WriteOnly, Pool.Default, Lock, Unlock, VertexFormats.Position, VertexFormats.Diffuse, DeclarationType.Float3, DeclarationType.Float2, DeclarationType.Color, SetStreamSource, PrimitiveType.TriangleStrip, VertexFormat, Indices, DrawPrimitives, and DrawIndexedPrimitives.

  •  Download (Last Updated: 06/15/05 - C++)
  •  Download (Last Updated: 06/15/05 - C#)

 

Transforms
 

Demonstrates how to use concatenated translation, rotation, and scaling matrices to create a simulated solar system. And as a small bonus, the sample also demonstrates how to optimize Direct3D applications using a matrix stack to prevent continuous changes to the view matrix, which can kill your apps draw time.

On an unrelated side-note, the sample also shows how to clone a mesh so you can add additional properties to its FVF code or vertex layout. The sample uses D3DXCreateSphere to create test spheres, which originally have no color. I then clone the mesh and add colors to them for demo purposes. Check out the OpenGLsource code page for the OpenGL equivalent of this sample.

Relevant C++ Keywords: SetTransform, D3DXMatrixTranslation, D3DXMatrixRotationY, D3DXMatrixScaling, D3DXCreateSphere, CloneMeshFVF, GetVertexBuffer, GetNumVertices, D3DXCreateMatrixStack, LoadIdentity, LoadMatrix, Push, Pop, MultMatrixLocal, LPD3DXMATRIXSTACK, and LPD3DXMESH.

Relevant C# Keywords: Mesh, Mesh.Sphere, Clone, Options.Value, VertexBuffer.Lock, VertexBuffer.Unlock, LockFlags.None, NumberVertices, DrawSubset, Dispose, Matrix, MatrixStack, Matrix.LookAtLH, Transform.View, Transform.World, Vector3, Matrix.Identity, RotateY, Translate, LoadMatrix, Push, Pop, and MultiplyMatrixLocal.

  •  Download (Last Updated: 06/28/05 - C++)
  •  Download (Last Updated: 06/28/05 - C#)
Home | Source | Tools | Links
DirectX 9.0 | DirectX 8.1 | OpenGL | User Samples
Python | Linux | Miscellaneous Code | Torque
Kevin R. Harris © [2010] | All Rights Reserved

 

 


你可能感兴趣的:(很好的几个Managed Directx 例子)