|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
SDL2 + OpenGL/ES window with event loop and console support. More...
#include <gl.hpp>
Public Member Functions | |
| GLWindow (const std::string &text, int width, int height, bool resize_=true, GLMode mode=GLMode::DESKTOP) | |
| Construct and open an SDL2 + OpenGL window. | |
| GLWindow (int width, int height, GLMode mode) | |
| Construct a window from dimensions and mode (internal use). | |
| virtual | ~GLWindow () |
| Destructor — destroys the GL context and SDL window. | |
| GLWindow (const GLWindow &)=delete | |
| GLWindow & | operator= (const GLWindow &)=delete |
| GLWindow (GLWindow &&)=delete | |
| GLWindow & | operator= (GLWindow &&)=delete |
| void | initGL (const std::string &title, int width, int height, bool resize_=true) |
| Initialise the GL context and SDL window. | |
| void | initGL (int width, int height) |
| Reinitialise with only dimensions (used by Emscripten). | |
| void | updateViewport () |
| Update the GL viewport to match the current window size. | |
| void | swap () |
| Swap front and back buffers to display the rendered frame. | |
| virtual void | event (SDL_Event &e)=0 |
| Process a single SDL event (pure virtual). | |
| virtual void | draw ()=0 |
| Render the current frame (pure virtual). | |
| virtual void | resize (int w, int h) |
| Called when the window is resized (optional override). | |
| void | setObject (GLObject *o) |
| Attach a GLObject to receive draw/event callbacks. | |
| void | quit () |
| Request the event loop to stop. | |
| void | proc () |
| Run the event+draw loop until quit() is called. | |
| void | loop () |
| Start the blocking main loop. | |
| void | delay () |
| Insert a small sleep to cap frame rate. | |
| void | setPath (const std::string &path) |
| Set the asset search path. | |
| void | setWindowTitle (const std::string &title) |
| Change the window title bar text. | |
| void | setWindowSize (int w, int h) |
| Resize the SDL window. | |
| void | setWindowIcon (SDL_Surface *ico) |
| Set the window icon from an SDL_Surface. | |
| void | setFullScreen (bool full) |
| Toggle fullscreen mode. | |
| void | activateConsole (const std::string &fnt, int size, const SDL_Color &color) |
| Activate the built-in debug console. | |
| void | activateConsole (const SDL_Rect &rc, const std::string &fnt, int size, const SDL_Color &color) |
| Activate the console at a specific screen region. | |
| void | drawConsole () |
| Draw the console overlay onto the current frame. | |
| void | showConsole (bool show) |
| Show or hide the console overlay. | |
| SDL_Window * | getWindow () |
| void | makeCurrent () |
| Restore this window's GL context as current on the calling thread. | |
Public Attributes | |
| std::unique_ptr< gl::GLObject > | object |
| Optional attached scene object. | |
| mx::mxUtil | util |
| Asset path and utility helpers. | |
| console::GLConsole | console |
| Built-in debug console. | |
| int | w = 0 |
| Current window width. | |
| int | h = 0 |
| Current window height. | |
| mx::Mixer | mixer |
| GLText | text |
| bool | console_visible = false |
| bool | console_active = false |
Private Attributes | |
| GLMode | gl_mode |
| SDL_GLContext | glContext |
| SDL_Window * | window = nullptr |
| bool | active = false |
| SDL_Event | e |
| bool | hide_console = false |
SDL2 + OpenGL/ES window with event loop and console support.
Creates an SDL2 window with an OpenGL (or GLES) context. Derived classes implement event() and draw(). An optional GLObject can be attached to delegate rendering. A built-in GLConsole can be activated for in-app debugging.
|
inline |
Construct and open an SDL2 + OpenGL window.
| text | Window title. |
| width | Width in pixels. |
| height | Height in pixels. |
| resize_ | Allow window resizing if true. |
| mode | GL mode (DESKTOP or ES). |
Definition at line 427 of file gl.hpp.
References gl::DESKTOP, gl_mode, glContext, initGL(), text, and window.
Referenced by GLWindow(), GLWindow(), operator=(), and operator=().
| gl::GLWindow::GLWindow | ( | int | width, |
| int | height, | ||
| GLMode | mode ) |
|
virtual |
Destructor — destroys the GL context and SDL window.
Definition at line 21 of file gl.cpp.
References glContext, mx::system_out, and window.
|
delete |
References GLWindow().
|
delete |
References GLWindow().
| void gl::GLWindow::activateConsole | ( | const SDL_Rect & | rc, |
| const std::string & | fnt, | ||
| int | size, | ||
| const SDL_Color & | color ) |
Activate the console at a specific screen region.
| rc | Console rectangle. |
| fnt | Font file path. |
| size | Font size. |
| color | Text colour. |
Definition at line 299 of file gl.cpp.
References console_active.
| void gl::GLWindow::activateConsole | ( | const std::string & | fnt, |
| int | size, | ||
| const SDL_Color & | color ) |
Activate the built-in debug console.
| fnt | Font file path. |
| size | Font size in points. |
| color | Text colour. |
Definition at line 294 of file gl.cpp.
References console_active.
| void gl::GLWindow::delay | ( | ) |
|
pure virtual |
Render the current frame (pure virtual).
Referenced by proc().
| void gl::GLWindow::drawConsole | ( | ) |
Draw the console overlay onto the current frame.
Definition at line 402 of file gl.cpp.
References console_visible.
Referenced by swap().
|
pure virtual |
|
inline |
| void gl::GLWindow::initGL | ( | const std::string & | title, |
| int | width, | ||
| int | height, | ||
| bool | resize_ = true ) |
Initialise the GL context and SDL window.
| title | Window title. |
| width | Width. |
| height | Height. |
| resize_ | Allow resizing. |
Definition at line 138 of file gl.cpp.
References gl::DESKTOP, gl_mode, glContext, h, mx::redirect(), mx::system_err, mx::system_out, text, w, and window.
Referenced by GLWindow(), GLWindow(), and operator=().
| void gl::GLWindow::initGL | ( | int | width, |
| int | height ) |
Reinitialise with only dimensions (used by Emscripten).
| width | New width. |
| height | New height. |
Definition at line 79 of file gl.cpp.
References gl::DESKTOP, gl_mode, glContext, h, mx::redirect(), mx::system_err, mx::system_out, text, w, and window.
| void gl::GLWindow::loop | ( | ) |
| void gl::GLWindow::makeCurrent | ( | ) |
References GLWindow().
References GLWindow(), initGL(), swap(), and updateViewport().
| void gl::GLWindow::proc | ( | ) |
Run the event+draw loop until quit() is called.
Definition at line 341 of file gl.cpp.
References active, console_active, console_visible, draw(), e, event(), hide_console, updateViewport(), and window.
Referenced by loop().
| void gl::GLWindow::quit | ( | ) |
Request the event loop to stop.
Definition at line 328 of file gl.cpp.
References active.
Referenced by console::GLConsole::event().
|
inlinevirtual |
| void gl::GLWindow::setFullScreen | ( | bool | full | ) |
Toggle fullscreen mode.
| full | true for fullscreen. |
Definition at line 282 of file gl.cpp.
References updateViewport(), and window.
| void gl::GLWindow::setObject | ( | gl::GLObject * | o | ) |
|
inline |
| void gl::GLWindow::setWindowIcon | ( | SDL_Surface * | ico | ) |
| void gl::GLWindow::setWindowSize | ( | int | w, |
| int | h ) |
| void gl::GLWindow::setWindowTitle | ( | const std::string & | title | ) |
| void gl::GLWindow::showConsole | ( | bool | show | ) |
Show or hide the console overlay.
| show | true to show, false to hide. |
Definition at line 310 of file gl.cpp.
References console_visible.
| void gl::GLWindow::swap | ( | ) |
Swap front and back buffers to display the rendered frame.
Definition at line 315 of file gl.cpp.
References drawConsole(), and window.
Referenced by operator=().
| void gl::GLWindow::updateViewport | ( | ) |
Update the GL viewport to match the current window size.
Definition at line 46 of file gl.cpp.
References console_active, h, text, w, and window.
Referenced by operator=(), proc(), setFullScreen(), and setWindowSize().
|
private |
| console::GLConsole gl::GLWindow::console |
| bool gl::GLWindow::console_active = false |
Definition at line 576 of file gl.hpp.
Referenced by activateConsole(), activateConsole(), proc(), and updateViewport().
| bool gl::GLWindow::console_visible = false |
Definition at line 575 of file gl.hpp.
Referenced by drawConsole(), console::GLConsole::event(), proc(), and showConsole().
|
private |
|
private |
Definition at line 413 of file gl.hpp.
Referenced by GLWindow(), GLWindow(), initGL(), and initGL().
|
private |
Definition at line 578 of file gl.hpp.
Referenced by GLWindow(), GLWindow(), initGL(), initGL(), makeCurrent(), and ~GLWindow().
| int gl::GLWindow::h = 0 |
Current window height.
Definition at line 564 of file gl.hpp.
Referenced by initGL(), initGL(), console::GLConsole::load(), console::GLConsole::load(), resize(), setWindowSize(), and updateViewport().
|
private |
| std::unique_ptr<gl::GLObject> gl::GLWindow::object |
| GLText gl::GLWindow::text |
Definition at line 574 of file gl.hpp.
Referenced by GLWindow(), initGL(), initGL(), and updateViewport().
| mx::mxUtil gl::GLWindow::util |
Asset path and utility helpers.
Definition at line 561 of file gl.hpp.
Referenced by console::GLConsole::load(), console::GLConsole::load(), and setPath().
| int gl::GLWindow::w = 0 |
Current window width.
Definition at line 563 of file gl.hpp.
Referenced by initGL(), initGL(), console::GLConsole::load(), console::GLConsole::load(), resize(), setWindowSize(), and updateViewport().
|
private |
Definition at line 579 of file gl.hpp.
Referenced by getWindow(), GLWindow(), GLWindow(), initGL(), initGL(), makeCurrent(), proc(), setFullScreen(), setWindowIcon(), setWindowSize(), setWindowTitle(), swap(), updateViewport(), and ~GLWindow().