Hallo,
ich fang gerade an mich mit DirectX zu beschäftigen ( weil das TAO Framework unter Vista irgendwie Probleme macht , schade )
Ok, ich arbeite also nach dem Tutorial hier :
www.mycsharp.de/wbb2...id=5919&hilight=
( die DirectX Tutorials die man im Netz findet sind ja eigentlich alle die gleichen )
Na ok, soweit, so gut. Hier ist der Code worums gehts :
Proghram.cs:
C#-Quelltext
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:
| using System; using System.Collections.Generic; using System.Windows.Forms;
namespace DxVorlage2 { static class Program { [STAThread] static void Main() { using (Form1 f = new Form1()) { f.Show(); while (f.Created) { f.Render(); Application.DoEvents(); } f.ShutDown(); } } } } |
Form1.designer.cs
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:
| namespace DxVorlage2 { partial class Form1 { private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }
#region Vom Windows Form-Designer generierter Code
private void InitializeComponent() { this.SuspendLayout(); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(642, 353); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false);
}
#endregion } } |
und die Form1.cs
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(); } } } |
Ok, das ist genau das was in dem Tutorial steht, allerdings drehts sich mein Dreieck nicht und wenn ich die Form resize, dann is es gleich mal ganz weg.
Warum ist das so ?
Was mach ich falsch ?
Wie mach ich das wenn ich z.B. 1000 Dreieck und 7000 Linien zu zeichnen habe ?
Bzw. eine unbestimmte Anzahl von Dreiecken , Linien und Text auszugeben habe ?
Dann geht ja
C#-Quelltext
1:
| m_VertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored), 3, m_Device, Usage.WriteOnly, CustomVertex.TransformedColored.Format, Pool.Default); |
nicht mehr.
Könnt Ihr mir da mal ein bischen weiterhelfen ?
Danke
Matthias