Commit Graph

27 Commits

Author SHA1 Message Date
portersky 5ec8cfc735 feat: add gfx pipeline abstraction with render targets
Add cbt/gfx layer (pipeline + render_target) inspired by Sokol but
C++-friendly with RAII and pipeline_desc. Supports building full
graphics pipelines (VS/IA/raster/PS/OM), render-to-texture (FBO),
and post-processing steps (scene -> RT -> fullscreen quad with
sampler + vignette).

- Depth/state/viewport/texture cleanup for reliable scene switching.
- Updated cube/sphere to demonstrate (sphere uses RT+post).
- Vulkan backend easy via PIMPL in impl (same public API).
- Fixed depth test, viewport restore, and state leakage on switch.

Followed coding conventions (snake_case, trailing returns, east const,
include order, no ; after ns/class, etc.).
2026-05-06 00:43:00 +02:00
portersky 98673b57ff docs: update README and AGENTS.md to match current project
Updated project description from 'cube timer' to 'OpenGL 3D
renderer with multiple scenes'. Added usage section with CLI
flags and key bindings. Listed both available scenes.

Updated AGENTS.md to include the sphere scene in static
libraries and source layout. Normalized run command to
./build/cuber for cross-platform consistency.
2026-05-06 00:15:43 +02:00
portersky a4ef4adfc7 feat: add window resize support
Added width/height tracking to the window class via a GLFW
resize callback. The callback stores the current size and
forwards it to a user-provided std::function.

Added context::set_size() to update the GL viewport when
the window is resized.

Changed scene::render() to accept (int width, int height)
parameters so scenes can compute the correct aspect ratio
for their projection matrix instead of hardcoding 1280/720.

Fixed parameter shadowing in resize_callback_impl
(glfw_window instead of window).
2026-05-06 00:06:59 +02:00
portersky 91fe3c6e8c style: color-code sphere faces to visualize seams
Each of the 6 cube-to-sphere faces now has a distinct color
(red, green, blue, yellow, magenta, cyan) passed via a
vertex color attribute. The fragment shader multiplies
lighting by this color instead of a uniform blue.

