Class GLFWContext

java.lang.Object
com.blackrook.gloop.glfw.GLFWContext

public final class GLFWContext extends Object
GLFW context state.
Author:
Matthew Tropiano
  • Constructor Details

    • GLFWContext

      public GLFWContext()
  • Method Details

    • init

      public static void init()
      Initializes GLFW. If already initialized, this does nothing.

      This must only be called from the main thread.

    • terminate

      public static void terminate()
      Destroys GLFW and frees its resources. The error callback is also freed. Does nothing if GLFW was not initialized.

      This must only be called from the main thread.

    • setErrorStream

      public static void setErrorStream(PrintStream stream)
      Sets the output stream for GLFW error callbacks. This can be called before initialization.

      This must only be called from the main thread.

      Parameters:
      stream - the stream to print to.
    • makeContextCurrent

      public static void makeContextCurrent(GLFWWindow window)
      Makes a window the current target of OpenGL/GLES calls for this thread. If the provided window is already current on this thread, nothing happens. If the provided window is already current on a different thread, this throws an IllegalStateException. If the provided window is null, and this thread has no bound context, nothing happens.

      This can be called from any thread, preferably the rendering thread.

      Parameters:
      window - the window to set as current, or null to detach from the thread.
      Throws:
      IllegalStateException - if the provided window is not null, and already current on a different thread.
      See Also:
    • setSwapInterval

      public static void setSwapInterval(int blanks)
      Sets how many vertical blanks need to occur before a window buffer swap. In layman's terms, this either sets VSync on (1 or greater) or off (0).

      This cannot be called until makeContextCurrent(GLFWWindow) is called in this thread.

      This can be called from any thread.

      Parameters:
      blanks - the amount of vertical blanks to wait.
      Throws:
      IllegalArgumentException - if blanks is less than 0.
      See Also:
    • pollEvents

      public static void pollEvents()
      Polls and processes all pending events. Any event that came in from any window is flushed through the callbacks and processed by bound listeners.

      This must only be called from the main thread. It is suggested that this be put in a loop at the end of initialization.

      This must NOT be called from any callback nor listener.

    • awaitEvents

      public static void awaitEvents()
      Polls and processes all pending events, but waits for an event first. Any event that came in from any window is flushed through the callbacks and processed by bound listeners.

      This must only be called from the main thread. It is suggested that this be put in a loop at the end of initialization.

      This must NOT be called from any callback nor listener.

    • awaitEvents

      public static void awaitEvents(long millis)
      Polls and processes all pending events, but waits for an event first for a specific amount of time. Any event that came in from any window is flushed through the callbacks and processed by bound listeners.

      This must only be called from the main thread. It is suggested that this be put in a loop at the end of initialization.

      This must NOT be called from any callback nor listener.

      NOTE: The corresponding call in GLFW uses a double for its wait parameter. This is in milliseconds because anything smaller than a millisecond does not sleep an adequate time, and would act as though you called glfwPollEvents() instead.

      Parameters:
      millis - the time in milliseconds to wait.
    • postEmptyEvent

      public static void postEmptyEvent()
      Posts an empty event so that a call to awaitEvents() continues on without receiving anything processable.

      This can be called from any thread.

    • createLoop

      public static GLFWContext.MainLoop createLoop(GLFWWindow window, GLFWInputSystem inputSystem)
      Creates a mechanism for looping on polling a GLFWWindow and InputSystem. Already assumes that the GLFWInputSystem is attached (GLFWInputSystem.attachToWindow(GLFWWindow)) to the window for listening to events.
      Parameters:
      window - the provided window handle.
      inputSystem - the input system to poll (for joystick input - mouse/keyboard is handled by the window).
      Returns:
      a new main loop object.