Skip to content

Retro Render Path

The retro path owns the bonus output image and the minimap image used during bonus rendering. In the current code, world-space content is redirected into app->bonus.retro.out, which is window-sized, then the HUD is drawn last so it stays readable.

Retro render path

Bonus world output with sharp final HUD overlay

The bonus retro path redirects world drawing into the window-sized bonus output image, keeps a dedicated minimap buffer, then draws the HUD after the world pass so UI remains readable.

retro_begin save frame and swap app->frame to out
world render background, raycast, sprites, minimap write into out
retro_render restore the original frame descriptor
HUD draw overlay is drawn after the world pass
mlx_put_image present retro.out when active
01
app->bonus.retro

Retro mode owns three MLX images and lightweight control state.

fb win_w x win_h allocated retro framebuffer / helper source
out win_w x win_h active bonus world output image
minimap radius/tile derived dedicated minimap image buffer
02
retro_begin(app, &saved_frame)

World code stays unchanged because only the active frame target changes.

saved_frame = app->frame;
app->frame = app->bonus.retro.out;

// background, DDA walls, sprites, minimap
// now write into the bonus output image
03
retro_upscale_to_out(app)

Nearest-neighbor mapping exists as a helper; the normal frame path currently renders directly into out.

src_x = x * fb.width  / out.width;
src_y = y * fb.height / out.height;

color = retro_get_pixel(fb, src_x, src_y);
put_pixel(out, x, y, color);
resolution visualizer

Compare the optional helper framebuffer with the window-sized output and final HUD overlay.

8x blocky
fb
out

HUD is drawn after the world pass.

safety and degradation

Retro mode is optional: failed allocations disable it instead of crashing runtime.

enabled flag checkedimage pointers validaddresses availabledimensions positivefallback to direct frame path
advantages

strong retro visual identity, lower world render cost, sharp HUD separation

tradeoffs

intentional pixelation, reduced world detail, extra image buffers

Retro state is stored in app->bonus.retro and contains:

  • fb, an allocated framebuffer kept by the retro context
  • out, the active window-sized bonus output image
  • minimap, the dedicated minimap image buffer
  • enabled, the runtime flag that activates or disables the path
  • minimap_zoom, the runtime zoom value used by minimap rendering

retro_init(app) resets retro images, allocates fb, allocates out, allocates the minimap image, and enables the path only when every required buffer is valid. Both fb and out are currently allocated with the active window dimensions.

If allocation fails, retro mode is disabled and the application continues on the normal frame path. This keeps the feature optional and safe under partial resource failure.

retro_begin(app, &saved_frame) saves the current window-sized frame descriptor and replaces app->frame with app->bonus.retro.out. The existing world pipeline then writes into the bonus output image without needing separate raycasting logic.

retro_render(app, &saved_frame) restores the original frame descriptor. The frame end then presents app->bonus.retro.out through mlx_put_image_to_window when retro mode is active.

HUD drawing happens after retro world handling so UI stays readable and is not mixed into the world pass.

retro_upscale_to_out(app) still exists in srcs_bonus/retro/display.c as a nearest-neighbor helper:

  • src_x = x * fb.width / out.width
  • src_y = y * fb.height / out.height
  • read the source color from fb
  • write it into out

The normal draw_frame() path does not currently call this helper, because the active bonus output already uses the window dimensions.

Retro rendering is guarded by readiness checks: image pointers, addresses, dimensions, and the enabled flag must be valid. On shutdown, retro_shutdown(app) destroys fb, out, and the minimap image, resets image state, and disables the path.

  • srcs_bonus/retro/api.c
  • srcs_bonus/retro/image.c
  • srcs_bonus/retro/display.c
  • srcs_bonus/retro/minimap.c
  • srcs_bonus/retro/minimap_pixels.c
  • srcs/render/render_frame.c
  • include/defines_bonus.h