示例#1
0
        static void Main(string[] args)
        {
            using var service = WindowingService.Create();

            var wci = new WindowCreateInfo(100, 100, 600, 600, "I'm rendering with DirectX11!");

            using var window = service.CreateWindow(wci);

            Initialize(window);
            BuildTriangle();
            BuildAndBindShaders();

            window.KeyDown   += (s, e) => Console.WriteLine($"Key down: {e.Key} ({e.ScanCode})");
            window.KeyUp     += (s, e) => Console.WriteLine($"Key up: {e.Key} ({e.ScanCode})");
            window.TextInput += (s, e) => Console.WriteLine($"Text input: {char.ConvertFromUtf32(e.Character)}");

            while (!window.IsCloseRequested)
            {
                Draw();
                Thread.Sleep(10);
                service.PumpEvents();
            }

            _inputLayout.Dispose();
            _inputSignature.Dispose();
            _vertexBuffer.Dispose();
            _vertexShader.Dispose();
            _pixelShader.Dispose();
            _renderTargetView.Dispose();
            _swapChain.Dispose();
            _d3dDevice.Dispose();
            _d3dDeviceContext.Dispose();
        }
示例#2
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window);
            stopwatch       = new Stopwatch();
            stopwatch.Start();

            CreateResources();

            while (window.Exists)
            {
                time[0] = (float)stopwatch.Elapsed.TotalSeconds;
                _graphicsDevice.UpdateBuffer(_uniformBuffer, 0, time);
                window.PumpEvents();
                Draw();
            }

            DisposeResources();
        }
        internal static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            GraphicsDevice = VeldridStartup.CreateGraphicsDevice(window);

            var bootstrapper = new VeldridBootstrap(GraphicsDevice);

            bootstrapper.CreateResources();
            bootstrapper.Draw(0, 0);

            while (window.Exists)
            {
                var events = window.PumpEvents();
                if (events.IsMouseDown(MouseButton.Left) && window.Exists)
                {
                    bootstrapper.Draw(events.MousePosition.X, events.MousePosition.Y);
                }
            }

            bootstrapper.DisposeResources();
        }
示例#4
0
        public static void Run()
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };

            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            GraphicsDeviceOptions options = new GraphicsDeviceOptions
            {
                PreferStandardClipSpaceYDirection = true,
                PreferDepthRangeZeroToOne         = true,
            };

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, options);

            window.Resized += () => _graphicsDevice.MainSwapchain.Resize((uint)window.Width, (uint)window.Height);

            CreateResources();

            while (window.Exists)
            {
                window.PumpEvents();
                Draw();
            }

            DisposeResources();
        }
示例#5
0
        public MainScreen()
        {
            var windowCreateInfo = new WindowCreateInfo
            {
                X                  = 100,
                Y                  = 100,
                WindowWidth        = 800,
                WindowHeight       = 600,
                WindowInitialState = WindowState.Maximized,
                WindowTitle        = "OpenShadows - Workbench"
            };

            var graphicsDeviceOptions = new GraphicsDeviceOptions(true, null, false, ResourceBindingModel.Improved, true, true, true);

            VeldridStartup.CreateWindowAndGraphicsDevice(windowCreateInfo, graphicsDeviceOptions, GraphicsBackend.Direct3D11, out Window, out Gd);

            Cl = Gd.ResourceFactory.CreateCommandList();

            ImGuiRenderer = new ImGuiRenderer(Gd, Gd.MainSwapchain.Framebuffer.OutputDescription, 800, 600, ColorSpaceHandling.Linear);
            ImGuiHelper.DeactivateIniFile();
            ImGui.StyleColorsLight();

            Window.Resized += () =>
            {
                Gd.MainSwapchain.Resize((uint)Window.Width, (uint)Window.Height);
                ImGuiRenderer.WindowResized(Window.Width, Window.Height);
            };

            Screens.Add(new AlfBrowserScreen());
            Screens.Add(new LevelBrowserScreen());
        }
示例#6
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window);

            CreateResources();

            while (window.Exists)
            {
                window.PumpEvents();

                if (window.Exists)
                {
                    Draw();
                }
            }

            DisposeResources();
        }
