示例#1
0
        private static void Main()
        {
            var app    = new ExampleApplication();
            var visual = new MainVisual();

            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            LoadResources(app.ResourceManager);

            Stopwatch globalTime       = new Stopwatch();
            bool      doPostProcessing = false;

            app.Render += () =>
            {
                float time = (float)globalTime.Elapsed.TotalSeconds;
                if (doPostProcessing)
                {
                    visual.DrawWithPostProcessing(time);
                }
                else
                {
                    visual.Draw();
                }
            };

            app.Update += (t) => doPostProcessing = !Keyboard.GetState()[Key.Space];
            app.Resize += visual.Resize;
            app.GameWindow.ConnectEvents(visual.OrbitCamera);

            globalTime.Start();
            app.Run();
        }
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.GameWindow.AddWindowAspectHandling(visual.Camera.Projection);
            var movementState = window.GameWindow.AddFirstPersonCameraEvents(visual.Camera.View);

            window.Update += (dt) => visual.Camera.View.ApplyRotatedMovement(movementState.movement * 30 * dt);
            var         sampleSeries = new ExponentialSmoothing(0.01);
            QueryObject timeQuery    = new QueryObject();

            window.Render += () =>
            {
                timeQuery.Activate(QueryTarget.TimeElapsed);
                visual.Draw();
                timeQuery.Deactivate();
                var timerQueryResult = timeQuery.ResultLong * 1e-6;
                sampleSeries.NewSample(timerQueryResult);
                window.GameWindow.Title = $"{sampleSeries.SmoothedValue:F0}ms";
            };
            window.Resize += visual.Resize;
            window.Resize += (w, h) => sampleSeries.Clear();
            window.Run();
        }
示例#3
0
        private static void Main()
        {
            var window = new ExampleWindow(debug: true);

            var camera = window.GameWindow.CreateFirstPersonCameraController(1f, new Vector3(36f, 0.1f, 30f), 70f, 0.01f, 300f);

            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.GameWindow.KeyDown += (s, a) => { if (a.Key == OpenTK.Input.Key.Tab)
                                                     {
                                                         visual.Wireframe = !visual.Wireframe;
                                                     }
            };

            var         sampleSeries = new ExponentialSmoothing(0.01);
            QueryObject timeQuery    = new QueryObject();

            window.Render += () =>
            {
                timeQuery.Activate(QueryTarget.TimeElapsed);
                visual.Draw(camera);
                timeQuery.Deactivate();
                var timerQueryResult = timeQuery.ResultLong * 1e-6;
                sampleSeries.NewSample(timerQueryResult);
                window.GameWindow.Title = $"{sampleSeries.SmoothedValue:F0}ms";
            };
            window.Resize += visual.Resize;
            window.Resize += (w, h) => sampleSeries.Clear();
            window.Run();
        }
示例#4
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MainVisual(window.RenderContext, window.ContentLoader);

            void updateMouseState(MouseEventArgs e)
            {
                var pos = window.GameWindow.ConvertWindowPixelCoords(e.X, e.Y);                 //convert pixel coordinates to [0,1]²

                pos *= .5f;
                pos += System.Numerics.Vector2.One * .5f;
                var mouseState = new MouseState()
                {
                    position  = pos,
                    drawState = GetDrawState(e.Mouse)
                };

                visual.MouseState = mouseState;
            }

            window.GameWindow.MouseMove += (s, a) => updateMouseState(a);
            window.GameWindow.MouseDown += (s, a) => updateMouseState(a);
            window.Render += visual.Render;
            window.Run();
        }
示例#5
0
        private static void Main()
        {
            var wnd    = new GameWindow();
            var resMng = new ResourceManager();

            Resources.LoadResources(resMng);
            var visual = new MainVisual();

            wnd.Resize += (s, a) => GL.Viewport(0, 0, wnd.Width, wnd.Height);
            wnd.ConnectEvents(visual.Camera);
            wnd.VSync = VSyncMode.Off;

            //var x = -1f;
            //GL.ClearColor(.5f, .2f, 0, 1);
            wnd.Visible = true;
            //main loop
            while (wnd.Exists)
            {
                //if (x < 1) x += .01f; else x = -1;
                //GL.Clear(ClearBufferMask.ColorBufferBit);
                //GL.Begin(PrimitiveType.Triangles);
                //GL.Vertex2(x, 0);
                //GL.Vertex2(x + 1, 0);
                //GL.Vertex2(x, 1);
                //GL.End();
                visual.Render();
                wnd.Context.SwapBuffers();
                wnd.ProcessEvents();                 //this call could destroy window, so do all stuff that needs the window (like gl) before
            }
        }
