1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
using Microsoft.DirectX; using Microsoft.DirectX.Direct3D;
namespace DxVorlage2 { public partial class Form1 : Form { public Device m_Device;
public CustomVertex.TransformedColored[] verts; public VertexBuffer m_VertexBuffer;
public Form1() { InitializeComponent(); if (!InitDX()) { MessageBox.Show("Fehler beim initialisieren von DirectX"); Application.Exit(); } CreateVertexBuffer(); } public void CreateVertexBuffer() { verts = new CustomVertex.TransformedColored[3];
verts[0].X = 150; verts[0].Y = 50; verts[0].Z = 0.5f; verts[0].Rhw = 1; verts[0].Color = Color.Yellow.ToArgb(); verts[1].X = 250; verts[1].Y = 250; verts[1].Z = 0.5f; verts[1].Rhw = 1; verts[1].Color = Color.Bisque.ToArgb(); verts[2].X = 50; verts[2].Y = 250; verts[2].Z = 0.5f; verts[2].Rhw = 1; ; verts[2].Color = Color.White.ToArgb();
m_VertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored), 3, m_Device, Usage.WriteOnly, CustomVertex.TransformedColored.Format, Pool.Default);
GraphicsStream stream = m_VertexBuffer.Lock(0, 0, 0);
stream.Write(verts); m_VertexBuffer.Unlock(); } public bool InitDX() { try { PresentParameters pp = new PresentParameters(); pp.Windowed = true; pp.SwapEffect = SwapEffect.Discard;
m_Device = new Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, pp); } catch (DirectXException e) { MessageBox.Show(e.Message, "Fehler"); return false; } return true; } public void Render() { m_Device.Clear(ClearFlags.Target, Color.Blue, 0.0f, 0); m_Device.BeginScene();
m_Device.Transform.World = Matrix.Identity; int iTime = Environment.TickCount % 1000; float fAngle = iTime * (2.0f * (float)Math.PI) / 1000.0f; m_Device.Transform.World = Matrix.RotationX(fAngle); m_Device.Transform.World = Matrix.Translation(1.0f, 0.0f, 0.0f); m_Device.Transform.World = Matrix.Scaling(1.5f, 1.0f, 1.0f);
m_Device.VertexFormat = CustomVertex.TransformedColored.Format; m_Device.SetStreamSource(0, m_VertexBuffer, 0); m_Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 1);
m_Device.EndScene(); m_Device.Present(); } public void ShutDown() { m_Device.Dispose(); } } } |