示例#7
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            GraphicsDeviceOptions options = new GraphicsDeviceOptions
            {
                PreferStandardClipSpaceYDirection = true,
                PreferDepthRangeZeroToOne         = true
            };

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, options, GraphicsBackend.Metal);

            CreateResources();

            while (window.Exists)
            {
                window.PumpEvents();

                if (window.Exists)
                {
                    Draw();
                }
            }

            DisposeResources();
        }
示例#8
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowHeight = 540,
                WindowWidth  = 960,
                WindowTitle  = "Hello World"
            };

            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window);

            _shaderResourceManager = new ShaderResourceManager(_graphicsDevice);

            CreateResources();

            _stopWatch = Stopwatch.StartNew();

            while (window.Exists)
            {
                window.PumpEvents();
                Draw();
                Console.WriteLine($"{_stopWatch.ElapsedMilliseconds / 1000}s");
            }
            _stopWatch.Stop();

            DisposeResources();
        }
示例#9
0
        public async Task Run()
        {
            var task = Task.Run(() =>
            {
                //--TODO: These values should come from the MainView in the future
                var windowCI = new WindowCreateInfo()
                {
                    X            = 100,
                    Y            = 100,
                    WindowHeight = 540,
                    WindowWidth  = 960,
                    WindowTitle  = "Veldrid Tutorial"
                };

                _window         = VeldridStartup.CreateWindow(windowCI);
                _graphicsDevice = VeldridStartup.CreateGraphicsDevice(_window);

                //--_window.BorderVisible = false; -- This is nice for a future state where we can render the title bar better...

                // _View = new MyView();

                //_View.Initialize(_Window, _graphicsDevice);

                WindowLoop();

                DisposeResources();
            });

            await task;
        }
示例#10
0
        static void Main(string[] args)
        {
            //var sonic06File = new Sonic06XnoReader("C:/Users/playmer/AppData/Local/Hyper_Development_Team/Sonic '06 Toolkit/Archives/68236/0tiors2s.003/enemy/win32/enemy/eBomber/en_eBomber.xno");

            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            var renderer = new Renderer(window);

            renderer.CreateResources();

            while (window.Exists)
            {
                var snapShot = window.PumpEvents();
                renderer.mImguiRenderer.Update(1f / 60f, snapShot); // [2]

                if (window.Exists)
                {
                    renderer.Transform();
                    renderer.Draw();
                }
            }
        }
示例#11
0
        private void ChangeBackend(GraphicsBackend backend)
        {
            DestroyAllObjects();
            bool syncToVBlank = _gd.SyncToVerticalBlank;

            _gd.Dispose();

            if (_recreateWindow)
            {
                WindowCreateInfo windowCI = new WindowCreateInfo
                {
                    X                  = _window.X,
                    Y                  = _window.Y,
                    WindowWidth        = _window.Width,
                    WindowHeight       = _window.Height,
                    WindowInitialState = _window.WindowState,
                    WindowTitle        = "Veldrid NeoDemo"
                };

                _window.Close();

                _window          = VeldridStartup.CreateWindow(ref windowCI);
                _window.Resized += () => _windowResized = true;
            }

            GraphicsDeviceOptions gdOptions = new GraphicsDeviceOptions(false, null, syncToVBlank);

#if DEBUG
            gdOptions.Debug = true;
#endif
            _gd = VeldridStartup.CreateGraphicsDevice(_window, gdOptions, backend);

            CreateAllObjects();
        }
示例#12
0
    public void CreateWindow(int x, int y, int width, int height)
    {
        if (_window != null)
        {
            return;
        }

        var windowInfo = new WindowCreateInfo
        {
            X                  = x,
            Y                  = y,
            WindowWidth        = _window?.Width ?? width,
            WindowHeight       = _window?.Height ?? height,
            WindowInitialState = _window?.WindowState ?? WindowState.Normal,
            WindowTitle        = "UAlbion"
        };

        _window = VeldridStartup.CreateWindow(ref windowInfo);
        _window.CursorVisible = false;
        _window.Resized      += () => Raise(new WindowResizedEvent(_window.Width, _window.Height));
        _window.Closed       += () => Raise(new WindowClosedEvent());
        _window.FocusGained  += () => Raise(new FocusGainedEvent());
        _window.FocusLost    += () => Raise(new FocusLostEvent());
        Raise(new WindowResizedEvent(_window.Width, _window.Height));
    }
