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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* ============================================================
* FILE: render.c
*
* PURPOSE: Draws the whole scene with modern OpenGL 3.3 core and as little
* code as possible: a ground grid, the player as a box, and the
* player's drop shadow.
*
* FITS IN: Implements render.h. Reads Camera (camera.h), Player (player.h)
* and world_half_extent()/world_ground_height() (world.h). Uses the
* GL functions that window.c loaded through GLEW.
*
* IMPLEMENT:
* - ONE shader program, source written as string literals in this file
* (no shader files to load):
* vertex: in vec3 a_pos; uniform mat4 u_mvp; gl_Position = u_mvp * vec4(a_pos,1)
* fragment: uniform vec4 u_color; out vec4 frag; frag = u_color
* Add a static helper that compiles a shader and prints the info log
* on failure. Look up the uniform locations once in render_init.
*
* - Three meshes, each a VAO + VBO built once in render_init:
* 1. Ground grid: GL_LINES in the XZ plane at y = 0, one line every
* GRID_SPACING from -world_half_extent() to +world_half_extent(), in
* both directions. Put "major" lines (every GRID_MAJOR_EVERY-th) in a
* SEPARATE draw range so they can get a brighter color. The grid is
* what makes motion readable in a blank world, so explain that in a comment.
* 2. Unit cube: 36 vertices (GL_TRIANGLES), spanning x,z in [-0.5, 0.5]
* and y in [0, 1] so its origin is at the BOTTOM center, matching
* Body.pos being the feet.
* 3. Shadow disc: a GL_TRIANGLE_FAN circle of radius 1 in the XZ plane
* (~24 segments).
*
* - render_frame(cam, player, aspect):
* 1. glClearColor(SKY_COLOR_R/G/B), clear color + depth.
* 2. vp = camera_projection(cam, aspect) * camera_view(cam).
* 3. Grid: u_mvp = vp. Draw minor lines in a dim color, major lines brighter.
* 4. Shadow (drawn BEFORE the player):
* model = translate(player x, ground_y + 0.01, player z) * scale(r, 1, r)
* with r around PLAYER_HALF_WIDTH * 1.2. Dark color. The +0.01 lift
* stops z-fighting with the ground. Comment WHY the shadow exists:
* in SM64 the blob under Mario is the main cue for where you'll land.
* Without it, jumps in 3D are very hard to judge.
* ground_y = world_ground_height(player x, player z).
* 5. Player box:
* model = translate(body.pos) * rotate_y(facing_yaw)
* * scale(2*PLAYER_HALF_WIDTH, PLAYER_HEIGHT, 2*PLAYER_HALF_WIDTH)
* Bright color (e.g. red). Also draw a small second box as a "nose" on
* the front face (+Z in model space) so the facing direction is visible.
* That makes the turn rate tunable by eye.
* Everything uses the one shader, changing only u_mvp and u_color.
*
* - render_shutdown: delete the VAOs, VBOs and the program.
*
* CONVENTIONS: `s_` statics for GL handles. Model matrices built from
* math3d.h helpers. There's no lighting, so flat colors are fine.
*
* NOT IN SCOPE: Lighting, textures, models, text/HUD, anti-aliasing,
* interpolating between ticks (a README roadmap item).
*
* DONE WHEN: The scene shows a sky-colored background, a grid ground plane
* stretching to the world edge, a box with a visible nose that faces
* where it runs, and a shadow that stays on the ground under the
* box during a jump.
* ============================================================
*/
|