cscの作法 その118

# 概要
cscの作法、調べてみた。
managed directxやってみた。
テクスチャーを使ってみた。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/09f1f1f6-a80b-5752-0b6b-3f84f741b0c2.png)

# サンプルコード


```
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace mdx
{
	public partial class Form1 : Form {
		private Device device = null;
		private Mesh _boxMesh = null;
		private Mesh _sphereMesh = null;
		private Mesh _teapotMesh = null;
		private Texture _texture;
		private VertexBuffer _vertexBuffer;
		public Form1() {
			Text = "Form1";
			this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
			PresentParameters pp = new PresentParameters();
			pp.Windowed = true;
			pp.SwapEffect = SwapEffect.Discard;
			device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, pp);
			_boxMesh = Mesh.Box(device, 2.0f, 1.0f, 0.5f);
			_sphereMesh = Mesh.Sphere(device, 0.8f, 8, 6);
			_teapotMesh = Mesh.Teapot(device);
			_texture = TextureLoader.FromFile(device, Application.StartupPath + @"\sprite-animation4.jpg");
			_vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, device, 0, CustomVertex.PositionTextured.Format, Pool.Managed);
			CustomVertex.PositionTextured[] verts = new CustomVertex.PositionTextured[4];
			verts[0].Position = new Vector3(3, 3, 0);
			verts[0].Tu = 0;
			verts[0].Tv = 0;
			verts[1].Position = new Vector3(-3, 3, 0);
			verts[1].Tu = 1;
			verts[1].Tv = 0;
			verts[2].Position = new Vector3(3, -3, 0);
			verts[2].Tu = 0;
			verts[2].Tv = 1;
			verts[3].Position = new Vector3(-3, -3, 0);
			verts[3].Tu = 1;
			verts[3].Tv = 1;
			GraphicsStream stm = _vertexBuffer.Lock(0, 0, 0);
			stm.Write(verts);
			_vertexBuffer.Unlock();
			this.Paint += Form1_Paint;
		}
		private void Form1_Paint(object sender, PaintEventArgs e) {
			device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 1.0f, 10.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
			device.Transform.Projection = Matrix.PerspectiveFovLH((float) (Math.PI / 4), 1.0f, 0.1f, 100.0f);
			device.Clear(ClearFlags.Target, Color.DarkBlue, 1.0f, 0);
			device.SetTexture(0, _texture);
			device.RenderState.Lighting = false;
			device.RenderState.CullMode = Cull.None;
			Matrix rotateMatrix = Matrix.RotationY(Environment.TickCount / 1000.0f);
			device.BeginScene();
			device.Transform.World = Matrix.Identity;
			device.SetStreamSource(0, _vertexBuffer, 0);
			device.VertexFormat = CustomVertex.PositionTextured.Format;
			device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
			device.SetTransform(TransformType.World, rotateMatrix * Matrix.Translation(new Vector3(0.0f, 2.0f, 0.0f)));
			_boxMesh.DrawSubset(0);
			device.SetTransform(TransformType.World, rotateMatrix * Matrix.Translation(new Vector3(0.0f, -2.0f, 0.0f)));
			_sphereMesh.DrawSubset(0);
			device.SetTransform(TransformType.World, rotateMatrix * Matrix.Translation(new Vector3(0.0f, 0.0f, 0.0f)));
			_teapotMesh.DrawSubset(0);
			device.EndScene();
			device.Present();
			this.Invalidate();
		}
		[STAThread]
		public static void Main() {
			Application.Run(new Form1());
		}
	}
}





```

以上。