Ejemplo n.º 1
0
 public Game(
     GameWindowSettings gameWindowSettings,
     NativeWindowSettings nativeWindowSettings)
     : base(gameWindowSettings, nativeWindowSettings)
 {
     Title = "Nile -> Ai";
 }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Initializing");
            GameWindowSettings gws = new GameWindowSettings();

            gws.IsMultiThreaded = true;
            gws.RenderFrequency = 0.0;
            gws.UpdateFrequency = 60;

            if (args.Length > 0)
            {
                autoexit = true;
            }

            NativeWindowSettings nws = new NativeWindowSettings();

            nws.Size         = WindowSize;
            nws.Title        = "Display";
            nws.WindowBorder = WindowBorder.Fixed;

            Console.WriteLine("Creating game object");
            using (Game g = new Game(gws, nws)) {
                g.Run();
            }
        }
Ejemplo n.º 3
0
        public Window(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings) : base(gameWindowSettings, nativeWindowSettings)
        {
            float x = 0.0f;
            float y = 0.0f;

            //radius lingkaran
            float radius = 0.5f;

            ////radius elips
            //float radius_x = 0.1f;
            //float radius_y = 0.2f;

            for (int i = 0; i < 360; i++)
            {
                //rumus derajat ke radian = derajat * 3.1416f / 180;
                float degInRad = i * 3.1416f / 180;

                //x
                //lingkaran
                _vertices_clock[i * 3] = x + (float)Math.Cos(degInRad) * radius;
                //elips
                //_vertices[i * 3] = x + (float)Math.Cos(degInRad) * radius_x;

                //y
                _vertices_clock[i * 3 + 1] = y + (float)Math.Sin(degInRad) * radius;
                //elips
                //_vertices[i * 3 + 1] = y + (float)Math.Sin(degInRad) * radius_y;

                //z
                _vertices_clock[i * 3 + 2] = 0;
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            GameWindowSettings gameWinSettings = new GameWindowSettings();
            var nativeWindowSettings           = new NativeWindowSettings()
            {
                Size       = new Vector2i(800, 600),
                Title      = "Habi",
                APIVersion = new System.Version(4, 5),
                API        = ContextAPI.OpenGL,
                Flags      = ContextFlags.ForwardCompatible,
                Profile    = ContextProfile.Core,
            };

            int width, height, xpos, ypos;

            unsafe
            {
                var monitor = GLFW.GetPrimaryMonitor();
                var vidmode = GLFW.GetVideoMode(monitor);
                width  = vidmode->Width - 200;
                height = vidmode->Height - 100;
                xpos   = (vidmode->Width - width) / 2;
                ypos   = (vidmode->Height - height) / 2;
            }

            nativeWindowSettings.Size     = new Vector2i(width, height);
            nativeWindowSettings.Location = new Vector2i(xpos, ypos);

            using (var game = new Draw2DGame(gameWinSettings, nativeWindowSettings))
            {
                game.Run();
            }
        }
Ejemplo n.º 5
0
        public void CreateMainWindow(string title, bool display = true)
        {
            if (TargetWindow != null)
            {
                throw new InvalidOperationException("There is already a window created for the current Render thread.");
            }

            NativeWindowSettings settings = new NativeWindowSettings()
            {
                IsFullscreen = Fullscreen, StartVisible = display, StartFocused = display, Title = title, Size = new OpenToolkit.Mathematics.Vector2i(WindowSize.Width, WindowSize.Height)
            };

            if (Fullscreen)
            {
                settings.WindowState  = OpenToolkit.Windowing.Common.WindowState.Fullscreen;
                settings.WindowBorder = OpenToolkit.Windowing.Common.WindowBorder.Fixed;
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                settings.API        = OpenToolkit.Windowing.Common.ContextAPI.OpenGL;
                settings.APIVersion = new Version(3, 3, 0, 0);
                settings.Flags     |= OpenToolkit.Windowing.Common.ContextFlags.ForwardCompatible;
                settings.Profile    = OpenToolkit.Windowing.Common.ContextProfile.Core;
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                settings.API        = OpenToolkit.Windowing.Common.ContextAPI.OpenGL;
                settings.APIVersion = new Version(3, 3, 0, 0);
                settings.Profile    = OpenToolkit.Windowing.Common.ContextProfile.Core;
            }

            TargetWindow = new RenderWindow(settings);
        }
Ejemplo n.º 6
0
 public Window(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings) : base(gameWindowSettings, nativeWindowSettings)
 {
     Console.WriteLine("\"Shaun the Sheep\" made by:");
     Console.WriteLine("Leonando L - C14190010");
     Console.WriteLine("Nicholas S - C14190034");
     Console.WriteLine("Jeremy H - C14190215");
     Console.WriteLine("\nControls:");
     Console.WriteLine("WASD - MOVE CAMERA");
     Console.WriteLine("LSHIFT - MOVE UP CAMERA");
     Console.WriteLine("LCTRL - MOVE DOWN CAMERA");
     Console.WriteLine("MOUSEWHEEL - ZOOM IN/OUT CAMERA");
     Console.WriteLine("R - RESET CAMERA");
     Console.WriteLine("");
     Console.WriteLine("LEFT MOUSE - HORIZONTAL SPIN");
     Console.WriteLine("RIGHT MOUSE - VERTICAL SPIN");
     Console.WriteLine("MIDDLE MOUSE - CIRCLE SPIN");
     Console.WriteLine("");
     Console.WriteLine("ARROW KEYS - MOVE LIGHT");
     Console.WriteLine("RSHIFT - MOVE UP LIGHT");
     Console.WriteLine("RCTRL - MOVE DOWN LIGHT");
     Console.WriteLine("L - RESET LIGHT");
     Console.WriteLine("");
     Console.WriteLine("F1 - SHOW HELP");
     Console.WriteLine("F7 - TOGGLE WIREFRAMES");
     Console.WriteLine("F8 - TOGGLE SOLIDS");
     Console.WriteLine("F9 - TOGGLE LIGHTBALL");
     Console.WriteLine("F10 - TOGGLE SHADOW");
     Console.WriteLine("F11 - TOGGLE FULLSCREEN");
     Console.WriteLine("F12 - TOGGLE ANIMATIONS");
     Console.WriteLine("\nActions:");
 }
Ejemplo n.º 7
0
        public LightingGame(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings) : base(gameWindowSettings, nativeWindowSettings)
        {
            VSync = VSyncMode.On;

            _material = new Material(new Vector3(1.0f, 0.5f, 0.31f), new Vector3(1.0f, 0.5f, 0.31f), new Vector3(0.5f, 0.5f, 0.5f), 32.0f);
            _light    = new Light(new Vector3(1.0f, 3.0f, 3.0f), new Vector3(0.2f, 0.2f, 0.2f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(1.0f, 1.0f, 1.0f));
        }
Ejemplo n.º 8
0
        public void OpenEditor()
        {
            var nativeWindowSettings = new NativeWindowSettings()
            {
                Size             = new OpenTK.Mathematics.Vector2i(800, 600),
                Title            = "ZigZag Editor",
                AutoLoadBindings = true
            };

            m_nativeWindow = new NativeWindow(nativeWindowSettings);
            m_nativeWindow.Context.MakeCurrent();
            GLFW.SwapInterval(1);

            m_imguiContext = ImGui.CreateContext();
            ImGui.SetCurrentContext(m_imguiContext);
            ImGui.GetIO().ConfigFlags |= ImGuiConfigFlags.DockingEnable;

            unsafe
            {
                fixed(byte *ptr = Resources.Fonts.WorkSans_Regular)
                {
                    ImGui.GetIO().Fonts.AddFontFromMemoryTTF((IntPtr)ptr, Resources.Fonts.WorkSans_Regular.Length, 28);
                }
            }

            ImGuiPlatformIntegration.SetupKeys();
            ImGuiRendererIntegration.Initialize();
            ImGuiRendererIntegration.CreateFontsTexture();

            m_mainMenu                 = new MainMenu();
            m_hierarchyWindow          = new HierarchyWindow("Hierarchy");
            m_historyWindow            = new HistoryWindow("History");
            m_mainMenu.HierarchyWindow = m_hierarchyWindow;
            m_mainMenu.HistoryWindow   = m_historyWindow;
        }
Ejemplo n.º 9
0
        public void CreateWindow(System.Numerics.Vector2 size, bool hidden = false)
        {
            var settings = new GameWindowSettings()
            {
                IsMultiThreaded = false
            };

            var nsettings = new NativeWindowSettings()
            {
                API = ContextAPI.OpenGL,
                AutoLoadBindings = true,
                Size             = new Vector2i((int)size.X, (int)size.Y),
                Title            = "OpenH2",
                Flags            = ContextFlags.Debug,
                APIVersion       = new Version(4, 6),
                NumberOfSamples  = 8
            };

            window = new GameWindow(settings, nsettings);

            window.Resize          += this.Window_Resize;
            this.AspectRatio        = size.X / size.Y;
            this.AspectRatioChanged = true;

            window.IsVisible = !hidden;

            window.Closed += this.Window_Closed;

            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.AlphaTest);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);
        }