示例#6
0
        private static void Main()
        {
            var window = new ExampleWindow();

            var camera = window.GameWindow.CreateOrbitingCameraController(0.3f, 70, 0.01f, 30f);

            camera.View.Elevation = 15;
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            var         sampleSeries = new ExponentialSmoothing(0.01);
            QueryObject timeQuery    = new QueryObject();

            window.Render += () =>
            {
                var timerQueryResult = timeQuery.ResultLong * 1e-6;
                sampleSeries.NewSample(timerQueryResult);
                window.GameWindow.Title = $"{sampleSeries.SmoothedValue:F0}ms";
                timeQuery.Activate(QueryTarget.TimeElapsed);
                visual.Draw(camera);
                timeQuery.Deactivate();
            };
            window.Resize += visual.Resize;
            window.Resize += (w, h) => sampleSeries.Clear();
            window.Run();
        }
示例#7
0
        private static void Main()
        {
            var window = new ExampleWindow();

            var camera = window.GameWindow.CreateOrbitingCameraController(1.8f, 70, 0.1f, 50f);

            camera.View.TargetY = -0.3f;
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            var  globalTime       = new GameTime();
            bool doPostProcessing = false;

            window.Render += () =>
            {
                if (doPostProcessing)
                {
                    visual.DrawWithPostProcessing(globalTime.AbsoluteTime, camera);
                }
                else
                {
                    visual.Draw(camera);
                }
            };

            window.Update += (t) => doPostProcessing = !window.Input.IsButtonDown("Space");
            window.Resize += visual.Resize;
            window.Run();
        }
示例#8
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Render += visual.Render;
            window.Run();
        }
示例#9
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var camera = window.GameWindow.CreateOrbitingCameraController(30, 90, 0.1f, 500f);
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Render += () => visual.Render(camera);
            window.Run();
        }
        private static void Main()
        {
            var window = new ExampleWindow();
            var orbit  = window.GameWindow.CreateOrbitingCameraController(0.5f, 70, 0.01f, 50f);
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Render += () => visual.Render(orbit, orbit.CalcPosition());
            window.Run();
        }
        private static void Main()
        {
            var window = new ExampleWindow(debug: true);
            var camera = window.GameWindow.CreateOrbitingCameraController(3f, 70f, 0.1f, 500f);
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Render += () => visual.Render(camera, camera.View.CalcPosition());
            window.Run();
        }
        private static void Main()
        {
            var window = new ExampleWindow();
            //window.SetContentSearchDirectory(Path.GetDirectoryName(PathTools.GetSourceFilePath())); //would be faster if you only specify a subdirectory
            var orbit  = window.GameWindow.CreateOrbitingCameraController(15, 30, 0.1f, 50f);
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Render += () => visual.Render(orbit, orbit.CalcPosition());
            window.Run();
        }
示例#13
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);
            var time   = new GameTime();

            window.Render += () => visual.Render(time.AbsoluteTime);
            window.Resize += visual.Resize;
            window.Run();
        }
示例#14
0
 private MyApplication()
 {
     gameWindow = new GameWindow(800, 800);
     //gameWindow.WindowState = WindowState.Fullscreen;
     gameWindow.KeyDown += GameWindow_KeyDown;
     gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
     gameWindow.RenderFrame += (s, arg) => visual.Render();
     gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers();
     visual = new MainVisual();
 }
示例#15
0
        private static void Main()
        {
            var window = new ExampleWindow();

            window.SetContentSearchDirectory(Path.GetDirectoryName(PathTools.GetSourceFilePath())); //would be faster if you only specify a subdirectory
            var visual = new MainVisual(window.ContentLoader);

            window.Render += visual.Render;
            window.Run();
        }
