diff options
| author | Schark <jordan@schark.online> | 2026-09-23 23:09:55 -0400 |
|---|---|---|
| committer | Schark <jordan@schark.online> | 2026-09-23 23:09:55 -0400 |
| commit | dab65412376d1b73381446f969c1461c24169811 (patch) | |
| tree | 27adfec438a9bd9f3c96a740ab54016df5f68b80 /platformer/src/window.c | |
| parent | af03f388cbcff795158ea8345b5c876470229e8b (diff) | |
| download | gamedev-dab65412376d1b73381446f969c1461c24169811.tar.gz gamedev-dab65412376d1b73381446f969c1461c24169811.zip | |
Base prompts
Diffstat (limited to '')
| -rw-r--r-- | platformer/src/window.c | 44 |
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. + * ============================================================ + */ |
