refactor: separate window from opengl::context
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.
This commit is contained in:
@@ -5,11 +5,18 @@
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "asio.hpp"
|
||||
|
||||
#include "cbt/window.hpp"
|
||||
#include "cbt/opengl/context.hpp"
|
||||
#include "scenes/cube.hpp"
|
||||
|
||||
auto main(int, char const*[]) -> int {
|
||||
auto ctx = cbt::opengl::context("cuber", 1280, 720);
|
||||
auto win = cbt::window("cuber", 1280, 720);
|
||||
|
||||
if (!win.valid()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto ctx = cbt::opengl::context(win);
|
||||
|
||||
if (!ctx.valid()) {
|
||||
return 1;
|
||||
@@ -37,10 +44,10 @@ auto main(int, char const*[]) -> int {
|
||||
// render loop
|
||||
auto prev = std::chrono::steady_clock::now();
|
||||
|
||||
while (!ctx.should_close()) {
|
||||
while (!win.should_close()) {
|
||||
process_signals();
|
||||
|
||||
if (quit || glfwGetKey(ctx.raw(), GLFW_KEY_Q) == GLFW_PRESS) {
|
||||
if (quit || glfwGetKey(win.raw(), GLFW_KEY_Q) == GLFW_PRESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -51,8 +58,8 @@ auto main(int, char const*[]) -> int {
|
||||
scn.update(dt);
|
||||
scn.render();
|
||||
|
||||
ctx.swap_buffers();
|
||||
ctx.poll_events();
|
||||
win.swap_buffers();
|
||||
win.poll_events();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user