tec::OS

#include <os.hpp>

Inherits from tec::EventQueue< KeyboardEvent >

Public Functions

Name
bool InitializeWindow(const int width, const int height, const std::string title, const int glMajor =3, const int glMinor =3, bool fullscreen =false)
Initialize the rendering window and makes the window's context the current one.
void MakeCurrent()
Make the context of the window current for the calling thread.
void SetWindowAspectRatio(const unsigned int numerator =16, const unsigned int denominator =9)
Sets the desired window aspect ratio numerator:denominator e.g. 16:9, 4:3.
void ToggleFullScreen()
Toggles between fullscreen and windowed mode based.
void DetachContext()
Detach the context of the window from the calling thread.
void Quit()
Tells the OS that the active window should close.
bool Closing()
Checks if the window is closing.
void SwapBuffers()
Swap the front and back buffers. Call after rendering.
void OSMessageLoop()
Processes events in the OS message event loop.
int GetWindowWidth() const
Gets the cached window width.
int GetWindowHeight() const
Gets the cached window height.
double GetDeltaTime()
Returns the time since the start of the program.
double GetTime()
Returns the time since initialization from glfw.
GLFWwindow * GetWindow()
Returns the current active window.
void EnableMouseLock()
void DisableMouseLock()
void Terminate()
Calls GLFWTerminate to close the window.
void WindowResized(GLFWwindow * window, int width, int height)
Callback for when the window is resized.
void KeyboardEventCallback(GLFWwindow * window, int key, int scancode, int action, int mods)
Callback for keyboard events.
void CharacterEventCallback(GLFWwindow * window, unsigned int uchar)
Callback for Unicode character event.
void MouseMoveEventCallback(GLFWwindow * window, double x, double y)
Callback for mouse move events.
void MouseScrollEventCallback(GLFWwindow * window, double x, double y)
Callback for mouse scroll events.
void MouseButtonEventCallback(GLFWwindow * window, int button, int action, int mods)
Callback for mouse button events.
void WindowFocusChangeCallback(GLFWwindow * window, int focused)
Callback for window focus change events.
void FileDropCallback(GLFWwindow * window, int count, const char ** paths)
Callback for window focus change events.
void SetMousePosition(const double x, const double y)
Sets the mouse cursor position relative to the upper-left corner of the window.
void GetMousePosition(double * x, double * y)
Gets the mouse cursor position relative to the upper-left corner of the window.
const GLFWwindow * GetFocusedWindow()
void RegisterLuaType(sol::state & )

Additional inherited members

Public Functions inherited from tec::EventQueue< KeyboardEvent >

Name
EventQueue()
EventQueue(eid entity_id)
virtual ~EventQueue()
void ProcessEventQueue()
void QueueEvent(Event< T > && e)

Protected Attributes inherited from tec::EventQueue< KeyboardEvent >

Name
Queue< Event< T > > * read_event_queue
std::atomic< Queue< Event< T > > * > write_event_queue

Public Functions Documentation

function InitializeWindow

bool InitializeWindow(
    const int width,
    const int height,
    const std::string title,
    const int glMajor =3,
    const int glMinor =3,
    bool fullscreen =false
)

Initialize the rendering window and makes the window's context the current one.

Parameters:

  • const unsigned int width, height The window's client width and height
  • const std::string title The title to show in the title bar and task manager.
  • const glMajor OpenGL major version number. Must be >= 3
  • const glMinor OpenGL minor version. If major = 3, must be 3 (OpenGL 3.3)
  • bool fullscreen Whether the window should be started in fullscreen mode.

Return: bool If creation was successful or not.

function MakeCurrent

void MakeCurrent()

Make the context of the window current for the calling thread.

function SetWindowAspectRatio

void SetWindowAspectRatio(
    const unsigned int numerator =16,
    const unsigned int denominator =9
)

Sets the desired window aspect ratio numerator:denominator e.g. 16:9, 4:3.

function ToggleFullScreen

void ToggleFullScreen()

Toggles between fullscreen and windowed mode based.

function DetachContext

void DetachContext()

Detach the context of the window from the calling thread.

function Quit

void Quit()

Tells the OS that the active window should close.

Return: void

Since the main loop is based on that close status of that active window this effectively causes Closing() to return true during an upcoming message loop.

