Пример #1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var form = new Form();

            form.ClientSize = new Size(800, 600);

            using (var device = LightDevice.Create(form))
            {
                var target = new RenderTargetList(device.GetDefaultTarget(Color.White.WithAlpha(1)));
                target.Apply();

                var sprite  = new Sprite(device);
                var guiFont = new TextureFontCache(device, SystemFonts.DefaultFont);

                form.Show();
                device.RunMultithreadLoop(delegate()
                {
                    target.ClearAll();

                    sprite.Apply();
                    sprite.DrawString(guiFont, "Hello World!", 0, 0, 800);

                    device.Present(true);
                });
            }
        }
Пример #2
0
        private void InitializeRendering()
        {
            _renderWindow = new Form();
            _renderWindow.FormBorderStyle = FormBorderStyle.None;
            _renderWindow.TopLevel        = false;
            _renderWindow.Parent          = this;
            _renderWindow.Dock            = DockStyle.Fill;
            _renderWindow.Show();

            _device            = LightDevice.Create(_renderWindow);
            _device.AutoResize = false; //We don't use loop, so AutoResize is not checked.

            _spriteDebug = new Sprite(_device);
            _spriteFont  = new TextureFontCache(_device, SystemFonts.DefaultFont);

            _target = new RenderTargetList(_device.GetDefaultTarget(Color.AliceBlue.WithAlpha(1)), _device.CreateDepthStencilTarget());
            _target.Apply();

            _modelPipeline = _device.CompilePipeline(InputTopology.Point,
                                                     ShaderSource.FromResource("Model.fx", ShaderType.Vertex | ShaderType.Geometry | ShaderType.Pixel));
            _inputProcessor = _modelPipeline.CreateVertexDataProcessor <Voxel>();

            _vsConstant = _modelPipeline.CreateConstantBuffer <Matrix4x4>();
            _modelPipeline.SetConstant(ShaderType.Vertex, 0, _vsConstant);
            _gsConstant = _modelPipeline.CreateConstantBuffer <GSConstant>();
            _modelPipeline.SetConstant(ShaderType.Geometry, 0, _gsConstant);

            _camera = new Camera(_device, new Vector3(0, 0, 0));
            _camera.SetForm(_renderWindow);

            _renderWindowLastWidth  = _renderWindow.ClientSize.Width;
            _renderWindowLastHeight = _renderWindow.ClientSize.Height;
            ResizeBegin            += RenderWindow_ResizeBegin;
            ResizeEnd += RenderWindow_ResizeEnd;
            _renderWindow.ResizeBegin       += RenderWindow_ResizeBegin;
            _renderWindow.ResizeEnd         += RenderWindow_ResizeEnd;
            _renderWindow.ClientSizeChanged += RenderWindow_ClientSizeChanged;

            _renderWindow.DoubleClick += delegate(object obj, EventArgs e)
            {
                ResetCamera();
            };
        }