Ejemplo n.º 10
0
        public void MakeWindow()
        {
            GameWindowSettings   settings       = new GameWindowSettings();
            NativeWindowSettings nativeSettings = new NativeWindowSettings();

            using (TriangleWindow window = new TriangleWindow(settings, nativeSettings))
            {
                window.Run();
            }

            using (SquareWindow window = new SquareWindow(settings, nativeSettings))
            {
                window.Run();
            }

            using (TextureWindow window = new TextureWindow(settings, nativeSettings))
            {
                window.Run();
            }

            using (CubeWindow window = new CubeWindow(settings, nativeSettings))
            {
                window.Run();
            }
        }
Ejemplo n.º 11
0
        private void ActivateThisWindowContext(string title, uint width, uint height, bool fullscreen)
        {
            // We use OpenGL 2.0 (ie. fixed-function pipeline!)
            var settings = new GameWindowSettings();

            settings.IsMultiThreaded = false;
            var nativeSettings = new NativeWindowSettings();

            nativeSettings.Profile      = ContextProfile.Any;
            nativeSettings.WindowState  = WindowState.Normal;
            nativeSettings.API          = ContextAPI.OpenGL;
            nativeSettings.APIVersion   = new Version(2, 0);
            nativeSettings.IsFullscreen = fullscreen;

            window = new GameWindow(settings, nativeSettings)
            {
                Title = title,
                Size  = new OpenTK.Mathematics.Vector2i((int)width, (int)height)
            };

            GL.ClearDepth(1);
            GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);

            isRunning = true;
            window.Context.MakeCurrent();
            window.IsVisible = true;

            GL.Viewport(0, 0, window.Size.X, window.Size.Y);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(0.0, 1.0, 0.0, 1.0, 0.0, 4.0);
        }
