DirectX Programm geht nicht im Vollbild
-
Hallo,
habe ein recht simples DirectX Programm geschrieben (in c#), welches auch wunderbar funktioniert, aber sobald ich die windowed Eigenschaft auf false setze, bekomm ich nur eine Fehlermeldung "Error in Application". Ich pack hier mal den Code rein, damit ihr vielleicht nachvolziehen könnt, was ich falsch gemacht habe. Danke für eure Hilfe!using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; namespace ManagedDirectXTutorial1 { public class MDXAvalonApp : System.Windows.Forms.Form { private Device m_Device; private CustomVertex.TransformedColored[] verts; private VertexBuffer m_VertexBuffer; public void InitGfx() { try { this.ClientSize = new Size(1024, 768); this.Text = "Codename: Avalon"; this.KeyPress += new KeyPressEventHandler(MDXAvalonApp_KeyPress); PresentParameters pp = new PresentParameters(); pp.Windowed = true; pp.SwapEffect = SwapEffect.Copy; m_Device = new Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, pp); // Vertex-Buffer mit Koordinaten füllen 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.Red.ToArgb(); verts[1].X = 250; verts[1].Y = 250; verts[1].Z = 0.5f; verts[1].Rhw = 1; verts[1].Color = Color.Green.ToArgb(); verts[2].X = 50; verts[2].Y = 250; verts[2].Z = 0.5f; verts[2].Rhw = 1; ; verts[2].Color = Color.Blue.ToArgb(); // Vertex-Buffer initialisieren m_VertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored), 3, m_Device, Usage.WriteOnly, CustomVertex.TransformedColored.Format, Pool.Default); // Daten in den Vertex-Buffer schreiben GraphicsStream stream = m_VertexBuffer.Lock(0, 0, 0); stream.Write(verts); m_VertexBuffer.Unlock(); } catch (DirectXException e) { MessageBox.Show(e.Message); } } public void Render() { m_Device.VertexFormat = CustomVertex.TransformedColored.Format; m_Device.SetStreamSource(0, m_VertexBuffer, 0); m_Device.BeginScene(); m_Device.Clear(ClearFlags.Target, Color.Black, 0.0f, 0); m_Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 1); m_Device.EndScene(); m_Device.Present(); } public void Shutdown() { m_Device.Dispose(); } void MDXAvalonApp_KeyPress(object sender, KeyPressEventArgs e) { if ((int)e.KeyChar == (int)Keys.Escape) this.Close(); } [STAThread] static void Main() { MDXAvalonApp avalon = new MDXAvalonApp(); avalon.InitGfx(); avalon.Show(); while (avalon.Created) { avalon.Render(); Application.DoEvents(); } avalon.Shutdown(); } } }
-
Du musst in den PresentParameters BackBufferWidth, BackBufferHeight usw. angeben.
Siehe dazu http://www.c-unit.com/tutorials/mdirectx/?t=29