In my program I've included the header for an external library (GLFW) in my Main class. Everything I need to use that library for can be handled in my main class, with the exception of two sneaky little methods that I need in a separate class.
#include <GLFW/glfw3.h>
#include "graphics/Display.hpp"
int main()
{
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
GLFWwindow* window = glfwCreateWindow(800, 600, "Adventum", nullptr, nullptr);
uint32_t extCount;
const char** extensions = glfwGetRequiredInstanceExtensions(&extCount);
Display* display = new Display();
//@formatter:off
auto terminate = [&](){glfwSetWindowShouldClose(window, true);};
auto surfaceCreation = [&](VkSurfaceKHR* surface){return (glfwCreateWindowSurface(display->instance, window, nullptr, surface));};
//@formatter:on
display->setTerminateFunction(terminate);
display->setSurfaceCreationFunction(surfaceCreation);
display->create(extensions, extCount);
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
}
display->destroy();
delete display;
glfwDestroyWindow(window);
glfwTerminate();
}
This is my main
function. The two functions I need are glfwSetWindowShouldClose
and glfwCreateWindowSurface
with both requiring a reference to variables in main
and would be an additional hurdle on top of including the header in both classes. As you can see I solved this by creating two lambda functions (terminate
and surfaceCreation
) that contain the external function call.
My question is, does this come off as an eyesore to experienced developers? Is this a crude and unnecessary work around? (I'm trying to figure out how to ask this without it being "opinion based".)
display
is not initialized in your code.window
from my main class to the Display class