22d2bb1c40
Extract GLFW window management into a dedicated cbt::window class (new files in cbt/). The opengl::context now only handles GLAD setup and context activation (no more window creation or GLFW init/terminate). Updated main loop in cuber.cpp, CMakeLists.txt (to build the new source), and AGENTS.md (docs + source layout). Addresses the design note in context.cpp about mixing concerns.
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
#include <string_view>
|
|
|
|
#define GLFW_INCLUDE_NONE
|
|
#include "GLFW/glfw3.h"
|
|
|
|
#include "fmt/std.h"
|
|
#include "glad/glad.h"
|
|
|
|
#include "cbt/opengl/context.hpp"
|
|
|
|
namespace cbt::opengl {
|
|
|
|
auto context::setup_gl() -> bool {
|
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
|
fmt::print("Failed to initialize GLAD\n");
|
|
return false;
|
|
}
|
|
print_info();
|
|
return true;
|
|
}
|
|
|
|
auto context::print_info() -> void {
|
|
fmt::print("OpenGL Info:\n");
|
|
fmt::print(" vendor | {}\n", std::string_view(reinterpret_cast<char const*>(glGetString(GL_VENDOR))));
|
|
fmt::print(" renderer| {}\n", std::string_view(reinterpret_cast<char const*>(glGetString(GL_RENDERER))));
|
|
fmt::print(" version | {}\n", std::string_view(reinterpret_cast<char const*>(glGetString(GL_VERSION))));
|
|
fmt::print(" glsl | {}\n", std::string_view(reinterpret_cast<char const*>(glGetString(GL_SHADING_LANGUAGE_VERSION))));
|
|
fmt::print("\n");
|
|
}
|
|
|
|
context::context(window const& win) {
|
|
glfwMakeContextCurrent(win.raw());
|
|
if (!setup_gl()) {
|
|
return;
|
|
}
|
|
m_valid = true;
|
|
}
|
|
|
|
context::~context() {}
|
|
|
|
auto context::valid() const -> bool {
|
|
return m_valid;
|
|
}
|
|
|
|
}
|