cangine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
cangine::Window Class Reference

Owns the application window, OpenGL context and the frame loop. More...

#include <window.hpp>

Collaboration diagram for cangine::Window:
Collaboration graph
[legend]

Public Member Functions

 Window (int width, int height, std::string title, bool fullscreen=false)
 Creates the window and OpenGL context.
 
 ~Window ()
 Destroys the window and releases GLFW resources.
 
bool shouldClose ()
 Reports whether the window has been asked to close.
 
void swapBuffers ()
 Swaps the front and back framebuffers.
 
void pollEvents ()
 Processes pending window and input events.
 
void loadGLAD ()
 Loads OpenGL function pointers via GLAD.
 
void onResize (int w, int h)
 Updates cached state in response to a resize.
 
void setTitle (std::string title)
 Sets the window title.
 
void fill (const Color &c)
 Clears the framebuffer to a solid color.
 
void beginFrame ()
 Begins a frame: updates timing and prepares for rendering.
 
void endFrame ()
 Ends a frame: swaps buffers and polls events.
 
int getFPS ()
 Returns the frames-per-second over the last full second.
 
int getInstantFPS ()
 Returns the instantaneous FPS from the latest frame.
 
double getDeltaTime ()
 Returns the time elapsed since the previous frame.
 

Static Public Member Functions

static void _characterCallback (GLFWwindow *window, unsigned int codepoint)
 Raw GLFW character input callback, forwarded to Input.
 
static void _processInput (GLFWwindow *win, int key, int scanCode, int action, int mods)
 Raw GLFW keyboard callback, forwarded to Input.
 
static void _scrollCallback (GLFWwindow *window, double xOffset, double yOffset)
 Raw GLFW scroll callback, forwarded to Mouse.
 
static Window * getInstance ()
 Returns the singleton instance.
 

Public Attributes

Dimensions dimensions
 Current window size in pixels.
 

Static Public Attributes

static std::unordered_set< Key > keysPressed
 Keys held this frame.
 
static std::unordered_set< Key > prevKeysPressed
 Keys held the previous frame (for edge detection).
 

Static Private Member Functions

static void _mouseButtonCallback (GLFWwindow *window, int button, int action, int mods)
 Raw GLFW mouse button callback, forwarded to Mouse.
 
static void _mouseEnterCallback (GLFWwindow *window, int e)
 Raw GLFW cursor enter/leave callback, forwarded to Mouse.
 
static void _mouseMoveCallback (GLFWwindow *window, double _x, double _y)
 Raw GLFW cursor move callback, forwarded to Mouse.
 

Private Attributes

double lastTime
 Timestamp used for the per-second FPS counter.
 
int frameCount
 Frames counted in the current second.
 
int fps
 Frames rendered in the last full second.
 
int instantFps
 FPS estimated from the latest frame's delta time.
 
double lastFrameTime = 0.0
 Timestamp of the previous frame.
 
float deltaTime = 0.0f
 Seconds elapsed since the previous frame.
 
GLFWwindow * main
 Underlying GLFW window handle.
 

Static Private Attributes

static Window * instance = nullptr
 

Detailed Description

Owns the application window, OpenGL context and the frame loop.

Wraps a GLFW window: creates the context, pumps input/events, tracks frame timing (FPS and delta time) and exposes per-frame begin/end hooks. Implemented as a singleton accessible via getInstance.

Constructor & Destructor Documentation

◆ Window()

cangine::Window::Window ( int  width,
int  height,
std::string  title,
bool  fullscreen = false 
)

Creates the window and OpenGL context.

Parameters
widthInitial width in pixels.
heightInitial height in pixels.
titleWindow title.
fullscreenWhether to open in fullscreen mode.

◆ ~Window()

cangine::Window::~Window ( )

Destroys the window and releases GLFW resources.

Member Function Documentation

◆ _characterCallback()

void cangine::Window::_characterCallback ( GLFWwindow *  window,
unsigned int  codepoint 
)
static

Raw GLFW character input callback, forwarded to Input.

Parameters
windowWindow receiving input.
codepointUnicode codepoint typed.

