예제 #1
0
        public PencilGamingWindows(int width, int height, string title, bool isFullscreen, bool shouldVsync)
        {
            onWindowOpened = new Trigger<PencilGamingWindows>();
            OnWindowOpened = onWindowOpened;

            onWindowClosed = new Trigger<PencilGamingWindows>();
            OnWindowClosed = onWindowClosed;

            onWindowResized = new Trigger<PencilGamingWindows>();
            OnWindowResized = onWindowResized;

            onKeyboard = new Trigger<PencilKeyInfo>();
            OnKeyboard = onKeyboard;

            onExit = new Trigger<PencilGamingWindows>();
            OnExit = onExit;

            window = GlfwWindowPtr.Null;
            this.width = width;
            this.height = height;
            this.title = title;
            this.isFullscreen = isFullscreen;
            this.shouldVsync = shouldVsync;
            this.firstTime = true;
            if (!Glfw.Init())
            {
                Console.Error.WriteLine("ERROR: Could not initialize GLFW, shutting down.");
                Environment.Exit(1);
            }
        }
예제 #2
0
		public static void create(int w, int h) {
			Width = w;
			Height = h;
			AspectRatio = Width / (float) Height;

			Glfw.WindowHint(WindowHint.Samples, 4);
			Glfw.WindowHint(WindowHint.ContextVersionMajor, 3);
			Glfw.WindowHint(WindowHint.ContextVersionMinor, 3);
			Glfw.WindowHint(WindowHint.OpenGLForwardCompat, GL_TRUE);
			Glfw.WindowHint(WindowHint.OpenGLProfile, OpenGLProfile.Core.GetHashCode());
			GlfwVidMode[] modes = Glfw.GetVideoModes(Glfw.GetPrimaryMonitor());

			Console.WriteLine("Displays");
			foreach (GlfwVidMode mode in modes) {
				Console.WriteLine(mode.Width + "x" + mode.Height + "\tr" + mode.RedBits + " g" + mode.GreenBits + " b" + mode.BlueBits + "\t " + mode.RefreshRate + "Hz");
			}
			GlfwVidMode defMode = Glfw.GetVideoMode(Glfw.GetPrimaryMonitor());
			Console.WriteLine("Default Display\n" + defMode.Width + "x" + defMode.Height + "\tr" + defMode.RedBits + " g" + defMode.GreenBits + " b" + defMode.BlueBits + "\t " + defMode.RefreshRate + "Hz");

			//Width = defMode.Width;
			//Height = defMode.Height;
			//window = Glfw.CreateWindow(Width, Height, title, Glfw.GetPrimaryMonitor(), GlfwWindowPtr.Null);

			window = Glfw.CreateWindow(Width, Height, title, GlfwMonitorPtr.Null, GlfwWindowPtr.Null);
			if (window.Equals(GlfwWindowPtr.Null)) {
				Glfw.Terminate();
				Console.WriteLine("Failed to create Window");
				Console.WriteLine("Press Any Key to continue ...");
				Console.ReadKey();
				Environment.Exit(1);
			}

			Glfw.MakeContextCurrent(window);

		}
예제 #3
0
		public static KeyboardState GetState(GlfwWindowPtr window) {
			KeyboardState result = new KeyboardState();

			for (int i = 0; i < allKeys.Length; ++i) {
				Key k = allKeys[i];
				result.keys[k] = Glfw.GetKey(window, k);
			}

			return result;
		}