This makes the cube-face seams clearly visible when
inspecting the mapped sphere.
2026-05-06 00:01:17 +02:00
portersky 6f696d377b feat: add --scene and --screenshot CLI flags
Added --scene <cube|sphere> to select the initial scene from
the command line (useful for headless/CI testing where key
presses aren't possible).

Added --screenshot to render a single frame, save a PNG,
and exit immediately. Combined with --duration or used
alone, this allows fully automated screenshot capture
without relying on interactive key presses.

Updated help text to reflect new options.
2026-05-05 23:59:54 +02:00
portersky 78d0515e8b feat: add sphere scene with fixed cube-to-sphere mapping
Added scenes/sphere.{hpp,cpp} using the cube-to-sphere
approach from nrz.cpp, but with corrected math: vertices
are simply normalized to project onto the unit sphere
(the original used a broken formula with p=50.0 as an
exponent).

The sphere uses indexed geometry with position, normal,
and UV attributes, plus a simple diffuse lighting shader.

Press 1/2 to switch between cube and sphere scenes.
Updated .gitignore to exclude generated PNG screenshots.
2026-05-05 23:54:48 +02:00
portersky 4a88c8cc06 feat: add stb dependency and window::screenshot()
Added deps/Findstb.cmake (fetches stb via FetchContent, provides
stb::stb interface target).

Linked to cbt_opengl. Implemented window::screenshot() using
glReadPixels + vertical flip + stb_image_write to save RGBA PNG.

Press S in the app to capture current frame (saved as
screenshot.png). Updated help text.

(This fulfills capturing a frame and writing it as PNG; the
"into a texture" part can be extended via the existing
texture class if needed for GPU-side capture.)
2026-05-05 23:48:05 +02:00
portersky c3860cc1d3 refactor: add window::stop() and remove quit flag
Added `window::stop()` (sets GLFW close flag). Updated
signal/timer handlers and Q key check to call it instead of
using a separate `quit` bool in main().

This encapsulates the close state in the window class (no
more external flag + manual checks). The render loop is now
simpler.

(The process_signals lambda and ASIO duration timer are
retained.)
2026-05-05 23:45:46 +02:00
portersky 3f78d0978d feat: add CLI argument parser with ASIO duration timer
Adds support for `--duration <seconds>` (and `--help`) to
automatically terminate after a set time. Useful for testing,
CI, and agent runs where the default infinite loop is
problematic.

Uses `asio::steady_timer` + `async_wait` for the timeout
(unified with the existing signal handling under one
io_context). The `process_signals` lambda was restored as it
looks nicer.

Combines what were 4 incremental commits into one (the
separate window refactor from earlier remains). Updated
cuber.cpp and includes.
2026-05-05 23:43:33 +02:00
portersky 22d2bb1c40 refactor: separate window from opengl::context
Extract GLFW window management into a dedicated cbt::window
class (new files in cbt/). The opengl::context now only
handles GLAD setup and context activation (no more window
creation or GLFW init/terminate).

Updated main loop in cuber.cpp, CMakeLists.txt (to build
the new source), and AGENTS.md (docs + source layout).

Addresses the design note in context.cpp about mixing
concerns.
2026-05-05 23:37:19 +02:00
portersky 7a81b30d32 feat: enable Windows dark mode for GLFW window
- Add DwmSetWindowAttribute call for immersive dark mode
- Include glfw3native.h after glfw3.h on Windows
2026-05-05 22:52:24 +02:00
portersky 40ae94788e style: fix include ordering across all source files
- C++ std headers first, then third-party, then local
- Apply consistently in cbt/ and scenes/
2026-05-05 22:40:51 +02:00
portersky 0c8af1dc0f docs: update AGENTS.md to reflect current project structure
- Update source layout with scenes/ directory and static libraries
- Add static library documentation (cbt_opengl, cbt_scene, scenes_cube)
- Remove stale references to nerv project
- Update run command for Windows
2026-05-05 22:35:17 +02:00
portersky b6adb7c23a style: move public members first in class declarations
- Reorder all class headers to put public interface before private members
- Document convention in AGENTS.md
2026-05-05 22:30:56 +02:00
portersky e71c4d55cf refactor: split into static libraries and restructure scenes
- Create cbt_opengl static library for OpenGL abstraction
- Create cbt_scene static library for base scene class
- Create scenes_cube static library for cube scene
- Move scene base to cbt/ (utility), scenes to root scenes/
- Link libraries in dependency chain: cuber -> scenes -> cbt_scene -> cbt_opengl
2026-05-05 22:27:19 +02:00
portersky 30ddaf7d39 feat: render spinning 3D cube with glm
- Add glm dependency for matrix transformations
- Replace triangle with 6-face colored cube
- Add MVP shader uniforms (model, view, projection)
- Enable depth testing for proper 3D rendering
- Spin cube around (1, 0.5, 0.3) axis

style: fix trailing return type for move assignment operators

- buffer/texture/shader/vao: use auto fn() -> T& style
- Document trailing return type convention in AGENTS.md
2026-05-05 22:19:33 +02:00
portersky 9114eaabc6 style: switch to east const across the codebase
- const T* -> T const* in all headers and implementations
- const T& -> T const& for copy constructor/operator= deletes
- update AGENTS.md to document east const convention
2026-05-05 22:10:00 +02:00
portersky 3f098faa88 chore: integrate Platform.cmake and Flags.cmake into build
- Add platform/compiler detection via Platform.cmake
- Apply warning flags (-Wall -Wextra -Werror) via Flags.cmake
- Link platform-specific libraries (OpenGL32, winmm, dwmapi)
2026-05-05 22:07:50 +02:00
portersky df08210f77 feat: render per-vertex color triangle
- Add shader class for vertex/fragment program compilation
- Add vao class for vertex array object management
- Render RGB gradient triangle with interpolated vertex colors
2026-05-05 22:05:40 +02:00
portersky 90d013695d feat: add OpenGL abstraction layer with RAII resources
- Replace window class with cbt::opengl::context
- Add buffer resource (VBO, EBO, UBO, SSBO) with move semantics
- Add texture resource with format/type enums and filtering
- Add descriptor_set for Vulkan-style resource binding
- All resources use RAII with proper cleanup
2026-05-05 21:58:34 +02:00
portersky f18e5e4adc feat: add ASIO signal handling for graceful shutdown
- Add asio dependency for async signal handling
- Register SIGINT and SIGTERM to quit the application
- Poll signals each frame for non-blocking shutdown
- Q key and Ctrl+C both cleanly exit the program
2026-05-05 21:53:51 +02:00
portersky 47d01f57c0 feat: add RAII window class with OpenGL 4.1 context
- Add cbt::window class in cbt/ directory with RAII lifecycle
- Add setup_opengl and info_opengl for glad init and GL info
- Add Q key to quit the application
- Update CMakeLists.txt with glfw3 and glad dependencies
- Update AGENTS.md with snake_case naming and shell conventions
2026-05-05 21:50:50 +02:00
portersky f13eb491d9 docs: add commit message conventions with 50/72 rule 2026-05-05 21:36:24 +02:00
portersky c7704f42f7 chore: expand .gitignore with common build/IDE artifacts 2026-05-05 21:35:27 +02:00
portersky 237f446c6e feat: implement stopwatch timer
Replace Hello World with a live stopwatch that prints elapsed time
in HH:MM:SS.mmm format, updating every 10ms with color output.
2026-05-05 21:34:00 +02:00
portersky a13105a591 docs: add coding and shell conventions to AGENTS.md
- Add include ordering rules: C++ std, C std, OS-specific,
  third-party, local headers (separated by blank lines)
- Clarify <> for system headers, "" for third-party deps
- Remove .exe from run command
- Mark shell code blocks as sh (POSIX compliant)
- Add shell script conventions section
2026-05-05 21:34:00 +02:00
portersky e2110ddf4f Inital commit 2026-05-05 21:34:00 +02:00