示例#13
0
        public Window(WindowCreateInfo windowCreateInfo, Audio audio)
        {
            BuildTimeline(this);
            _timeline.Execute(_time.Elapsed);
            //_swLifetime.Start();
            _swThisSecond.Start();
            _window        = VeldridStartup.CreateWindow(ref windowCreateInfo);
            _window.Shown += _window_Shown;
            _gd            = VeldridStartup.CreateGraphicsDevice(
                _window,
                new GraphicsDeviceOptions {
                PreferStandardClipSpaceYDirection = true, SyncToVerticalBlank = true
            },
                GraphicsBackend.OpenGL);
            _factory = _gd.ResourceFactory;
            _audio   = audio;

            _window.CursorVisible = false;

            _cl = _factory.CreateCommandList();

            _textureRenderer     = new TextureRenderer(_gd, DefaultShaders.FragmentCode, Time, View);
            _passthroughRenderer = new PassthroughRenderer(_gd, _textureRenderer.Texture, Time);

            audio.OnRepeat           += (s, a) => SyncAudio();
            _time.OnStart            += (s, a) => audio.Play();
            _time.OnStop             += (s, a) => audio.Stop();
            _time.OnStep             += (s, a) => SyncAudio();
            _time.OnTimescaleChanged += (s, a) => audio.PlaybackRate = (float)((Time)s).Timescale;

            //_time.SetTime(TimeSpan.FromSeconds(108));
        }
示例#14
0
文件: Program.cs 项目: my0n/Wrecker
        static void Main(string[] args)
        {
            WindowCreateInfo wci = new WindowCreateInfo
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 1280,
                WindowHeight = 720,
                WindowTitle  = "Tortuga Demo"
            };
            GraphicsDeviceOptions options = new GraphicsDeviceOptions(
                debug: false,
                swapchainDepthFormat: PixelFormat.R16_UNorm,
                syncToVerticalBlank: true,
                resourceBindingModel: ResourceBindingModel.Improved,
                preferDepthRangeZeroToOne: true,
                preferStandardClipSpaceYDirection: true);

#if DEBUG
            options.Debug = true;
#endif

            var app = new WreckerApp(new ResourceLoader(), new Scene());

            app.Start(wci, options).Wait();
        }
示例#15
0
        public SampleApplication()
        {
            WindowCreateInfo wci = new WindowCreateInfo
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = GetTitle(),
            };

            _window          = VeldridStartup.CreateWindow(ref wci);
            _window.Resized += () =>
            {
                _windowResized = true;
                OnWindowResized();
            };
            _window.MouseMove += OnMouseMove;
            _window.KeyDown   += OnKeyDown;

            GraphicsDeviceOptions options = new GraphicsDeviceOptions(false, PixelFormat.R16_UNorm, true);

#if DEBUG
            options.Debug = true;
#endif
            _gd = VeldridStartup.CreateGraphicsDevice(_window, options);
        }