示例#16
0
        private static void Main()
        {
            var app    = new ExampleApplication();
            var visual = new MainVisual();

            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            LoadResources(app.ResourceManager);
            app.Render += visual.Render;
            app.Run();
        }
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.GameWindow.AddWindowAspectHandling(visual.Camera.Projection);
            window.GameWindow.AddMayaCameraEvents(visual.Camera.Projection, visual.Camera.View);
            window.Render += visual.Render;
            window.Run();
        }
示例#18
0
 private MyApplication()
 {
     var mode = new GraphicsMode(new ColorFormat(32), 24, 8, 0);
     gameWindow = new GameWindow(1024, 1024, mode, "Example", GameWindowFlags.Default, DisplayDevice.Default, 4, 3, GraphicsContextFlags.ForwardCompatible);
     gameWindow.WindowState = WindowState.Fullscreen;
     gameWindow.KeyDown += GameWindow_KeyDown;
     gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
     gameWindow.RenderFrame += (s, arg) => visual.Render();
     gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers();
     visual = new MainVisual();
 }
示例#19
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var camera = window.GameWindow.CreateOrbitingCameraController(30, 90, 0.1f, 500f);
            //var camera = window.GameWindow.CreateFirstPersonCameraController(1f, new Vector3(0, 0, 10), 70f, 0.1f, 20f);

            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.Render += () => visual.Render(camera);
            window.Run();
        }
        private static void Main()
        {
            var window = new ExampleWindow();

            window.SetContentSearchDirectory(Path.GetDirectoryName(PathTools.GetSourceFilePath()));             //would be faster if you only specify a subdirectory
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);
            var time   = new GameTime();

            window.Render += () => visual.Render(time.AbsoluteTime);
            window.Run();
        }
示例#21
0
        private static void Main()
        {
            var app    = new ExampleApplication();
            var visual = new MainVisual();

            app.GameWindow.ConnectEvents(visual.OrbitCamera);
            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            LoadResources(app.ResourceManager);
            app.Render += visual.Render;
            app.Run();
        }
示例#22
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var camera = window.GameWindow.CreateOrbitingCameraController(1.5f, 90f, 0.1f, 50f);

            camera.View.Azimuth   = 90;
            camera.View.Elevation = 20;
            var visual = new MainVisual(window.RenderContext, window.ContentLoader);

            window.Render += () => visual.Render(camera);
            window.Run();
        }
示例#23
0
        private MyApplication()
        {
            var mode = new GraphicsMode(new ColorFormat(32), 24, 8, 0);

            gameWindow              = new GameWindow(1024, 1024, mode, "Example", GameWindowFlags.Default, DisplayDevice.Default, 4, 3, GraphicsContextFlags.ForwardCompatible);
            gameWindow.WindowState  = WindowState.Fullscreen;
            gameWindow.KeyDown     += GameWindow_KeyDown;
            gameWindow.Resize      += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
            gameWindow.RenderFrame += (s, arg) => visual.Render();
            gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers();
            visual = new MainVisual();
        }
示例#24
0
        private static void Main()
        {
            var app = new ExampleApplication();
            //app.IsRecording = true;
            var visual = new MainVisual();

            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            LoadResources(app.ResourceManager);

            app.Render += visual.Render;
            app.Update += visual.Update;
            app.Run();
        }
示例#25
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var model  = new Model();
            var camera = window.GameWindow.CreateOrbitingCameraController(30, 90, 0.1f, 500f);
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            var time = new GameTime();

            window.Render += () => visual.Render(model.Bodies, time.AbsoluteTime, camera);
            window.Update += model.Update;
            window.Run();
        }
示例#26
0
        private static void Main()
        {
            var app    = new ExampleApplication();
            var model  = new Model();
            var visual = new MainVisual();

            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            LoadResources(app.ResourceManager);
            app.Render += () => visual.Render(model.Bodies);
            app.Update += model.Update;
            app.GameWindow.ConnectEvents(visual.Camera);
            app.Run();
        }
