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.
67 lines
1.3 KiB
C++
67 lines
1.3 KiB
C++
#define GLFW_INCLUDE_NONE
|
|
|
|
#include <csignal>
|
|
|
|
#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 win = cbt::window("cuber", 1280, 720);
|
|
|
|
if (!win.valid()) {
|
|
return 1;
|
|
}
|
|
|
|
auto ctx = cbt::opengl::context(win);
|
|
|
|
if (!ctx.valid()) {
|
|
return 1;
|
|
}
|
|
|
|
auto scn = cbt::scenes::cube();
|
|
if (!scn.init()) {
|
|
return 1;
|
|
}
|
|
|
|
// signal handling
|
|
asio::io_context io;
|
|
asio::signal_set signals(io, SIGINT, SIGTERM);
|
|
bool quit = false;
|
|
|
|
signals.async_wait([&](auto, auto) {
|
|
quit = true;
|
|
io.stop();
|
|
});
|
|
|
|
auto process_signals = [&]() -> void {
|
|
while (io.poll()) {}
|
|
};
|
|
|
|
// render loop
|
|
auto prev = std::chrono::steady_clock::now();
|
|
|
|
while (!win.should_close()) {
|
|
process_signals();
|
|
|
|
if (quit || glfwGetKey(win.raw(), GLFW_KEY_Q) == GLFW_PRESS) {
|
|
break;
|
|
}
|
|
|
|
auto now = std::chrono::steady_clock::now();
|
|
auto dt = std::chrono::duration<float>(now - prev).count();
|
|
prev = now;
|
|
|
|
scn.update(dt);
|
|
scn.render();
|
|
|
|
win.swap_buffers();
|
|
win.poll_events();
|
|
}
|
|
|
|
return 0;
|
|
}
|