function Closing

bool Closing()

Checks if the window is closing.

Return: bool True if the window is closing.

function SwapBuffers

void SwapBuffers()

Swap the front and back buffers. Call after rendering.

Return: void

function OSMessageLoop

void OSMessageLoop()

Processes events in the OS message event loop.

function GetWindowWidth

int GetWindowWidth() const

Gets the cached window width.

Return: int The window width.

function GetWindowHeight

int GetWindowHeight() const

Gets the cached window height.

Return: int The window height.

function GetDeltaTime

double GetDeltaTime()

Returns the time since the start of the program.

Return: double The amount of time that have passed since the last call in seconds.

function GetTime

double GetTime()

Returns the time since initialization from glfw.

Return: double The amount of time since glfw was initialized in seconds.

function GetWindow

GLFWwindow * GetWindow()

Returns the current active window.

Return: GLFWwindow* The current active window.

function EnableMouseLock

void EnableMouseLock()

function DisableMouseLock

void DisableMouseLock()

function Terminate

static void Terminate()

Calls GLFWTerminate to close the window.

Return: void

This is a static method so it can be called from anywhere to terminate the current window.

function WindowResized

static void WindowResized(
    GLFWwindow * window,
    int width,
    int height
)

Callback for when the window is resized.

Parameters:

  • GLFWwindow* window
  • int width, height The new client width and height of the window.

Return: void

function KeyboardEventCallback

static void KeyboardEventCallback(
    GLFWwindow * window,
    int key,
    int scancode,
    int action,
    int mods
)

Callback for keyboard events.

Parameters:

  • GLFWwindow* window
  • int key ASCII key number.
  • int scancode The converted key value
  • int action The event type.
  • int mods Modifier keys.

Return: void

function CharacterEventCallback

static void CharacterEventCallback(
    GLFWwindow * window,
    unsigned int uchar
)

Callback for Unicode character event.

Parameters:

  • GLFWwindow* window
  • unsigned int uchar The Unicode character key code.

Return: void

This is different from just a normal keyboard event as it has been translated and modified by the OS and is just like typing into a text editor.

function MouseMoveEventCallback

static void MouseMoveEventCallback(
    GLFWwindow * window,
    double x,
    double y
)

Callback for mouse move events.

Parameters:

  • GLFWwindow* window
  • double x, y The new x and y coordinate of the mouse in screen coordinates.

Return: void

function MouseScrollEventCallback

static void MouseScrollEventCallback(
    GLFWwindow * window,
    double x,
    double y
)

Callback for mouse scroll events.

Parameters:

  • GLFWwindow* window
  • double x, y The delta x and y of the mouse wheel.

Return: void

function MouseButtonEventCallback

static void MouseButtonEventCallback(
    GLFWwindow * window,
    int button,
    int action,
    int mods
)

Callback for mouse button events.

Parameters:

  • GLFWwindow* window
  • int button The button that the action occurred on.
  • int action The action that occurred.
  • int mods Modifier keys.

Return: void

function WindowFocusChangeCallback

static void WindowFocusChangeCallback(
    GLFWwindow * window,
    int focused
)

Callback for window focus change events.

Parameters:

  • GLFWwindow* window
  • int focused GL_TRUE if focused, GL_FALSE if unfocused.

Return: void

function FileDropCallback

static void FileDropCallback(
    GLFWwindow * window,
    int count,
    const char ** paths
)

Callback for window focus change events.

Parameters:

  • GLFWwindow* window
  • int count The number of files dropped.
  • const char** paths Array of filenames.

Return: void

function SetMousePosition

static void SetMousePosition(
    const double x,
    const double y
)

Sets the mouse cursor position relative to the upper-left corner of the window.

Parameters:

  • double x, y The new x and y coordinate of the mouse in screen coordinates.

Return: void

function GetMousePosition

static void GetMousePosition(
    double * x,
    double * y
)

Gets the mouse cursor position relative to the upper-left corner of the window.

Parameters:

  • double* x, y The current x and y coordinate of the mouse in screen coordinates.

Return: void

function GetFocusedWindow

static inline const GLFWwindow * GetFocusedWindow()

function RegisterLuaType

static void RegisterLuaType(
    sol::state & 
)

Updated on 2022-07-24 at 19:27:35 +0000