コード例 #1
0
ファイル: GLFW3_Wrapper.cs プロジェクト: masums/GLFW3.NET
 /// <summary>
 /// Init this instance.
 /// Callbacks are here initialized for the events.
 /// </summary>
 private void Init()
 {
     SizeChangedCallback = (IntPtr _handle, int width, int height) => {
         SizeChanged.Invoke(this, new SizeChangedEventArgs {
             source = this, width = width, height = height
         });
     };
     Glfw.SetWindowSizeCallback(this, SizeChangedCallback);
     KeyPressedCallback = (IntPtr _handle, int key, int scancode, int action, int mods) =>
     {
         var args = new KeyEventArgs
         {
             source   = this,
             key      = (Key)System.Enum.Parse(typeof(Key), key.ToString()),
             action   = (State)System.Enum.Parse(typeof(State), action.ToString()),
             scancode = scancode,
             mods     = mods
         };
         KeyChanged.Invoke(this, args);
     };
     Glfw.SetKeyCallback(this, KeyPressedCallback);
     // Add dummy handlers to prevent any null reference exceptions
     SizeChanged = new EventHandler <SizeChangedEventArgs>((__, _) => { });
     KeyChanged  = new EventHandler <KeyEventArgs>((__, _) => { });
 }
コード例 #2
0
        public Game()
        {
            var basePath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location ?? "");

            Directory.SetCurrentDirectory(basePath);

            if (glfwInit() == 0)
            {
                throw new InvalidOperationException("Failed to initialize GLFW.");
            }

            glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

            _window = glfwCreateWindow(1024, 768, "SameGame", IntPtr.Zero, IntPtr.Zero);

            if (_window == IntPtr.Zero)
            {
                throw new InvalidOperationException("Failed to create window.");
            }

            _windowSizeCallback = (a, b, c) => OnWindowSize(a, b, c);
            glfwSetWindowSizeCallback(_window, _windowSizeCallback);

            _keyboardCallback = (a, b, c, d, e) => OnKeyboard(a, b, c, d, e);
            glfwSetKeyCallback(_window, _keyboardCallback);

            _mouseMoveCallback = (a, b, c) => OnMouseMove(a, b, c);
            glfwSetCursorPosCallback(_window, _mouseMoveCallback);

            _mouseButtonCallback = (a, b, c, d) => OnMouseButton(a, b, c, d);
            glfwSetMouseButtonCallback(_window, _mouseButtonCallback);

            GLUtils.CreateContext(_window, out _display, out _surface);

            Graphics = new Graphics(this);

            BoardRenderer = new BoardRenderer(Graphics);

            Board = new Board(new RNG(100));
        }
コード例 #3
0
ファイル: Glfw.cs プロジェクト: SpectrumLib/Spectrum
 public static void SetWindowSizeCallback(IntPtr window, GLFWwindowsizefun func) => _glfwSetWindowSizeCallback(window, func);
コード例 #4
0
 public static extern GLFWwindowsizefun glfwSetWindowSizeCallback(IntPtr window, GLFWwindowsizefun cbfun);
コード例 #5
0
ファイル: Window.cs プロジェクト: PlumpMath/GLFWSharp
 public static GLFWwindowsizefun setWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun)
 {
     return(Glfwint.setWindowSizeCallback(window.handle, cbfun));
 }
コード例 #6
0
 [DllImport(GLFW_DLL, EntryPoint = "glfwSetWindowSizeCallback")] public static extern void SetWindowSizeCallback(IntPtr window, GLFWwindowsizefun cbfun);
コード例 #7
0
ファイル: Glfw.cs プロジェクト: vhotur/tao
 public static extern void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun);
コード例 #8
0
 internal OpenGLContext(string name)
 {
     if (GLFW.GlfwInit() == 0)
     {
         Console.Error.WriteLine("GLFW failed to initialize!");
         Environment.Exit(1);
     }
     Window = GLFW.GlfwCreateWindow(1920, 1080, name, null, null);
     if (Window == null)
     {
         Console.Error.WriteLine("GLFW failed to open window!");
         GLFW.GlfwTerminate();
         Environment.Exit(1);
     }
     Input = new InputSource();
     GLFW.GlfwMakeContextCurrent(Window);
     StrongReferences = new List <Delegate>();
     {
         GLFWkeyfun cb = KeyCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetKeyCallback(Window, cb);
     }
     {
         GLFWcharfun cb = CharCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetCharCallback(Window, cb);
     }
     {
         GLFWerrorfun cb = ErrorCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetErrorCallback(cb);
     }
     {
         GLFWscrollfun cb = ScrollCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetScrollCallback(Window, cb);
     }
     {
         GLFWcharmodsfun cb = CharModsCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetCharModsCallback(Window, cb);
     }
     {
         GLFWcursorposfun cb = CursorPosCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetCursorPosCallback(Window, cb);
     }
     {
         GLFWwindowposfun cb = WindowPosCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetWindowPosCallback(Window, cb);
     }
     {
         GLFWwindowsizefun cb = WindowSizeCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetWindowSizeCallback(Window, cb);
     }
     {
         GLFWcursorenterfun cb = CursorEnterCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetCursorEnterCallback(Window, cb);
     }
     {
         GLFWmousebuttonfun cb = MouseButtonCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetMouseButtonCallback(Window, cb);
     }
     {
         GLFWwindowfocusfun cb = WindowFocusCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetWindowFocusCallback(Window, cb);
     }
     {
         GLFWwindowiconifyfun cb = WindowIconifyCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetWindowIconifyCallback(Window, cb);
     }
     {
         GLFWframebuffersizefun cb = FrameBufferSizeCallback;
         StrongReferences.Add(cb);
         GLFW.GlfwSetFramebufferSizeCallback(Window, cb);
     }
 }
