Программирование - это просто
Advertisement
arrow C# arrow C# arrow C#. 4. (VertexBuffer, PresentParameters)
01.02.2023 .
1:
C#
Delphi
Web-
Excel-
.
C#. 4. (VertexBuffer, PresentParameters) E-mail
megabax   
16.09.2011 .
New Page 2

C#. 4. (VertexBuffer, PresentParameters)

.

3 DirectX. DirectX . :

    C#.  4.   (VertexBuffer, PresentParameters)

VertexBuffer GraphicsStream, Microsoft.DirectX.Direct3D. 3. . FormChild VertexBuffer ( ) :

    public partial class FormChild : Form

    {

        private Device device=null;

        private VertexBuffer vertexBuffer;

        public FormChild()

        {

            InitializeComponent();

        }

 

...

 

 

initializeDirectX, VertexBuffer:

        public bool initializeDirectX()

        {

            try

            {

                PresentParameters presPars = new PresentParameters();

                presPars.Windowed = true;

                presPars.SwapEffect = SwapEffect.Discard;

                device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presPars);

                this.OnCreateDevice(device, null);

                return true;

            }

            catch (DirectXException e)

            {

                MessageBox.Show(" DirectX "+e.ErrorString);

                return false;

            }

        }

VertexBuffer OnCreateDevice FormChild:

        public void OnCreateDevice(object sender, EventArgs e)

        {

            //

            vertexBuffer = new VertexBuffer(

                typeof(CustomVertex.TransformedColored),

                3,

                device,

                0,

                CustomVertex.TransformedColored.Format,

                Pool.Default);

            vertexBuffer.Created += new System.EventHandler(this.OnCreateVertexBuffer);

            this.OnCreateVertexBuffer(vertexBuffer,null);

        }

"" VertexBuffer:

            vertexBuffer.Created += new System.EventHandler(this.OnCreateVertexBuffer);

            this.OnCreateVertexBuffer(vertexBuffer,null);

, , :

        public void OnCreateVertexBuffer(object sender, EventArgs e)

        {

            GraphicsStream graphicsStream = vertexBuffer.Lock(0, 0, 0);

            CustomVertex.TransformedColored[] vertex=new CustomVertex.TransformedColored[3];

 

            // 0

            vertex[0].X = 150;

            vertex[0].Y = 50;

            vertex[0].Z = 0.5f;

            vertex[0].Rhw = 1;

            vertex[0].Color = System.Drawing.Color.Black.ToArgb();

 

            // 1

            vertex[1].X = 250;

            vertex[1].Y = 70;

            vertex[1].Z = 0.5f;

            vertex[1].Rhw = 1;

            vertex[1].Color = System.Drawing.Color.LightPink.ToArgb();

 

            // 2

            vertex[2].X = 50;

            vertex[2].Y = 250;

            vertex[2].Z = 0.5f;

            vertex[2].Rhw = 1;

            vertex[2].Color = System.Drawing.Color.Aqua.ToArgb();

 

            //

            graphicsStream.Write(vertex);

            vertexBuffer.Unlock();

        }

:

        public void rendering()

        {

            if (device == null) return;

 

            // ()

            device.Clear(ClearFlags.Target, System.Drawing.Color.White, 1.0f, 0);

 

            //

            device.BeginScene();

            device.SetStreamSource(0, vertexBuffer, 0);

            device.VertexFormat = CustomVertex.TransformedColored.Format;

            device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

            device.EndScene();

            device.Present();

        }

, . , , .

. OnCreateVertexBuffer :

    C#.  4.   (VertexBuffer, PresentParameters)

( Color):

    C#.  4.   (VertexBuffer, PresentParameters)

 


, ,    "Microsoft Visual Studio 2010", Microsoft


 

 

( 06.11.2011 . )
 
« .   . »
 
© 2023 Программирование - это просто
Joomla! - , GNU/GPL.
© 2005-2008 Joom.Ru - Joomla!
Design by Mamboteam.com | Powered by Mambobanner.de
  .