From dab65412376d1b73381446f969c1461c24169811 Mon Sep 17 00:00:00 2001 From: Schark Date: Wed, 23 Sep 2026 23:09:55 -0400 Subject: Base prompts --- platformer/src/window.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 platformer/src/window.c (limited to 'platformer/src/window.c') diff --git a/platformer/src/window.c b/platformer/src/window.c new file mode 100644 index 0000000..455b249 --- /dev/null +++ b/platformer/src/window.c @@ -0,0 +1,44 @@ +/* + * ============================================================ + * FILE: window.c + * + * PURPOSE: Creates and owns the single game window and its OpenGL context. + * This is the ONLY file that calls GLFW window/context functions + * and glewInit. (controls.c calls GLFW input functions.) + * + * FITS IN: main.c calls window_init() first and window_shutdown() last. + * Every frame main.c calls window_poll_events() and window_swap(). + * Implements the interface in window.h. + * + * IMPLEMENT: + * - Private state: `static GLFWwindow *s_window;` + * - Include order matters: BEFORE . + * - window_init(): + * 1. glfwSetErrorCallback -> print GLFW errors to stderr. + * 2. glfwInit(). Note that this also initializes GLFW's joystick/gamepad + * support, which controls.c depends on. + * 3. Hints: GL 3.3, GLFW_OPENGL_CORE_PROFILE, GLFW_OPENGL_FORWARD_COMPAT. + * 4. Create a WINDOW_WIDTH x WINDOW_HEIGHT window titled WINDOW_TITLE + * (config.h), make its context current. + * 5. glewExperimental = GL_TRUE; glewInit(). With a core profile, glewInit + * can leave a harmless GL_INVALID_ENUM behind, so call glGetError() + * once to clear it and add a comment explaining why. + * 6. glfwSwapInterval(1) for vsync. + * 7. Framebuffer-size callback -> glViewport(0, 0, w, h). + * 8. Enable GL_DEPTH_TEST here (it's global GL state set once). + * On any failure: print a clear message, clean up, return false. + * - window_framebuffer_size / window_aspect: use glfwGetFramebufferSize + * (NOT the window size, because they differ on HiDPI displays). Guard against + * height == 0 (minimized window) so the aspect never divides by zero. + * - Everything else is a thin wrapper over the matching glfw* call. + * + * CONVENTIONS: `s_` prefix for file-private statics. Messages go to stderr. + * + * NOT IN SCOPE: Input handling (that's controls.c), drawing (render.c), + * fullscreen, window icons, resizable-minimum-size logic. + * + * DONE WHEN: A window opens at the configured size and title with a + * 3.3 core context, closes cleanly, and resizing it keeps the + * viewport correct. + * ============================================================ + */ -- cgit v1.2.3-18-g5258