◆ _mouseButtonCallback()

void cangine::Window::_mouseButtonCallback ( GLFWwindow *  window,
int  button,
int  action,
int  mods 
)
staticprivate

Raw GLFW mouse button callback, forwarded to Mouse.

◆ _mouseEnterCallback()

void cangine::Window::_mouseEnterCallback ( GLFWwindow *  window,
int  e 
)
staticprivate

Raw GLFW cursor enter/leave callback, forwarded to Mouse.

◆ _mouseMoveCallback()

void cangine::Window::_mouseMoveCallback ( GLFWwindow *  window,
double  _x,
double  _y 
)
staticprivate

Raw GLFW cursor move callback, forwarded to Mouse.

◆ _processInput()

void cangine::Window::_processInput ( GLFWwindow *  win,
int  key,
int  scanCode,
int  action,
int  mods 
)
static

Raw GLFW keyboard callback, forwarded to Input.

◆ _scrollCallback()

void cangine::Window::_scrollCallback ( GLFWwindow *  window,
double  xOffset,
double  yOffset 
)
static

Raw GLFW scroll callback, forwarded to Mouse.

◆ beginFrame()

void cangine::Window::beginFrame ( )

Begins a frame: updates timing and prepares for rendering.

◆ endFrame()

void cangine::Window::endFrame ( )

Ends a frame: swaps buffers and polls events.

◆ fill()

void cangine::Window::fill ( const Color &  c)

Clears the framebuffer to a solid color.

Parameters
cFill color.

◆ getDeltaTime()

double cangine::Window::getDeltaTime ( )

Returns the time elapsed since the previous frame.

Returns
Delta time in seconds.

◆ getFPS()

int cangine::Window::getFPS ( )

Returns the frames-per-second over the last full second.

Returns
Averaged FPS.

◆ getInstance()

Window * cangine::Window::getInstance ( )
static

Returns the singleton instance.

Returns
Pointer to the Window instance.

◆ getInstantFPS()

int cangine::Window::getInstantFPS ( )

Returns the instantaneous FPS from the latest frame.

Returns
Instantaneous FPS.

◆ loadGLAD()

void cangine::Window::loadGLAD ( )

Loads OpenGL function pointers via GLAD.

◆ onResize()

void cangine::Window::onResize ( int  w,
int  h 
)

Updates cached state in response to a resize.

Parameters
wNew width in pixels.
hNew height in pixels.

◆ pollEvents()

void cangine::Window::pollEvents ( )

Processes pending window and input events.

◆ setTitle()

void cangine::Window::setTitle ( std::string  title)

Sets the window title.

Parameters
titleNew title text.

◆ shouldClose()

bool cangine::Window::shouldClose ( )

Reports whether the window has been asked to close.

Returns
true if the window should close.

◆ swapBuffers()

void cangine::Window::swapBuffers ( )

Swaps the front and back framebuffers.

Member Data Documentation

◆ deltaTime

float cangine::Window::deltaTime = 0.0f
private

Seconds elapsed since the previous frame.

◆ dimensions

Dimensions cangine::Window::dimensions

Current window size in pixels.

◆ fps

int cangine::Window::fps
private

Frames rendered in the last full second.

◆ frameCount

int cangine::Window::frameCount
private

Frames counted in the current second.

◆ instance

Window * cangine::Window::instance = nullptr
staticprivate

Singleton instance.

◆ instantFps

int cangine::Window::instantFps
private

FPS estimated from the latest frame's delta time.

◆ keysPressed

std::unordered_set< Key > cangine::Window::keysPressed
static

Keys held this frame.

◆ lastFrameTime

double cangine::Window::lastFrameTime = 0.0
private

Timestamp of the previous frame.

◆ lastTime

double cangine::Window::lastTime
private

Timestamp used for the per-second FPS counter.

◆ main

GLFWwindow* cangine::Window::main
private

Underlying GLFW window handle.

◆ prevKeysPressed

std::unordered_set< Key > cangine::Window::prevKeysPressed
static

Keys held the previous frame (for edge detection).


The documentation for this class was generated from the following files: