summaryrefslogtreecommitdiff
path: root/platformer/src/window.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--platformer/src/window.c44
1 files changed, 44 insertions, 0 deletions
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: <GL/glew.h> BEFORE <GLFW/glfw3.h>.
+ * - 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.
+ * ============================================================
+ */