1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vs2010でmanaged directx その14

Posted at

概要

c#で、3Dやりたかった。
hlslやってみた。

写真

image

サンプルコード

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        Device device = null;
        PresentParameters ppr = new PresentParameters();
        Effect effect;
        Mesh m;

        public Form1()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            ppr.Windowed = true;
            ppr.SwapEffect = SwapEffect.Discard;
            device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, ppr);
            m = Mesh.Teapot(device);
            try
            {
                string a;
                effect = Effect.FromFile(device, "my0.fx", null, null, ShaderFlags.None, null, out a);
             }
            catch
            {
                MessageBox.Show("ng1");
            }
        }
        private void Form1_Paint(object sender, PaintEventArgs e)
        {      
            device.BeginScene();
            device.RenderState.CullMode = Cull.None;
            device.RenderState.ZBufferEnable = true;
            device.Clear(ClearFlags.Target, Color.DarkBlue, 1f, 0);
            effect.Begin(FX.None);
            effect.BeginPass(0);            
            m.DrawSubset(0);
            effect.EndPass();
            effect.End();
            device.EndScene();
            device.Present();
            this.Invalidate();
        }
    }
}



以上。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?