예제 #1
0
        public Window()
        {
            this.title  = string.Empty;
            this.width  = 800;
            this.height = 600;

            this.Handle = GLFW.CreateWindow(this.width, this.height, this.title, IntPtr.Zero, IntPtr.Zero);

            if (this.Handle == IntPtr.Zero)
            {
                throw new GLFWException("Failed to create window.");
            }

            int xpos, ypos;

            GLFW.GetWindowPos(this.Handle, out xpos, out ypos);
            this.x = xpos;
            this.y = ypos;

            this.keyCallback = this.OnKey;
            GLFW.SetKeyCallback(this.Handle, this.keyCallback);

            this.windowPosCallback = this.OnWindowPos;
            GLFW.SetWindowPosCallback(this.Handle, this.windowPosCallback);

            this.windowSizeCallback = this.OnWindowSize;
            GLFW.SetWindowSizeCallback(this.Handle, this.windowSizeCallback);
        }
예제 #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                GLFW.SetKeyCallback(this.Handle, null);
                this.keyCallback = null;

                GLFW.SetWindowPosCallback(this.Handle, null);
                this.windowPosCallback = null;

                GLFW.SetWindowSizeCallback(this.Handle, null);
                this.windowSizeCallback = null;
            }
        }
예제 #3
0
        public GLFWWindow(GLContextParams contextParams)
        {
            if (GLFW.Init() == 0)
                throw new GLFWException("GLFW initialization failed.");

            GLFW.RegisterErrorCallback();

            GLFW.WindowHint(GLFW.CLIENT_API, GLFW.OPENGL_API);
            GLFW.WindowHint(GLFW.CONTEXT_VERSION_MAJOR, contextParams.VersionMajor);
            GLFW.WindowHint(GLFW.CONTEXT_VERSION_MINOR, contextParams.VersionMinor);
            GLFW.WindowHint(GLFW.OPENGL_FORWARD_COMPAT, contextParams.ForwardCompatible ? 1 : 0);

            this.window = GLFW.CreateWindow(800, 600, string.Empty, IntPtr.Zero, IntPtr.Zero);

            this.title = string.Empty;
            this.size = new Size(800, 600);
            this.position = new Point(0, 0);

            // It is important to hold references to the callbacks so that the GC does not garbage collect the delegates.

            this.windowPosCallback = this.OnWindowMove;
            GLFW.SetWindowPosCallback(this.window, this.windowPosCallback);

            this.windowSizeCallback = this.OnWindowResize;
            GLFW.SetWindowSizeCallback(this.window, this.windowSizeCallback);

            this.charCallback = this.OnChar;
            GLFW.SetCharCallback(this.window, this.charCallback);

            this.keyCallback = this.OnKey;
            GLFW.SetKeyCallback(this.window, this.keyCallback);

            this.cursorPosCallback = this.OnCursorPos;
            GLFW.SetCursorPosCallback(this.window, this.cursorPosCallback);

            this.mouseButtonCallback = this.OnMouseButton;
            GLFW.SetMouseButtonCallback(this.window, this.mouseButtonCallback);

            this.scrollCallback = this.OnScroll;
            GLFW.SetSetScrollCallback(this.window, this.scrollCallback);

            GLFW.MakeContextCurrent(this.window);
            this.GLContext = new GLContext(new GLFWContext(contextParams, this.window));

            this.keyEventArgs = new KeyEventArgs();
            this.keyPressEventArgs = new KeyPressEventArgs();
            this.mouseEventArgs = new MouseEventArgs();
            this.mouseButtonEventArgs = new MouseButtonEventArgs();
            this.mouseWheelEventArgs = new MouseWheelEventArgs();
        }