Skip to main content

GLFWFactory Class

Factory class for creating pre-configured GLFW-specific application components. More...

Declaration

class helios::ext::glfw::app::GLFWFactory { ... }

Public Static Functions Index

static std::unique_ptr< GLFWApplication >makeOpenGLApp (std::string title, int width=800, int height=600, int aspectRatioNumer=0, int aspectRatioDenom=0)

Creates a pre-configured GLFWApplication instance for OpenGL rendering. More...

static helios::ext::glfw::window::GLFWWindowConfigmakeWindowCfg (std::string title, int width=800, int height=600, int aspectRatioNumer=0, int aspectRatioDenom=0)

Creates a default `GLFWWindowConfig` with the specific title. More...

Description

Factory class for creating pre-configured GLFW-specific application components.

Eases setup of examples and default applications by reducing required boilerplate code.

Definition at line 40 of file GLFWFactory.ixx.

Public Static Functions

makeOpenGLApp()

std::unique_ptr< GLFWApplication > helios::ext::glfw::app::GLFWFactory::makeOpenGLApp (std::string title, int width=800, int height=600, int aspectRatioNumer=0, int aspectRatioDenom=0)
inline static

Creates a pre-configured GLFWApplication instance for OpenGL rendering.

Parameters
title

The default title used with the application's main window.

width

The width for the main window.

height

The height for the main window.

aspectRatioNumer

Aspect ratio numerator.

aspectRatioDenom

Aspect ratio denominator.

Returns

A unique_ptr to the newly created GLFWApplication.

Definition at line 55 of file GLFWFactory.ixx.

55 static std::unique_ptr<GLFWApplication> makeOpenGLApp(
56 std::string title,
57 int width = 800, int height = 600,
58 int aspectRatioNumer = 0, int aspectRatioDenom = 0
59 ) {
60 auto openGLDevice = std::make_unique<helios::ext::opengl::rendering::OpenGLDevice>(
61 std::make_unique<helios::ext::opengl::rendering::OpenGLMeshRenderer>(),
62 std::make_unique<helios::ext::opengl::rendering::OpenGLGlyphTextRenderer>(),
63 std::make_unique<helios::ext::opengl::rendering::FreeTypeFontResourceManager>()
64 );
65 auto deadzoneStrategy = std::make_unique<helios::input::gamepad::RadialDeadzoneStrategy>();
66 auto inputManager = std::make_unique<helios::input::InputManager>(
67 std::make_unique<helios::ext::glfw::input::GLFWInputAdapter>(std::move(deadzoneStrategy))
68 );
69 auto eventManager = std::make_unique<helios::event::BasicEventManager>(
70 std::make_unique<helios::event::DequeEventQueue>(),
71 std::make_unique<helios::event::Dispatcher>()
72 );
73
74 std::unique_ptr<GLFWApplication> app = std::make_unique<GLFWApplication>(
75 std::move(openGLDevice),
76 std::move(inputManager),
77 std::move(eventManager)
78 );
79
80 app->init();
81 auto cfg = makeWindowCfg(
82 std::move(title),
83 width,
84 height,
85 aspectRatioNumer,
86 aspectRatioDenom
87 );
88 auto renderTarget = std::make_unique<helios::rendering::RenderTarget>();
89
90 helios::ext::glfw::window::GLFWWindow& win = app->createWindow(std::move(renderTarget), cfg);
91 app->addController(std::make_unique<helios::app::controller::BasicWindowRenderingController>(win));
92
93 // set the window user pointer so the frameBufferSizeCallback does not break
94 win.setWindowUserPointer(std::make_unique<helios::ext::glfw::window::GLFWWindowUserPointer>(
95 app.get(),
96 &win
97 ));
98
99 app->setCurrent(win);
100
101 return std::move(app);
102 }

References makeWindowCfg and helios::ext::glfw::window::GLFWWindow::setWindowUserPointer.

makeWindowCfg()

helios::ext::glfw::window::GLFWWindowConfig helios::ext::glfw::app::GLFWFactory::makeWindowCfg (std::string title, int width=800, int height=600, int aspectRatioNumer=0, int aspectRatioDenom=0)
inline static

Creates a default `GLFWWindowConfig` with the specific title.

This method also makes sure that a proper frameBufferSizeCallback is configured, assuming this config is used with a Window created by an application.

Parameters
title

The title for the window configuration.

width

The width for the main window.

height

The height for the main window.

aspectRatioNumer

Aspect ratio numerator.

aspectRatioDenom

Aspect ratio denominator.

Returns

A `GLFWWindowConfig` object with default properties like height and width.

Definition at line 119 of file GLFWFactory.ixx.

120 std::string title, int width = 800, int height = 600,
121 int aspectRatioNumer = 0, int aspectRatioDenom = 0
122 ) {
124 cfg.title = std::move(title);
125 cfg.width = width;
126 cfg.height = height;
127 cfg.aspectRatioNumer = aspectRatioNumer;
128 cfg.aspectRatioDenom = aspectRatioDenom;
129
130 cfg.frameBufferSizeCallback = [] (GLFWwindow* nativeWin, const int width, const int height) {
131 static const auto evtGuid = helios::util::Guid::generate();
132
133 if (const auto* ptr = static_cast<helios::ext::glfw::window::GLFWWindowUserPointer*>(glfwGetWindowUserPointer(nativeWin))) {
134 auto event = std::make_unique<helios::window::event::FrameBufferResizeEvent>(
135 ptr->window->guid(), width, height,
136 // we will use the window's guid as the tag
137 ptr->window->guid().value()
138 );
139 ptr->application->eventManager().post(
140 std::move(event),
142 );
143 }
144 };
145
146 return cfg;
147 }

References helios::util::Guid::generate, helios::event::LATEST_WINS and helios::window::WindowConfig::title.

Referenced by makeOpenGLApp.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.