示例#16
0
        public static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X           = 100, Y = 100,
                WindowWidth = 960, WindowHeight = 540,
                WindowTitle = "Veldrid TinyDemo",
            };
            RenderContextCreateInfo contextCI = new RenderContextCreateInfo();

            VeldridStartup.CreateWindowAndRenderContext(ref windowCI, ref contextCI, out var window, out RenderContext rc);

            VertexBuffer vb = rc.ResourceFactory.CreateVertexBuffer(Cube.Vertices, new VertexDescriptor(VertexPositionColor.SizeInBytes, 2), false);
            IndexBuffer  ib = rc.ResourceFactory.CreateIndexBuffer(Cube.Indices, false);

            string folder    = rc.BackendType == GraphicsBackend.Direct3D11 ? "HLSL" : "GLSL";
            string extension = rc.BackendType == GraphicsBackend.Direct3D11 ? "hlsl" : "glsl";

            VertexInputLayout inputLayout = rc.ResourceFactory.CreateInputLayout(new VertexInputDescription[]
            {
                new VertexInputDescription(
                    new VertexInputElement("Position", VertexSemanticType.Position, VertexElementFormat.Float3),
                    new VertexInputElement("Color", VertexSemanticType.Color, VertexElementFormat.Float4))
            });

            string vsPath = Path.Combine(AppContext.BaseDirectory, folder, $"vertex.{extension}");
            string fsPath = Path.Combine(AppContext.BaseDirectory, folder, $"fragment.{extension}");

            Shader vs = rc.ResourceFactory.CreateShader(ShaderStages.Vertex, File.ReadAllText(vsPath));
            Shader fs = rc.ResourceFactory.CreateShader(ShaderStages.Fragment, File.ReadAllText(fsPath));

            ShaderSet shaderSet = rc.ResourceFactory.CreateShaderSet(inputLayout, vs, fs);
            ShaderResourceBindingSlots bindingSlots = rc.ResourceFactory.CreateShaderResourceBindingSlots(
                shaderSet,
                new ShaderResourceDescription("ViewProjectionMatrix", ShaderConstantType.Matrix4x4));
            ConstantBuffer viewProjectionBuffer = rc.ResourceFactory.CreateConstantBuffer(ShaderConstantType.Matrix4x4);

            while (window.Exists)
            {
                InputSnapshot snapshot = window.PumpEvents();
                rc.ClearBuffer();

                rc.SetViewport(0, 0, window.Width, window.Height);
                float timeFactor = Environment.TickCount / 1000f;
                viewProjectionBuffer.SetData(
                    Matrix4x4.CreateLookAt(
                        new Vector3(2 * (float)Math.Sin(timeFactor), (float)Math.Sin(timeFactor), 2 * (float)Math.Cos(timeFactor)),
                        Vector3.Zero,
                        Vector3.UnitY)
                    * Matrix4x4.CreatePerspectiveFieldOfView(1.05f, (float)window.Width / window.Height, .5f, 10f));
                rc.SetVertexBuffer(0, vb);
                rc.IndexBuffer = ib;
                rc.ShaderSet   = shaderSet;
                rc.ShaderResourceBindingSlots = bindingSlots;
                rc.SetConstantBuffer(0, viewProjectionBuffer);
                rc.DrawIndexedPrimitives(Cube.Indices.Length);

                rc.SwapBuffers();
            }
        }
示例#17
0
        public NeoDemo()
        {
            WindowCreateInfo windowCI = new WindowCreateInfo
            {
                X                  = 50,
                Y                  = 50,
                WindowWidth        = 960,
                WindowHeight       = 540,
                WindowInitialState = WindowState.Normal,
                WindowTitle        = "Veldrid NeoDemo"
            };
            GraphicsDeviceCreateInfo gdCI = new GraphicsDeviceCreateInfo();

            //gdCI.Backend = GraphicsBackend.Vulkan;
#if DEBUG
            gdCI.DebugDevice = true;
#endif

            VeldridStartup.CreateWindowAndGraphicsDevice(ref windowCI, ref gdCI, out _window, out _gd);
            _window.Resized += () => _windowResized = true;

            CommandList initCL = _gd.ResourceFactory.CreateCommandList();
            _gd.SetResourceName(initCL, "Initialization Command List");
            initCL.Begin();

            _scene = new Scene(_window.Width, _window.Height);

            _sc.SetCurrentScene(_scene, initCL);

            _igRenderable   = new ImGuiRenderable(_window.Width, _window.Height);
            _resizeHandled += (w, h) => _igRenderable.WindowResized(w, h);
            _scene.AddRenderable(_igRenderable);
            _scene.AddUpdateable(_igRenderable);

            Skybox skybox = Skybox.LoadDefaultSkybox();
            _scene.AddRenderable(skybox);

            AddSponzaAtriumObjects(initCL);
            _sc.Camera.Position = new Vector3(-80, 25, -4.3f);
            _sc.Camera.Yaw      = -MathF.PI / 2;
            _sc.Camera.Pitch    = -MathF.PI / 9;

            ShadowmapDrawer texDrawer = new ShadowmapDrawer(() => _window, () => _sc.NearShadowMapView);
            _resizeHandled    += (w, h) => texDrawer.OnWindowResized();
            texDrawer.Position = new Vector2(10, 25);
            _scene.AddRenderable(texDrawer);

            ShadowmapDrawer texDrawer2 = new ShadowmapDrawer(() => _window, () => _sc.MidShadowMapView);
            _resizeHandled     += (w, h) => texDrawer2.OnWindowResized();
            texDrawer2.Position = new Vector2(20 + texDrawer2.Size.X, 25);
            _scene.AddRenderable(texDrawer2);

            ShadowmapDrawer texDrawer3 = new ShadowmapDrawer(() => _window, () => _sc.FarShadowMapView);
            _resizeHandled     += (w, h) => texDrawer3.OnWindowResized();
            texDrawer3.Position = new Vector2(30 + (texDrawer3.Size.X * 2), 25);
            _scene.AddRenderable(texDrawer3);

            CreateAllObjects();
        }
示例#18
0
        public RenderView(RenderViewSettings settings)
        {
            WindowCreateInfo windowCI = settings != null ?
                                        new WindowCreateInfo()
            {
                X            = settings.X,
                Y            = settings.Y,
                WindowWidth  = settings.Width,
                WindowHeight = settings.Height,
                WindowTitle  = settings.Title,
            } :
            new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Herno"
            };

            Window = VeldridStartup.CreateWindow(ref windowCI);

            GraphicsDeviceOptions options = new GraphicsDeviceOptions
            {
                PreferStandardClipSpaceYDirection = true,
                PreferDepthRangeZeroToOne         = true
            };

            void CreateAndAddCursor(SDL_SystemCursor type)
            {
                //var cursor = Sdl2Native.SDL_CreateSystemCursor(type);
                //cursorMap.Add(type, cursor);
            }

            CreateAndAddCursor(SDL_SystemCursor.Arrow);
            CreateAndAddCursor(SDL_SystemCursor.Crosshair);
            CreateAndAddCursor(SDL_SystemCursor.Hand);
            CreateAndAddCursor(SDL_SystemCursor.IBeam);
            CreateAndAddCursor(SDL_SystemCursor.No);
            CreateAndAddCursor(SDL_SystemCursor.SizeAll);
            CreateAndAddCursor(SDL_SystemCursor.SizeNESW);
            CreateAndAddCursor(SDL_SystemCursor.SizeNS);
            CreateAndAddCursor(SDL_SystemCursor.SizeNWSE);
            CreateAndAddCursor(SDL_SystemCursor.SizeWE);
            CreateAndAddCursor(SDL_SystemCursor.Wait);
            CreateAndAddCursor(SDL_SystemCursor.WaitArrow);

            GraphicsDevice = dispose.Add(VeldridStartup.CreateGraphicsDevice(Window, options, GraphicsBackend.Direct3D11));

            Window.Resized += () =>
            {
                GraphicsDevice.MainSwapchain.Resize((uint)Window.Width, (uint)Window.Height);
            };
        }
示例#19
0
        public int OnExecute()
        {
            _cellSize  = LowResolution ? LowResCellSize : HighResCellSize;
            _worldSize = new Vector2(Width, Height);

            Configuration.Default.MemoryAllocator = new SixLabors.Memory.SimpleGcMemoryAllocator();
            int width  = (int)(_worldSize.X * _cellSize);
            int height = (int)(_worldSize.Y * _cellSize);
            WindowCreateInfo      wci     = new WindowCreateInfo(50, 50, width, height, WindowState.Normal, "Snake");
            GraphicsDeviceOptions options = new GraphicsDeviceOptions();

            _window = new Sdl2Window("Snake", 50, 50, width, height, SDL_WindowFlags.OpenGL, false);
#if DEBUG
            options.Debug = true;
#endif
            options.SyncToVerticalBlank  = true;
            options.ResourceBindingModel = ResourceBindingModel.Improved;
            _gd             = VeldridStartup.CreateGraphicsDevice(_window, options);
            _cl             = _gd.ResourceFactory.CreateCommandList();
            _spriteRenderer = new SpriteRenderer(_gd);

            _window.Resized += () => _gd.ResizeMainWindow((uint)_window.Width, (uint)_window.Height);

            _world        = new World(_worldSize, _cellSize);
            _snake        = new Snake(_world);
            _textRenderer = new TextRenderer(_gd);
            _textRenderer.DrawText("0");
            _snake.ScoreChanged += () => _textRenderer.DrawText(_snake.Score.ToString());
            _snake.ScoreChanged += () => _highScore = Math.Max(_highScore, _snake.Score);

            Stopwatch sw           = Stopwatch.StartNew();
            double    previousTime = sw.Elapsed.TotalSeconds;
            while (_window.Exists)
            {
                InputSnapshot snapshot = _window.PumpEvents();
                Input.UpdateFrameInput(snapshot);

                double newTime = sw.Elapsed.TotalSeconds;
                double elapsed = newTime - previousTime;
                previousTime = newTime;
                Update(elapsed);

                if (_window.Exists)
                {
                    DrawFrame();
                }
            }

            _gd.Dispose();

            Console.WriteLine($"Thanks for playing! Your high score was {_highScore}.");
            return(_snake.Score);
        }
示例#20
0
        public VeldridHost(string title)
        {
            WindowCreateInfo wci = new WindowCreateInfo
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 1280,
                WindowHeight = 720,
                WindowTitle  = title,
            };

            window          = VeldridStartup.CreateWindow(ref wci);
            window.Resized += () => windowResized = true;
            window.KeyDown += OnKeyDown;
        }
示例#21
0
        private void InitGraphics()
        {
            var windowCi = new WindowCreateInfo
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = WindowWidth,
                WindowHeight = WindowHeight,
                WindowTitle  = WindowTitle
            };

            _window = VeldridStartup.CreateWindow(ref windowCi);

            Renderer.Initialize(_window);
        }
示例#22
0
文件: VxContext.cs 项目: mellinoe/Vx
        public static void Initialize()
        {
            lock (s_initializationLock)
            {
                if (s_instance != null)
                {
                    throw new VxException("VxContext has already been initialized.");
                }

                WindowCreateInfo      wci     = new WindowCreateInfo(50, 50, 1280, 720, WindowState.Normal, Assembly.GetEntryAssembly().GetName().Name);
                GraphicsDeviceOptions options = new GraphicsDeviceOptions(false, PixelFormat.R16_UNorm, true, ResourceBindingModel.Improved, true, true);
                VeldridStartup.CreateWindowAndGraphicsDevice(wci, options, out Sdl2Window window, out GraphicsDevice gd);
                s_instance = new VxContext(gd, window);
            }
        }
示例#23
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window);

            textRenderer = new TextRender.TextRenderer(_graphicsDevice);
            text         = new Text(textRenderer, "Hello world!")
            {
                Position = new Vector2(200, 100),
                FontSize = 24,
                Color    = RgbaFloat.White
            };
            text.Initialize();

            text2 = new Text(textRenderer, "Test")
            {
                Position  = new Vector2(400, 150),
                FontSize  = 36,
                FontStyle = FontStyle.Bold,
                FontName  = "Courier New",
                Color     = RgbaFloat.Yellow
            };
            text2.Initialize();

            CreateResources();

            while (window.Exists)
            {
                window.PumpEvents();

                if (window.Exists)
                {
                    Draw();
                    Thread.Sleep(1);
                }
            }

            DisposeResources();
        }
示例#24
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };

            window = VeldridStartup.CreateWindow(ref windowCI);

            s          = new GShader(window);
            s.fillMode = PolygonFillMode.Solid;
            s.topo     = PrimitiveTopology.PointList;

            List <VertexPositionColour> verts = new List <VertexPositionColour>()
            {
                new VertexPositionColour(new Vector2(0.9f, 0.9f), new RgbaFloat(1, 1, 1, 1)),
                new VertexPositionColour(new Vector2(-0.9f, 0.9f), new RgbaFloat(1, 1, 1, 1)),
                new VertexPositionColour(new Vector2(-0.9f, -0.9f), new RgbaFloat(1, 1, 1, 1)),
                new VertexPositionColour(new Vector2(0.9f, -0.9f), new RgbaFloat(1, 1, 1, 1))
            };

            //INITIALISE VERTEX SET HERE


            s.verteces = verts;
            s.GenerateIndeces();
            s.CreateResources();

            Thread vertexThread = new Thread(new ThreadStart(WaitForVertex));

            vertexThread.Start();

            while (window.Exists)
            {
                window.PumpEvents();
                if (updateFromThread1)
                {
                    AddVertex(/*INSERT FUNCTION TO GENERATE ONE RANDOM VERTEX HERE*/);
                    updateFromThread1 = false;
                }
                s.Draw();
            }
            s.DisposeResources();
        }
示例#25
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 1920,
                Y            = 100,
                WindowWidth  = 1920,
                WindowHeight = 1920,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, GraphicsBackend.OpenGL);

            CreateResources(window);

            var pty         = new LinuxPty();
            var readStream  = new ConsoleLoggingStream(pty.ReadStream, "READ");
            var writeStream = new ConsoleLoggingStream(pty.WriteStream, "WRIT");

            var charsWidth  = (int)(window.Width / (float)_fontAtlas.CellWidth);
            var charsHeight = (int)(window.Height / (float)_fontAtlas.CellHeight);

            pty.SetSize(charsWidth, charsHeight);

            _tokenizer = new OutputTokenizer(_textLayout);

            var inputProcessor = new InputKeyStreamer {
                OutStream = writeStream
            };

