Autor Beitrag
goose
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 93



BeitragVerfasst: Mo 05.03.07 13:14 
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:
ausblenden 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
    {
        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            using (Form1 f = new Form1())
            {
                f.Show();
                while (f.Created)
                {
                    f.Render();
                    Application.DoEvents();
                }
                f.ShutDown();
            }
        }
    }
}


Form1.designer.cs
ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
namespace DxVorlage2
{
    partial class Form1
    {
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Vom Windows Form-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(642353);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

        #endregion
    }
}

und die Form1.cs
ausblenden volle Höhe 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:
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(000);

            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.0f0);
            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.0f0.0f0.0f);
            m_Device.Transform.World = Matrix.Scaling(1.5f1.0f1.0f);

            m_Device.VertexFormat = CustomVertex.TransformedColored.Format;
            
            m_Device.SetStreamSource(0, m_VertexBuffer, 0);
            m_Device.DrawPrimitives(PrimitiveType.TriangleStrip, 01);

            //m_Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 1, verts);

            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
ausblenden 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
goose Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 93



BeitragVerfasst: Di 06.03.07 18:54 
Hallo ???

Weiß das wirklich keiner ?

Matthias
Leuchtturm
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1087

Win Vista, Knoppix, Ubuntu
Delphi 7 Pe, Turbo Delphi, C#(VS 2005 Express), (X)HTML + CSS, bald Assembler
BeitragVerfasst: Di 06.03.07 19:02 
Ich würde dir empfehlen die Frage mal bei myCsharp.de zu stellen :wink: Hier halten sich sowieso nicht so viele c#-Programmierer auf.

_________________
Ich bin dafür verantwortlich was ich sage - nicht dafür was du verstehst.
goose Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 93



BeitragVerfasst: Di 06.03.07 20:05 
Hallo,

danke für den Hinweis, aber das hab ich auch schon gemacht.

www.mycsharp.de/wbb2...d.php?threadid=33228

Leider antwortet da auch keiner ???

Hmm....
Matthias