CGVIS Utils
Loading...
Searching...
No Matches
GLEnv Class Reference

Window/context manager for OpenGL (GLFW+GLEW) or WebGL (Emscripten). More...

#include <GLEnv.h>

Public Member Functions

 GLEnv (uint32_t w, uint32_t h, uint32_t s, const std::string &title, bool fpsCounter=false, bool sync=true, int major=2, int minor=1, bool core=false)
 Construct a GL environment and create a window/canvas + context.
 ~GLEnv ()
 Destroy window/context (desktop) or release resources (web).
void setKeyCallback (GLFWkeyfun f)
 Set key callback for GLFW builds.
void setKeyCallbacks (GLFWkeyfun f, GLFWcharfun c)
 Set key + char callbacks for GLFW builds.
void setMouseCallbacks (GLFWcursorposfun p, GLFWmousebuttonfun b, GLFWscrollfun s)
 Set mouse position/button/scroll callbacks for GLFW builds.
void setResizeCallback (GLFWframebuffersizefun f)
 Set framebuffer resize callback for GLFW builds.
Dimensions getFramebufferSize () const
 Get framebuffer size in texels/pixels.
Dimensions getWindowSize () const
 Get logical window size.
bool shouldClose () const
 Query whether the window should close (desktop always; web always false).
void setClose ()
 Request closing the window (desktop only; no‑op on web).
void endOfFrame ()
 End‑of‑frame housekeeping: swap/poll + optional FPS title update.
void setCursorMode (CursorMode mode)
 Set mouse cursor behavior.
void setFPSCounter (bool fpsCounter)
 Enable/disable FPS title updates.
void setSync (bool sync)
 Enable/disable vsync.
bool getSync () const
 Current vsync state.
void setTitle (const std::string &title)
 Set the window/page title (stored; displayed on next FPS refresh).

Static Public Member Functions

static void checkGLError (const std::string &id)
 Convenience GL error check, logs to stderr with an identifier.

Detailed Description

Window/context manager for OpenGL (GLFW+GLEW) or WebGL (Emscripten).

Creates a context and provides utilities around frame management, input, vsync, and dimension queries. On errors, the desktop path throws GLException using GLFW's error callback; Web builds avoid tear‑down exceptions for shouldClose().

Constructor & Destructor Documentation

◆ GLEnv()

GLEnv::GLEnv ( uint32_t w,
uint32_t h,
uint32_t s,
const std::string & title,
bool fpsCounter = false,
bool sync = true,
int major = 2,
int minor = 1,
bool core = false )

Construct a GL environment and create a window/canvas + context.

Parameters
wInitial width in pixels.
hInitial height in pixels.
sMultisample count (GLFW window hint).
titleWindow title (desktop) or page title (web via FPS counter).
fpsCounterIf true, compute FPS and append to the title each second.
syncIf true, enable vsync (glfwSwapInterval(1) / RAF timing).
majorRequested GL major version (desktop) / WebGL major.
minorRequested GL minor version (desktop) / WebGL minor.
coreIf true (desktop), request a core profile context.
Exceptions
GLExceptionOn GLFW/GLEW initialization or window creation failures.
Here is the call graph for this function:

◆ ~GLEnv()

GLEnv::~GLEnv ( )

Destroy window/context (desktop) or release resources (web).

Member Function Documentation

◆ checkGLError()

void GLEnv::checkGLError ( const std::string & id)
static

Convenience GL error check, logs to stderr with an identifier.

Parameters
idHuman‑readable label for the check site.
Here is the call graph for this function:

◆ endOfFrame()

void GLEnv::endOfFrame ( )

End‑of‑frame housekeeping: swap/poll + optional FPS title update.

◆ getFramebufferSize()

Dimensions GLEnv::getFramebufferSize ( ) const

Get framebuffer size in texels/pixels.

Returns
Dimensions with width/height (framebuffer).

◆ getSync()

bool GLEnv::getSync ( ) const
inline

Current vsync state.

◆ getWindowSize()

Dimensions GLEnv::getWindowSize ( ) const

Get logical window size.

Returns
Dimensions with width/height (window/canvas).

◆ setClose()

void GLEnv::setClose ( )

Request closing the window (desktop only; no‑op on web).

◆ setCursorMode()

void GLEnv::setCursorMode ( CursorMode mode)

Set mouse cursor behavior.

Parameters
modeNORMAL (visible), HIDDEN, or FIXED (pointer‑lock/web or disabled cursor/desktop).

◆ setFPSCounter()

void GLEnv::setFPSCounter ( bool fpsCounter)

Enable/disable FPS title updates.

◆ setKeyCallback()

void GLEnv::setKeyCallback ( GLFWkeyfun f)

Set key callback for GLFW builds.

◆ setKeyCallbacks()

void GLEnv::setKeyCallbacks ( GLFWkeyfun f,
GLFWcharfun c )

Set key + char callbacks for GLFW builds.

◆ setMouseCallbacks()

void GLEnv::setMouseCallbacks ( GLFWcursorposfun p,
GLFWmousebuttonfun b,
GLFWscrollfun s )

Set mouse position/button/scroll callbacks for GLFW builds.

◆ setResizeCallback()

void GLEnv::setResizeCallback ( GLFWframebuffersizefun f)

Set framebuffer resize callback for GLFW builds.

◆ setSync()

void GLEnv::setSync ( bool sync)

Enable/disable vsync.

Here is the caller graph for this function:

◆ setTitle()

void GLEnv::setTitle ( const std::string & title)

Set the window/page title (stored; displayed on next FPS refresh).

◆ shouldClose()

bool GLEnv::shouldClose ( ) const

Query whether the window should close (desktop always; web always false).


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