#pragma warning disable 4014
            PipePtyToScreen(readStream);
#pragma warning restore 4014

            while (window.Exists)
            {
                var input = window.PumpEvents();
                inputProcessor.ProcessToStream(input);

                if (window.Exists)
                {
                    Draw();
                }
            }

            DisposeResources();
        }
示例#26
0
        static void Main(string[] args)
        {
            WindowCreateInfo wci = new WindowCreateInfo
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 1280,
                WindowHeight = 720,
                WindowTitle  = "Tortuga Demo"
            };
            GraphicsDeviceOptions options = new GraphicsDeviceOptions(
                debug: false,
                swapchainDepthFormat: PixelFormat.R16_UNorm,
                syncToVerticalBlank: true,
                resourceBindingModel: ResourceBindingModel.Improved,
                preferDepthRangeZeroToOne: true,
                preferStandardClipSpaceYDirection: true);

#if DEBUG
            options.Debug = true;
#endif

            _editorMenu = new EditorMenu();

            Message <TransformMessageApplier>();
            Message <InputForceApplier>();
            Message <SimpleCameraMover>();
            Message <ClientEntityAssignmentApplier>();
            Message <VoxelSpaceMessageApplier>();
            Message <VoxelGridMessageApplier>();
            Message <VoxelGridChangeMessageApplier>();
            Message <EntityRemover>();
            Message <VoxelEditReceiver>();
            Message <VoxelSpaceLoadReciever>();
            Message <ComponentSyncMessageApplier <EntityMetaData> >();

            _messageTargetMap = new MessageTargetMap(_byType, _byNum);

            _clientMessagingChannel = new MessagingChannel(_messageTargetMap);
            _client          = new ClunkerClientApp(new ResourceLoader(), _messageTargetMap, _clientMessagingChannel);
            _client.Started += _client_Started;

            _server          = new ClunkerServerApp();
            _server.Started += _server_Started;

            var serverTask = _server.Start();
            _client.Start(wci, options).Wait();
        }
示例#27
0
        public IDrawspace GetDrawspace(IRect2D subRect)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = (int)subRect.Position.X,
                Y            = (int)subRect.Position.Y,
                WindowWidth  = (int)subRect.Size.X,
                WindowHeight = (int)subRect.Size.Y,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window _window = VeldridStartup.CreateWindow(ref windowCI);

            _windowList.Add(_window);
            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(_window);
            return(new VeldridDrawspace(_window));
        }
示例#28
0
        public Window(int width, int height, string title)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 800,
                WindowHeight = 600,
                WindowTitle  = title
            };

            SdlWindow = VeldridStartup.CreateWindow(ref windowCI);

            GraphicsDevice = VeldridStartup.CreateGraphicsDevice(SdlWindow);
            CommandList    = GraphicsDevice.ResourceFactory.CreateCommandList();
        }
示例#29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameWindow"/> class.
        /// </summary>
        /// <param name="title">The title.</param>
        public GameWindow(string title)
        {
            var windowCreateInfo = new WindowCreateInfo
            {
                X            = Sdl2Native.SDL_WINDOWPOS_CENTERED,
                Y            = Sdl2Native.SDL_WINDOWPOS_CENTERED,
                WindowWidth  = Configuration.ChunkWidth * Configuration.TileSize,
                WindowHeight = Configuration.ChunkHeight * Configuration.TileSize,
                WindowTitle  = title,
            };

            this.window           = VeldridStartup.CreateWindow(ref windowCreateInfo);
            this.window.Resizable = false;
            this.window.Resized  += () => { this.windowResized = true; };
            this.window.KeyDown  += this.OnKeyDown;
        }
示例#30
0
        public VeldridStartupWindow(string title, ViewerOptions options)
        {
            _options = options;
            var wci = new WindowCreateInfo
            {
                X                  = 100,
                Y                  = 100,
                WindowWidth        = 1280,
                WindowHeight       = 720,
                WindowTitle        = title,
                WindowInitialState = _options.WindowState
            };

            _window          = VeldridStartup.CreateWindow(ref wci);
            _window.Resized += () => { _windowResized = true; };
            _window.KeyDown += OnKeyDown;
        }