예제 #4
0
파일: World.cs 프로젝트: enguard/Ecalia
        public void Initialize()
        {
            try
            {
                // Throws and Exception if GLFW cannot be initialized
                if (!Glfw.Init())
                    throw new GlfwInitException();

                // Creates the Window
                window = Glfw.CreateWindow(Width, Height, Caption, GlfwMonitorPtr.Null, GlfwWindowPtr.Null);

                // Window Hints
                Glfw.WindowHint(WindowHint.ContextVersionMajor, 3);
                Glfw.WindowHint(WindowHint.ContextVersionMinor, 0);
                Glfw.WindowHint(WindowHint.OpenGLProfile, (int)OpenGLProfile.Core);
                Glfw.WindowHint((WindowHint)WindowAttrib.Resizeable, Convert.ToInt32(false));
                Glfw.WindowHint(WindowHint.OpenGLForwardCompat, Convert.ToInt32(true)); // This is for the client to work in MacOS

                // Without this the window will not pop up
                Glfw.MakeContextCurrent(window);

                // This is shown as a false in C++ but false = 0 so that's why it's a 0
                Glfw.SwapInterval(0);

                // Set Key callback for the window
                Glfw.SetKeyCallback(window, OnKeyCallback);

                // Anything else you want to initialize should go here
                // i.e ShaderProgram if you want to use Modern openGL

                // END

                while (!Glfw.WindowShouldClose(window))
                {
                    Glfw.PollEvents();

                    // Add Anything you need to Render HERE

                    OnWindowRender();

                    // END

                    Glfw.SwapBuffers(window);
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {
                Glfw.Terminate();
            }
        }
예제 #5
0
		public static MouseState GetMouseState(GlfwWindowPtr window) {
			MouseState result = new MouseState();

			result.LeftButton = Glfw.GetMouseButton(window, MouseButton.LeftButton);
			result.MiddleButton = Glfw.GetMouseButton(window, MouseButton.MiddleButton);
			result.RightButton = Glfw.GetMouseButton(window, MouseButton.RightButton);
			int x, y;
			Glfw.GetCursorPos(window, out x, out y);
			result.X = x;
			result.Y = y;

			return result;
		}
예제 #6
0
        // the pragram starts here
        private static void AppMain()
        {
            // initialize GLFW
            if (!Glfw.Init())
                throw new Exception("glfwInit failed");

            // open a window with GLFW
            Glfw.WindowHint(WindowHint.OpenGLProfile, (int)OpenGLProfile.Core);
            Glfw.WindowHint(WindowHint.ContextVersionMajor, 3);
            Glfw.WindowHint(WindowHint.ContextVersionMinor, 2);
            _window = Glfw.CreateWindow(ScreenSize.X, ScreenSize.Y, "", GlfwMonitorPtr.Null, GlfwWindowPtr.Null);
            if (_window.Equals(GlfwWindowPtr.Null))
                throw new Exception("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?");
            Glfw.MakeContextCurrent(_window);

            // TODO: GLEW in C#

            // print out some info about the graphics drivers
            Console.WriteLine("OpenGL version: {0}", GL.GetString(StringName.Version));
            Console.WriteLine("GLSL version: {0}", GL.GetString(StringName.ShadingLanguageVersion));
            Console.WriteLine("Vendor: {0}", GL.GetString(StringName.Vendor));
            Console.WriteLine("Renderer: {0}", GL.GetString(StringName.Renderer));

            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);

            // load vertex and fragment shaders into opengl
            LoadShaders();

            // load the texture
            LoadTexture();

            // create buffer and fill it with the points of the triangle
            LoadCube();

            double lastTime = Glfw.GetTime();
            // run while window is open
            while (!Glfw.WindowShouldClose(_window)) {
                // update the scene based on the time elapsed since last update
                double thisTime = Glfw.GetTime();
                Update(thisTime - lastTime);
                lastTime = thisTime;

                // draw one frame
                Render();
            }

            // clean up and exit
            Glfw.Terminate();
        }
예제 #7
0
 internal static extern void glfwGetFramebufferSize(GlfwWindowPtr window, out int width, out int height);
예제 #8
0
 public static void GetWindowSize(GlfwWindowPtr window, out int width, out int height)
 {
     GlfwDelegates.glfwGetWindowSize(window, out width, out height);
 }
예제 #9
0
 internal static extern void glfwMakeContextCurrent(GlfwWindowPtr window);
예제 #10
0
 internal static extern void glfwHideWindow(GlfwWindowPtr window);
예제 #11
0
        // the pragram starts here
        private static void AppMain()
        {
            // initialize GLFW
            if (!Glfw.Init())
                throw new Exception("glfwInit failed");

            // open a window with GLFW
            Glfw.WindowHint(WindowHint.OpenGLProfile, (int)OpenGLProfile.Core);
            Glfw.WindowHint(WindowHint.ContextVersionMajor, 3);
            Glfw.WindowHint(WindowHint.ContextVersionMinor, 2);
            _window = Glfw.CreateWindow(ScreenSize.X, ScreenSize.Y, "", GlfwMonitorPtr.Null, GlfwWindowPtr.Null);
            if (_window.Equals(GlfwWindowPtr.Null))
                throw new Exception("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?");
            Glfw.MakeContextCurrent(_window);

            // GLFW settings
            Glfw.SetInputMode(_window, InputMode.CursorMode, CursorMode.CursorHidden | CursorMode.CursorCaptured);
            Glfw.SetCursorPos(_window, 0, 0);
            Glfw.SetScrollCallback(_window, new GlfwScrollFun((win, x, y) => {
                //increase or decrease field of view based on mouse wheel
                float zoomSensitivity = -0.2f;
                float fieldOfView = _gCamera.FieldOfView + zoomSensitivity * (float)y;
                if (fieldOfView < 5.0f) fieldOfView = 5.0f;
                if (fieldOfView > 130.0f) fieldOfView = 130.0f;
                _gCamera.FieldOfView = fieldOfView;
            }));

            // TODO: GLEW in C#

            // print out some info about the graphics drivers
            Console.WriteLine("OpenGL version: {0}", GL.GetString(StringName.Version));
            Console.WriteLine("GLSL version: {0}", GL.GetString(StringName.ShadingLanguageVersion));
            Console.WriteLine("Vendor: {0}", GL.GetString(StringName.Vendor));
            Console.WriteLine("Renderer: {0}", GL.GetString(StringName.Renderer));

            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);

            // initialise the gWoodenCrate asset
            LoadWoodenCrateAsset();

            // create all the instances in the 3D scene based on the gWoodenCrate asset
            CreateInstances();

            _gCamera.Position = new Vector3(-4, 0, 17);
            _gCamera.ViewportAspectRatio = (float)ScreenSize.X / (float)ScreenSize.Y;
            _gCamera.SetNearAndFarPlanes(0.5f, 100.0f);

            // setup light
            _gLight = new Light() {
                Position = _gCamera.Position,
                Intensities = new Vector3(1, 1, 1), // white
                Attenuation = 0.2f,
                AmbientCoefficient = 0.005f
            };

            float lastTime = (float)Glfw.GetTime();
            // run while window is open
            while (!Glfw.WindowShouldClose(_window)) {
                // update the scene based on the time elapsed since last update
                float thisTime = (float)Glfw.GetTime();
                Update(thisTime - lastTime);
                lastTime = thisTime;

                // draw one frame
                Render();
                //exit program if escape key is pressed
                if (Glfw.GetKey(_window, Key.Escape))
                    Glfw.SetWindowShouldClose(_window, true);
            }

            // clean up and exit
            Glfw.Terminate();
        }
