309. Main uses full framebuffer
Create main.py from main_only_background.py and use Console.render_framebuffer().
Lesson 309 of 356 · tests/chapter_09_sprite_rendering/test_309_main_uses_full_framebuffer.py
Files involved
main_only_background.py
main.pyWhy this step exists
main_only_background.py preserves the previous manual runner that displayed only the background framebuffer. For this step, copy that file to main.py and then apply the full-frame rendering modifications there.
Console now exposes render_framebuffer(), which returns background + sprites in one pure Framebuffer. The new main.py should use that full-frame render path instead of the older background-only helper.
The template file, main_only_background.py, displays:
console.render_background_framebuffer()After copying it to main.py and applying this step, main.py displays:
console.render_framebuffer()This lets the manual pygame runner show sprites such as Mario/enemies/items when the current PPU state contains valid OAM, CHR, and sprite palette data.
Suggested implementation workflow
cp main_only_background.py main.pyThen update main.py so this line:
framebuffer = console.render_background_framebuffer()becomes:
framebuffer = console.render_framebuffer()Do this both before creating the pygame window and after each frame step.
Important preservation rule
Do not delete main_only_background.py. Older tutorial tests use it as a stable historical checkpoint for the background-only runner.
Known visual limitation
Sprites may appear in front of pipes/tubes incorrectly. That is expected for now because sprite/background priority bit 5 is decoded but not applied yet. The next planned work is a background opacity mask and priority-aware composition.
Manual command
uv run python main.pyExpected manual behavior
The pygame window should still show the background, and sprites should now appear. Visual priority may still be wrong. Performance may still be slow because the current pygame drawing helper is intentionally simple.
Out of scope
- background opacity mask
- sprite/background priority behavior
- sprite 0 hit
- sprite overflow
- fast framebuffer upload optimization
- calling main() from pytest
Run this lesson
uv run pytest tests/chapter_09_sprite_rendering/test_309_main_uses_full_framebuffer.py -v