Class GLFWRenderModuleWindow

java.lang.Object
io.codetoil.curved_spacetime.render.RenderModuleWindow
io.codetoil.curved_spacetime.render.glfw.GLFWRenderModuleWindow
Direct Known Subclasses:
VulkanGLFWRenderModuleWindow

public abstract class GLFWRenderModuleWindow extends RenderModuleWindow
A window backed by GLFW, sized to the primary monitor.

Handles the parts of window management that are the same whichever graphics API is being driven: initialising GLFW, opening the window, wiring up input, and tearing it all down. Subclasses supply the API-specific pieces — which window hints to set, and how to check that a usable driver is present.

Closing the window stops the engine, so the window's lifetime is effectively the program's.

This will be changed in a future build, as to allow no-window and multi-window setups.

  • Field Details

    • windowHandle

      protected long windowHandle
      The GLFW window handle, valid between init() and clean().
    • width

      protected int width
      The window's width, kept current by GLFW's framebuffer size callback.
    • height

      protected int height
      The window's height, kept current by GLFW's framebuffer size callback.
    • initialized

      protected boolean initialized
      Whether the window has been initialized.
  • Constructor Details

    • GLFWRenderModuleWindow

      protected GLFWRenderModuleWindow(MainModuleEngine mainModuleEngine, String title, Logger logger)
      Creates a GLFW window.

      Nothing is opened until init() is called.

      Parameters:
      mainModuleEngine - the engine this window belongs to
      title - the window's title bar text
      logger - the logger to write window diagnostics to
  • Method Details

    • init

      public void init()
      Description copied from class: RenderModuleWindow
      Opens the window and creates its input objects.
      Specified by:
      init in class RenderModuleWindow
    • loop

      public void loop()
      Description copied from class: RenderModuleWindow
      Advances the window by one frame, sampling input and handling a close request.
      Specified by:
      loop in class RenderModuleWindow
    • getHeight

      public int getHeight()
      Description copied from class: RenderModuleWindow
      Returns the window's height.
      Specified by:
      getHeight in class RenderModuleWindow
      Returns:
      the current height in pixels
    • getWidth

      public int getWidth()
      Description copied from class: RenderModuleWindow
      Returns the window's width.
      Specified by:
      getWidth in class RenderModuleWindow
      Returns:
      the current width in pixels
    • isInitialized

      public boolean isInitialized()
      Description copied from class: RenderModuleWindow
      Returns whether the window has been initialized
      Specified by:
      isInitialized in class RenderModuleWindow
      Returns:
      true if the window is initialized.
    • setShouldClose

      public void setShouldClose()
      Description copied from class: RenderModuleWindow
      Asks the window to close at the next opportunity.
      Overrides:
      setShouldClose in class RenderModuleWindow
    • shouldClose

      public boolean shouldClose()
      Description copied from class: RenderModuleWindow
      Returns whether the window has been asked to close.
      Overrides:
      shouldClose in class RenderModuleWindow
      Returns:
      true once a close has been requested, by this class or by the user
    • clean

      public void clean()
      Description copied from class: RenderModuleWindow
      Destroys the window and releases its platform resources.
      Specified by:
      clean in class RenderModuleWindow
    • doesDriverExist

      public abstract boolean doesDriverExist()
      Returns whether a driver for the subclass's graphics API is present.

      Checked during init(), before the window is created, so that an unusable environment is reported before any resource is acquired.

      Returns:
      true if the graphics API can be used on this machine
    • throwDriverNotFoundException

      protected abstract void throwDriverNotFoundException()
      Fails with a message naming the graphics API that could not be found.

      Called when doesDriverExist() returns false; implementations are expected to throw rather than return.

    • setWindowHints

      protected abstract void setWindowHints()
      Applies the GLFW window hints the subclass's graphics API requires.

      Called before the window is created. A Vulkan implementation, for example, sets GLFW_CLIENT_API to GLFW_NO_API so GLFW does not create an OpenGL context.

    • getWindowHandle

      public long getWindowHandle()
      Returns the underlying GLFW window handle.

      Needed to create a rendering surface against this window.

      Returns:
      the GLFW window handle, or 0 before init()