|
|
我用4个vertex做一个正方形,然后贴一张图片(texture)上去。
只是想显示一幅图片而已:
VertexBuffer vb = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 4, dev, Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Default);
CustomVertex.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])vb.Lock(0,0); // Lock the buffer (which will return our structs)
// Fill up our structs
verts[0].Position = new Vector3(0, 1, 0);
verts[0].Normal = new Vector3(0, 1, 0);
verts[0].Tu = 1.0f;
verts[0].Tv = 1.0f;
verts[1].Position = new Vector3(1, 1, 0);
verts[1].Normal = new Vector3(1, 1, 0);
verts[1].Tu = 0.0f;
verts[1].Tv = 1.0f;
verts[2].Position = new Vector3(1, 0, 0);
verts[2].Normal = new Vector3(1, 0, 0);
verts[2].Tu = 0.0f;
verts[2].Tv = 0.0f;
verts[3].Position = new Vector3(0, 0, 0);
verts[3].Normal = new Vector3(0, 0, 0);
verts[3].Tu = 0.0f;
verts[3].Tv = 1.0f;
// Unlock (and copy) the data
vb.Unlock();
...
texture = TextureLoader.FromFile(dev, Application.StartupPath + @"\..\..\19.jpg");
...
device.SetTexture(0,texture);
device.TextureState[0].ColorOperation = TextureOperation.Modulate;
device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
device.TextureState[0].AlphaOperation = TextureOperation.Disable;
device.SetStreamSource(0, vertexBuffer, 0);
device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);
显示老是不对,最好的结果就是显示了两张三角形的图片。
原因是不理解Tu和Tv的意思,不好意思,我是从来没有玩过D3D的。
请大侠们简单讲解一下,谢谢! |
|