Directx 3D编程实例:多个3D球的综合Directx实例

本文是一篇关于Directx 3D编程的实例教程,讲解如何在Directx环境下实现多个3D球体的绘制。首先介绍了判断显卡是否支持Directx的步骤,然后详细阐述了具体的程序源码实现。
摘要由CSDN通过智能技术生成


    最近朋友建议我写一些关于微软云技术的博客留给学校下一届的学生们看,怕下一届的MSTC断档。于是我也觉的有这个必要。写了几篇博客之后,我觉得也有必要把这一年的学习内容放在博客做个纪念,就这样写了本篇博客。


第一步:判断显卡是否支持

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 综合举例
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1 frm = new Form1();
            if (frm.InitializeGraphics() == false)
            {
                MessageBox.Show("显卡不支持3D或者未安装配套的显卡驱动程序!");
                return;
            }
            Application.Run(frm);
        }
    }
}


第二步:程序源码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace 综合举例
{
    public partial class Form1 : Form
    {
        private Device device = null;
        private Microsoft.DirectX.Direct3D.Font d3dfont;
        private string helpString;
        private bool showHelpString = true;
        private float angle = 0;
        private bool enableRotator = true;
        private int rotatorXYZ = 0;
        private float rotateSpeed = 0.01f;        //旋转速度
        private bool enableSolidMode = true;
        private bool enableCullMode = true;
        private Mesh[] sphereMeshs;
        private float sphereRadius = 1.5f;        //小球半径
        private int sphereNumber = 18;
        private Matrix[] spherePositions;   //原始位置变换矩阵
        private float xRadius = 15.0f;        //x方向圆的半径
        private int ySpacing = 10;        //y方向相对空间大小
        private VertexBuffer vertexBuffer = null; //顶点缓冲
        private Material[] sphereMaterial;        //小球材质
        private Material[] lineMaterial;          //线的材质
        private bool enableEmissive = false;    //是否允许物体本身发光
        private Material commonSphereMaterial = new Material();
        private Material commonLineMaterial = new Material();
        private bool multiMaterial = true;
        private bool isPointLight = false;
        private bool enableLight = true;

        public Form1()
        {
            InitializeComponent();
        }
        public bool Ini
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值