LoginSignup
1

More than 5 years have passed since last update.

vs2010でmanaged directx

Last updated at Posted at 2018-08-30

概要

c#で、3Dがやりたかった。

写真

image

環境

windows vista
visualstudio 2010 pro
c# 4.0

手順

新規プロジェクトでwindows formを指定。
app.configを追加

<startup useLegacyV2RuntimeActivationPolicy="true">
  </startup>

参照を追加

Microsoft.DirectX.dll
Microsoft.DirectX.direct3d.dll
Microsoft.DirectX.direct3dx.dll

サンプルコード

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;
using System.Threading;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        private Device device = null;
        public Form1()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed = true;
                presentParams.SwapEffect = SwapEffect.Discard;
                device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);        
        }
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
            device.BeginScene();
            device.EndScene();
            device.Present();
        }
    }
}

以上。

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