public GLApplication(GLContextParams contextParams)
        {
            this.window = new GLFWWindow(contextParams);
            this.window.Initialize += this.WindowInternal_Initialize;
            this.window.Shutdown += this.WindowInternal_Shutdown;
            this.window.Idle += this.WindowInternal_Idle;

            this.TargetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 60);
            this.MaxElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 10);
        }
Exemple #2
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();
        }