예제 #12
0
 internal static extern void glfwSetWindowShouldClose(GlfwWindowPtr window, int value);
예제 #13
0
 internal static extern void glfwSetWindowSize(GlfwWindowPtr window, int width, int height);
예제 #14
0
 public static GlfwWindowRefreshFun SetWindowRefreshCallback(GlfwWindowPtr window, GlfwWindowRefreshFun cbfun)
 {
     windowRefreshFun = cbfun;
     return(GlfwDelegates.glfwSetWindowRefreshCallback(window, cbfun));
 }
예제 #15
0
 public static GlfwWindowIconifyFun SetWindowIconifyCallback(GlfwWindowPtr window, GlfwWindowIconifyFun cbfun)
 {
     windowIconifyFun = cbfun;
     return(GlfwDelegates.glfwSetWindowIconifyCallback(window, cbfun));
 }
예제 #16
0
 public static IntPtr GetWindowUserPointer(GlfwWindowPtr window)
 {
     return(GlfwDelegates.glfwGetWindowUserPointer(window));
 }
예제 #17
0
 public static GlfwFramebufferSizeFun SetFramebufferSizeCallback(GlfwWindowPtr window, GlfwFramebufferSizeFun cbfun)
 {
     framebufferSizeFun = cbfun;
     return(GlfwDelegates.glfwSetFramebufferSizeCallback(window, cbfun));
 }
예제 #18
0
 public static void SetWindowUserPointer(GlfwWindowPtr window, IntPtr pointer)
 {
     GlfwDelegates.glfwSetWindowUserPointer(window, pointer);
 }