コード例 #9
0
ファイル: GlfwWindow.cs プロジェクト: DangerRoss/JankWorks
        public GlfwWindow(WindowSettings settings) : base(settings)
        {
            var glfwMonitor = settings.Monitor as GlfwMonitor ?? throw new NotSupportedException();

            this.keyRepeatEnabled = false;

            var enc = Encoding.GetEncoding("utf-32", new EncoderReplacementFallback("□"), new DecoderReplacementFallback("□"));

            this.utf32Decoder = enc.GetDecoder();

            glfwDefaultWindowHints();

            glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
            glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
            glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);

            switch (settings.Style)
            {
            case WindowStyle.Windowed:
                glfwWindowHint(GLFW_DECORATED, GLFW_TRUE);
                break;

            case WindowStyle.FullScreen:
            case WindowStyle.Borderless:
                glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
                break;
            }

            checked
            {
                var mode          = settings.DisplayMode;
                int bitspercolour = (int)mode.BitsPerPixel / 4;

                glfwWindowHint(GLFW_RED_BITS, bitspercolour);
                glfwWindowHint(GLFW_GREEN_BITS, bitspercolour);
                glfwWindowHint(GLFW_BLUE_BITS, bitspercolour);
                glfwWindowHint(GLFW_ALPHA_BITS, bitspercolour);

                glfwWindowHint(GLFW_REFRESH_RATE, (int)mode.RefreshRate);

                var titleutf8 = Encoding.UTF8.GetBytes(settings.Title);

                unsafe
                {
                    fixed(byte *titleptr = titleutf8)
                    {
                        this.window = glfwCreateWindow((int)mode.Width, (int)mode.Height, titleptr, settings.Style == WindowStyle.FullScreen ? glfwMonitor.Handle : IntPtr.Zero, IntPtr.Zero);
                    }
                }
            }

            if (this.window == IntPtr.Zero)
            {
                var errorPtr = IntPtr.Zero;
                glfwGetError(errorPtr);
                var errorDesc = new CString(errorPtr);
                throw new ApplicationException(errorDesc);
            }

            this.windowResizeDelegate = this.HandleResizeEvent;
            this.windowFocusDelegate  = this.HandleFocusEvent;
            this.cursorEnterDelegate  = this.HandleMouseEnterOrLeaveEvent;
            this.cursorMoveDelegate   = this.HandleMouseMoveEvent;
            this.mouseButtonDelegate  = this.HandleMouseButtonEvent;
            this.scrollDelegate       = this.HandleScrollEvent;
            this.keyDelegate          = this.HandleKeyEvent;
            this.textDelegate         = this.HandleTextEvent;

            this.SetupCallbacks();

            this.Activate();
            glfwSwapInterval(settings.VSync ? 1 : 0);
            glfwSetInputMode(this.window, GLFW_CURSOR, settings.ShowCursor ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
        }
コード例 #10
0
ファイル: GLFW3.Bindings.cs プロジェクト: lodico/glfw-net
 /*! @brief Sets the size callback for the specified window.
  *
  *  This function sets the size callback of the specified window, which is
  *  called when the window is resized.  The callback is provided with the size,
  *  in screen coordinates, of the client area of the window.
  *
  *  @param[in] window The window whose callback to set.
  *  @param[in] cbfun The new callback, or `NULL` to remove the currently set
  *  callback.
  *  @return The previously set callback, or `NULL` if no callback was set or the
  *  library had not been [initialized](@ref intro_init).
  *
  *  @par Thread Safety
  *  This function may only be called from the main thread.
  *
  *  @sa @ref window_size
  *
  *  @since Added in GLFW 1.0.
  *
  *  @par
  *  __GLFW 3:__ Added window handle parameter.  Updated callback signature.
  *
  *  @ingroup window
  */
 internal static extern GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun cbfun);