1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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.
* ============================================================
*/
|