예제 #19
0
 public static int GetWindowAttrib(GlfwWindowPtr window, WindowHint param)
 {
     return(GlfwDelegates.glfwGetWindowAttrib(window, (int)param));
 }
예제 #20
0
 public static GlfwMonitorPtr GetWindowMonitor(GlfwWindowPtr window)
 {
     return(GlfwDelegates.glfwGetWindowMonitor(window));
 }
예제 #21
0
 internal static extern IntPtr glfwGetWin32Window(GlfwWindowPtr window);
예제 #22
0
 public static int GetInputMode(GlfwWindowPtr window, InputMode mode)
 {
     return(GlfwDelegates.glfwGetInputMode(window, mode));
 }
예제 #23
0
 internal static extern void glfwDestroyWindow(GlfwWindowPtr window);
예제 #24
0
 public static void SetInputMode(GlfwWindowPtr window, InputMode mode, CursorMode value)
 {
     GlfwDelegates.glfwSetInputMode(window, mode, value);
 }
예제 #25
0
 internal static extern void glfwGetWindowPos(GlfwWindowPtr window, out int xpos, out int ypos);
예제 #26
0
 public static bool GetKey(GlfwWindowPtr window, Key key)
 {
     return(GlfwDelegates.glfwGetKey(window, key) != 0);
 }
예제 #27
0
 internal static extern void glfwRestoreWindow(GlfwWindowPtr window);
예제 #28
0
 public static bool GetMouseButton(GlfwWindowPtr window, MouseButton button)
 {
     return(GlfwDelegates.glfwGetMouseButton(window, button) != 0);
 }
예제 #29
0
 internal static extern int glfwGetWindowAttrib(GlfwWindowPtr window, int param);
예제 #30
0
 public static void GetCursorPos(GlfwWindowPtr window, out double xpos, out double ypos)
 {
     GlfwDelegates.glfwGetCursorPos(window, out xpos, out ypos);
 }
예제 #31
0
 public static void HideWindow(GlfwWindowPtr window)
 {
     GlfwDelegates.glfwHideWindow(window);
 }
예제 #32
0
 public static void SetCursorPos(GlfwWindowPtr window, double xpos, double ypos)
 {
     GlfwDelegates.glfwSetCursorPos(window, xpos, ypos);
 }
예제 #33
0
 internal static extern sbyte* glfwGetClipboardString(GlfwWindowPtr window);
예제 #34
0
 public static GlfwKeyFun SetKeyCallback(GlfwWindowPtr window, GlfwKeyFun cbfun)
 {
     keyFun = cbfun;
     return(GlfwDelegates.glfwSetKeyCallback(window, cbfun));
 }
예제 #35
0
 internal static extern void glfwSwapBuffers(GlfwWindowPtr window);
예제 #36
0
 public static GlfwCharFun SetCharCallback(GlfwWindowPtr window, GlfwCharFun cbfun)
 {
     charFun = cbfun;
     return(GlfwDelegates.glfwSetCharCallback(window, cbfun));
 }
예제 #37
0
 internal static extern GlfwFramebufferSizeFun glfwSetFramebufferSizeCallback(GlfwWindowPtr window, GlfwFramebufferSizeFun cbfun);
예제 #38
0
 public static GlfwMouseButtonFun SetMouseButtonCallback(GlfwWindowPtr window, GlfwMouseButtonFun cbfun)
 {
     mouseButtonFun = cbfun;
     return(GlfwDelegates.glfwSetMouseButtonCallback(window, cbfun));
 }
예제 #39
0
 internal static extern GlfwWindowPtr glfwCreateWindow(int width, int height, [MarshalAs(UnmanagedType.LPStr)] string title, GlfwMonitorPtr monitor, GlfwWindowPtr share);
예제 #40
0
 public static GlfwCursorEnterFun SetCursorEnterCallback(GlfwWindowPtr window, GlfwCursorEnterFun cbfun)
 {
     cursorEnterFun = cbfun;
     return(GlfwDelegates.glfwSetCursorEnterCallback(window, cbfun));
 }
예제 #41
0
 internal static extern int glfwWindowShouldClose(GlfwWindowPtr window);