示例#27
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var camera = window.GameWindow.CreateOrbitingCameraController(2, 70, 0.1f, 20f);

            camera.View.Elevation = 15;
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);
            var time   = new GameTime();

            window.Render += () => visual.Render(time.DeltaTime, camera);
            window.Resize += visual.Resize;
            window.Run();
        }
示例#28
0
 private MyApplication()
 {
     gameWindow = new GameWindow(800, 800);
     //gameWindow.LoadLayout();
     //gameWindow.WindowState = WindowState.Fullscreen;
     gameWindow.MouseMove += GameWindow_MouseMove;
     gameWindow.MouseWheel += GameWindow_MouseWheel;
     gameWindow.KeyDown += GameWindow_KeyDown;
     gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
     gameWindow.RenderFrame += (s, arg) => visual.Render();
     gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers();
     gameWindow.UpdateFrame += (s, arg) => visual.Update((float)timeSource.Elapsed.TotalSeconds);
     visual = new MainVisual();
     timeSource.Start();
 }
        private static void Main()
        {
            var window     = new ExampleWindow();
            var controller = new Controller();

            var camera = window.GameWindow.CreateOrbitingCameraController(2, 70, 0.1f, 20f);

            camera.Elevation = 15;
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            var time = new GameTime();

            window.Render += () => visual.Render(camera);
            window.Update += (t) => visual.Update(time.AbsoluteTime);
            window.Run();
        }
示例#30
0
        private static void Main()
        {
            var app = new ExampleApplication();

            LoadResources(app.ResourceManager);
            var controller = new Controller();
            var visual     = new MainVisual();

            app.ResourceManager.ShaderChanged += visual.ShaderChanged;
            var timeSource = new Stopwatch();

            app.GameWindow.ConnectEvents(visual.OrbitCamera);
            app.Render += visual.Render;
            app.Update += (t) => visual.Update((float)timeSource.Elapsed.TotalSeconds);
            timeSource.Start();
            app.Run();
        }
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.GameWindow.MouseMove += (s, e) =>
            {
                if (ButtonState.Pressed == e.Mouse.LeftButton)
                {
                    visual.CameraAzimuth   += 300 * e.XDelta / (float)window.GameWindow.Width;
                    visual.CameraElevation += 300 * e.YDelta / (float)window.GameWindow.Height;
                }
            };
            window.GameWindow.MouseWheel += (s, e) => visual.CameraDistance *= (float)Math.Pow(1.05, e.DeltaPrecise);
            window.Update += visual.Update;
            window.Render += visual.Render;
            window.Run();
        }
示例#32
0
        private static void Main()
        {
            var app = new ExampleApplication();

            Resources.LoadResources(app.ResourceManager);
            var visual = new MainVisual();
            Action <MouseEventArgs> updateMouseState = (a) =>
            {
                var mouseState = new MouseState();
                mouseState.position  = app.CalcNormalized(a.X, a.Y);
                mouseState.drawState = GetDrawState(a.Mouse);
                visual.MouseState    = mouseState;
            };

            app.GameWindow.MouseMove += (s, a) => updateMouseState(a);
            app.GameWindow.MouseDown += (s, a) => updateMouseState(a);
            app.Render += visual.Render;
            app.Run();
        }
示例#33
0
        private static void Main()
        {
            var window = new ExampleWindow();

            window.SetContentSearchDirectory(Path.GetDirectoryName(PathTools.GetSourceFilePath())); //would be faster if you only specify a subdirectory
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.GameWindow.MouseMove += (s, e) =>
            {
                if (ButtonState.Pressed == e.Mouse.LeftButton)
                {
                    visual.CameraAzimuth   += 10 * e.XDelta / (float)window.GameWindow.Width;
                    visual.CameraElevation += 10 * e.YDelta / (float)window.GameWindow.Height;
                }
            };
            window.GameWindow.MouseWheel += (s, e) => visual.CameraDistance *= (float)Math.Pow(1.05, e.DeltaPrecise);
            window.Update += visual.Update;
            window.Render += visual.Render;
            window.Run();
        }