Ejemplo n.º 12
0
        public Window2D(Scene2D scene, GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings)
            : base(gameWindowSettings, nativeWindowSettings)
        {
            Scene = scene;

            eventContext = new EventContext();
        }
Ejemplo n.º 13
0
 //feets.bac
 public Window(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings) : base(gameWindowSettings, nativeWindowSettings)
 {
     GL.Enable(EnableCap.Multisample);
     GL.Disable(EnableCap.DepthTest);
     GL.Enable(EnableCap.Blend);
     GL.Enable(EnableCap.LineSmooth);
 }
Ejemplo n.º 14
0
 public Game(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings)
     : base(gameWindowSettings, nativeWindowSettings)
 {
     frameCounter = 0.0f;
     sceneManager = new SceneManager(this);
     KeyDown     += sceneManager.ProcessKeyInput;
     MouseDown   += sceneManager.ProcessMouseButtonDown;
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MyOTKEWindow"/> class.
        /// </summary>
        /// <param name="gameWindowSettings">The GameWindow related settings.</param>
        /// <param name="nativeWindowSettings">The NativeWindow related settings.</param>
        /// <param name="lockCursor">A value indicating whether the cursor is placed back at the center of the view during each update.</param>
        /// <param name="clearColor">The color to clear the view with on each render call.</param>
        public MyOTKEWindow(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings, bool lockCursor, Color clearColor)
            : base(gameWindowSettings, nativeWindowSettings)
        {
            GlDebug.RegisterDebugCallback();

            this.LockCursor = lockCursor;
            this.clearColor = clearColor;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Use this method to create an OpenGL context.
        /// Never use this method in your application, ONLY in unit testing.
        /// This will enable you to unit test classes which use OpenGL-dependent
        /// function calls, including `Text', `Image', and `ImageStride' classes.
        /// </summary>
        public static void CreateOpenGLContext()
        {
            var settings       = new GameWindowSettings();
            var nativeSettings = new NativeWindowSettings();

            Window._contextWin = new GameWindow(settings, nativeSettings);
            Window._contextWin.Context.MakeCurrent();
        }
Ejemplo n.º 17
0
        static void Main()
        {
            var gameSettings         = new GameWindowSettings();
            var nativeWindowSettings = new NativeWindowSettings();

            var program = new Program(gameSettings, nativeWindowSettings);

            program.Run();
        }
Ejemplo n.º 18
0
 public PolyWindow(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings)
     : base(gameWindowSettings, nativeWindowSettings)
 {
     Title       = "";
     updateFreq  = Convert.ToUInt64(UpdateFrequency);
     renderFreq  = Convert.ToUInt64(RenderFrequency);
     updateTimes = new double[updateFreq];
     renderTimes = new double[renderFreq];
 }
Ejemplo n.º 19
0
        public static AppWindow New(int width, int height)
        {
            GameWindowSettings   setting        = new GameWindowSettings();
            NativeWindowSettings nativeSettings = new NativeWindowSettings();

            nativeSettings.Size = new OpenTK.Mathematics.Vector2i(width, height);
            nativeSettings.API  = ContextAPI.OpenGL;
            return(new AppWindow(setting, nativeSettings));
        }
Ejemplo n.º 20
0
        public static Lines2D New(int width, int height)
        {
            GameWindowSettings   setting        = new GameWindowSettings();
            NativeWindowSettings nativeSettings = new NativeWindowSettings();

            nativeSettings.Size = new Vector2i(width, height);
            nativeSettings.API  = ContextAPI.OpenGL;
            return(new Lines2D(setting, nativeSettings));
        }
Ejemplo n.º 21
0
        public static Scene New(int width, int height, string title)
        {
            GameWindowSettings   setting        = new GameWindowSettings();
            NativeWindowSettings nativeSettings = new NativeWindowSettings();

            nativeSettings.Size  = new OpenTK.Mathematics.Vector2i(width, height);
            nativeSettings.Title = title;
            return(new Scene(setting, nativeSettings));
        }
Ejemplo n.º 22
0
        /// <inheritdoc />
        public Game(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings)
            : base(gameWindowSettings, nativeWindowSettings)
        {
            _environment = System.Environment.Version.ToString();
            Input        = new Input(this);
            Global.Input = Input;

            DebugDrawer        = new DebugDrawer();
            Global.DebugDrawer = DebugDrawer;
        }
        static void Main(string[] args)
        {
            var windowSettings = new NativeWindowSettings();

            windowSettings.Size = new OpenToolkit.Mathematics.Vector2i(1264, 1008);

            new MainWindow(GameWindowSettings.Default,
                           windowSettings)
            .Run();
        }
Ejemplo n.º 24
0
        public static GameWindow CreateDefaultWindow(int width, int height, string title = "Game Window")
        {
            var nativeSettings = new NativeWindowSettings {
                Size  = new OpenTK.Mathematics.Vector2i(width, height),
                Title = title
            };
            var defaultSettings = GameWindowSettings.Default;

            return(new GameWindow(defaultSettings, nativeSettings));
        }
Ejemplo n.º 25
0
        public MainWindow(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings)
            : base(gameWindowSettings, nativeWindowSettings)
        {
            Camera = new FpsCamera(Size.X, Size.Y);

            Camera.CameraPosition = new OpenToolkit.Mathematics.Vector3(0, -80, 40);
            Camera.CameraYaw      = -90;
            Camera.CameraPitch    = 90;
            Camera.RecalculateCamera(0, 0);
        }
Ejemplo n.º 26
0
        public static void Init(GameWindowSettings gws, NativeWindowSettings nws, GLRenderer renderer = null, Action initCallback = null)
        {
            _window = new GameWindow(gws, nws);

            //log basic info
            Logger.Log("Base Directory: " + AppContext.BaseDirectory, true);
            Logger.Log("Renderer: " + GL.GetString(StringName.Renderer), true);
            Logger.Log("Vendor: " + GL.GetString(StringName.Vendor), true);
            Logger.Log("Version: " + GL.GetString(StringName.Version), true);
            Logger.Log("Shading Language version: " + GL.GetString(StringName.ShadingLanguageVersion), true);

            //subscribe to window events
            MainWindow.UpdateFrame += UpdateFrame;
            MainWindow.RenderFrame += RenderFrame;

            //intialize engine
            Logger.Log("Initializing LeaderEngine...", true);
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            //init debug callbacks
            GLFW.SetErrorCallback(LogGLFWError);

            DebugProc debugProcCallback       = DebugCallback;
            GCHandle  debugProcCallbackHandle = GCHandle.Alloc(debugProcCallback);

            GL.DebugMessageCallback(debugProcCallback, IntPtr.Zero);
            GL.Enable(EnableCap.DebugOutput);
            GL.Enable(EnableCap.DebugOutputSynchronous);

            //init modules
            AssetManager.Init();
            DefaultShaders.Init();
            SpriteRenderer.Init();
            SkyboxRenderer.Init();

            _renderer = renderer ?? new ForwardRenderer();
            Renderer.Init();

            AudioManager.Init();

            Input.Init(MainWindow.KeyboardState, MainWindow.MouseState);

            //init main application
            initCallback?.Invoke();

            stopwatch.Stop();
            //print init complete msg
            Logger.Log($"LeaderEngine initialized. ({stopwatch.ElapsedMilliseconds}ms)", true);

            //open window
            MainWindow.Run();
        }
Ejemplo n.º 27
0
        private static void Main(string[] args)
        {
            var windowSettings = new NativeWindowSettings
            {
                Size  = new Vector2i(800, 600),
                Title = "Hello world!"
            };

            using var window = new Window(GameWindowSettings.Default, windowSettings);
            window.Run();
        }
Ejemplo n.º 28
0
        static void Main(string[] args)
        {
            var nativeWinSettings = new NativeWindowSettings
            {
                Size  = new Vector2i(800, 600),
                Title = "My OpenTK Test",
                Flags = ContextFlags.ForwardCompatible
            };

            using var window = new Window(GameWindowSettings.Default, nativeWinSettings);
            window.Run();
        }
Ejemplo n.º 29
0
        public RenderWindow(GameWindowSettings gameWindowSettings,
                            NativeWindowSettings nativeWindowSettings)
            : base(gameWindowSettings, nativeWindowSettings)
        {
            Load        += MainWindowLoad;
            Resize      += MainWindowResize;
            RenderFrame += MainWindowRenderFrame;
            UpdateFrame += MainWindowUpdateFrame;

            RenderCommandUpdatesChannel = Channel.CreateUnbounded <IRenderCommand>();
            EventChannel = Channel.CreateUnbounded <IEvent>();
        }
Ejemplo n.º 30
0
        public MainWindow(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings, Action initializeCallback) : base(gameWindowSettings, nativeWindowSettings)
        {
            if (instance != null)
            {
                Debug.WriteLine("Another instance is running!");
                return;
            }

            instance = this;

            this.initializeCallback = initializeCallback;
        }