예제 #42
0
 public static GlfwScrollFun SetScrollCallback(GlfwWindowPtr window, GlfwScrollFun cbfun)
 {
     scrollFun = cbfun;
     return(GlfwDelegates.glfwSetScrollCallback(window, cbfun));
 }
예제 #43
0
 internal static extern void glfwSetWindowTitle(GlfwWindowPtr window, [MarshalAs(UnmanagedType.LPStr)] string title);
예제 #44
0
 public static void SetClipboardString(GlfwWindowPtr window, string @string)
 {
     GlfwDelegates.glfwSetClipboardString(window, @string);
 }
예제 #45
0
 internal static extern void glfwSetWindowPos(GlfwWindowPtr window, int xpos, int ypos);
예제 #46
0
 public static string GetClipboardString(GlfwWindowPtr window)
 {
     return(new string(GlfwDelegates.glfwGetClipboardString(window)));
 }
예제 #47
0
 internal static extern void glfwIconifyWindow(GlfwWindowPtr window);
예제 #48
0
 public static void MakeContextCurrent(GlfwWindowPtr window)
 {
     GlfwDelegates.glfwMakeContextCurrent(window);
 }
예제 #49
0
 internal static extern void glfwShowWindow(GlfwWindowPtr window);
예제 #50
0
 public static void SetWindowSize(GlfwWindowPtr window, int width, int height)
 {
     GlfwDelegates.glfwSetWindowSize(window, width, height);
 }
예제 #51
0
 internal static extern GlfwMonitorPtr glfwGetWindowMonitor(GlfwWindowPtr window);
예제 #52
0
파일: World.cs 프로젝트: enguard/Ecalia
 private void OnKeyCallback(GlfwWindowPtr wnd, Key key, int scanCode, KeyAction action, KeyModifiers mods)
 {
     if (key == Key.LeftAlt | key == Key.RightAlt && key == Key.F4 & action == KeyAction.Press)
         Glfw.Terminate();
 }
예제 #53
0
 internal static extern void glfwSetWindowUserPointer(GlfwWindowPtr window, IntPtr pointer);
예제 #54
0
 public static void RestoreWindow(GlfwWindowPtr window)
 {
     GlfwDelegates.glfwRestoreWindow(window);
 }
예제 #55
0
 public static void SetWindowPos(GlfwWindowPtr window, int xpos, int ypos)
 {
     GlfwDelegates.glfwSetWindowPos(window, xpos, ypos);
 }
예제 #56
0
 public static void ShowWindow(GlfwWindowPtr window)
 {
     GlfwDelegates.glfwShowWindow(window);
 }
예제 #57
0
 public static void SwapBuffers(GlfwWindowPtr window)
 {
     GlfwDelegates.glfwSwapBuffers(window);
 }
예제 #58
0
 public static void IconifyWindow(GlfwWindowPtr window)
 {
     GlfwDelegates.glfwIconifyWindow(window);
 }
예제 #59
0
        public void CreateWindow()
        {
            var monitor = isFullscreen ? Glfw.GetPrimaryMonitor() : GlfwMonitorPtr.Null;
            var currentWindow = Glfw.CreateWindow(Width, Height, Title, monitor, window);

            Glfw.SetKeyCallback(currentWindow, new GlfwKeyFun((w, key, scancode, action, modifiers) =>
            {
                var info = new PencilKeyInfo(key, scancode, action, modifiers);
                onKeyboard.Fire(info);
            }));

            Glfw.SetWindowCloseCallback(currentWindow, new GlfwWindowCloseFun(w =>
            {
                Exit();
            }));

            Glfw.SetWindowSizeCallback(currentWindow, new GlfwWindowSizeFun((w, width, height) =>
            {
                this.width = width;
                this.height = height;
                onWindowResized.Fire(this);
            }));

            Glfw.SwapInterval(shouldVsync ? 1 : 0);
            Glfw.MakeContextCurrent(currentWindow);
            if(!firstTime) Glfw.SetWindowShouldClose(window, true);

            window = currentWindow;
            rebuiltWindow = true;
            onWindowOpened.Fire(this);

            firstTime = false;
        }
예제 #60
0
 public static void GetWindowPos(GlfwWindowPtr window, out int xpos, out int ypos)
 {
     GlfwDelegates.glfwGetWindowPos(window, out xpos, out ypos);
 }