diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-02 09:19:17 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-02 09:19:17 +0100 |
| commit | 0b0067cb0a8db5ea5178501a12aacdef436a9845 (patch) | |
| tree | 362322b45ffde32346351dfa0710d3a470dd6e88 | |
| parent | 275fe655fd7272edd9fa49439d47f449231ce445 (diff) | |
feat(platform): Fix high-DPI scaling and add resolution option
- Fixed a 'squished' viewport bug on high-DPI (Retina) displays by querying the framebuffer size in pixels instead of using the window size in points.
- Centralized window dimension management within the platform layer.
- Added a '--resolution WxH' command-line option to allow specifying a custom window size at startup. This option is stripped in STRIP_ALL builds.
- Updated all test and tool executables to use the new platform API.
| -rw-r--r-- | git_setup_summary.txt | 148 | ||||
| -rw-r--r-- | src/main.cc | 21 | ||||
| -rw-r--r-- | src/platform.cc | 44 | ||||
| -rw-r--r-- | src/platform.h | 10 | ||||
| -rw-r--r-- | src/tests/test_3d_render.cc | 9 | ||||
| -rw-r--r-- | tools/spectool.cc | 2 |
6 files changed, 218 insertions, 16 deletions
diff --git a/git_setup_summary.txt b/git_setup_summary.txt new file mode 100644 index 0000000..dd4edad --- /dev/null +++ b/git_setup_summary.txt @@ -0,0 +1,148 @@ +GIT REPOSITORY SETUP SUMMARY +=========================== + +OVERVIEW +-------- +You have a local bare repository (demo.git) as the source of truth, mirrored on a VPS. +Users can clone from the VPS and push/pull changes to stay synchronized. + +Branch: main (not master) + + +INITIAL VPS SETUP (done once) +----------------------------- + +SSH into VPS as ubuntu user: + ssh ubuntu@your_vps_ip + +Create bare repository as git user: + sudo su - git + mkdir -p /home/git + cd /home/git + git init --bare demo.git + +The bare repository is ready to receive pushes. + + +YOUR LAPTOP CONFIGURATION +------------------------- + +Working directory: /home/me/demo +Bare repository: /home/me/demo.git + +Set up dual remotes to push to both local and VPS: + + cd /home/me/demo + git remote set-url origin /home/me/demo.git + git remote add vps ssh://git@your_vps_ip/~/demo.git + git remote set-url --add --push origin /home/me/demo.git + git remote set-url --add --push origin ssh://git@your_vps_ip/~/demo.git + +First sync (push all branches and tags): + git push -u origin --all + git push -u origin --tags + +Verify configuration: + git remote -v + +When you push, both repositories are updated: + git push origin main + + +USER ACCESS SETUP (per user) +---------------------------- + +One-time setup for each user: + +1. User generates SSH key (if they don't have one): + ssh-keygen -t ed25519 -C "their_email@example.com" + (accept defaults) + +2. User sends you their public key (~/.ssh/id_ed25519.pub) + +3. You add their key to the git user on VPS: + ssh ubuntu@your_vps_ip + sudo su - git + cat >> ~/.ssh/authorized_keys + (paste their public key, then Ctrl+D) + + +CLONING FROM VPS +---------------- + +Users clone with: + git clone ssh://git@your_vps_ip/~/demo.git + +This automatically sets up 'origin' remote pointing to the VPS repository. + +Verify: + git remote -v + + +PUSHING CHANGES +--------------- + +Users push to VPS with: + git push origin main + +This updates the VPS repository, which you can then pull from your laptop. + + +PULLING CHANGES +--------------- + +If user1 pushed to VPS and user2 wants to get their changes: + +User2 pulls from VPS: + git pull vps main + +If user2 also has a local bare repo, they can then sync it: + git push origin main + + +YOUR LAPTOP - PULLING USER CHANGES +---------------------------------- + +When users push to the VPS, pull those changes to your laptop: + git pull vps main + +Then push to your local bare repo: + git push origin main + + +PATHS EXPLAINED +--------------- + +/home/me/demo.git - Your local bare repository (source of truth) +/home/me/demo - Your local working directory +ssh://git@your_vps_ip/~/demo.git - Remote VPS repository + +The ~/demo.git path expands to /home/git/demo.git but hides the full path. + + +SUMMARY OF WORKFLOWS +-------------------- + +YOUR LAPTOP: + git push origin main (pushes to both local demo.git and VPS) + git pull vps main (pulls changes pushed by other users to VPS) + +USER CLONING: + git clone ssh://git@your_vps_ip/~/demo.git + +USER PUSHING: + git push origin main (pushes to VPS) + +USER PULLING: + git pull origin main (pulls from VPS) + OR + git pull vps main (if they have dual origins like you do) + + +KEY POINTS +---------- +- Main branch is 'main' (default since Git 2.28) +- SSH key authentication: secure and requires minimal setup +- VPS path is hidden using ~/ syntax +- Users need SSH keys added to ~/.ssh/authorized_keys on VPS +- All pushes and pulls use SSH (ssh://git@your_vps_ip/~/demo.git) diff --git a/src/main.cc b/src/main.cc index 8cedfce..f7136ef 100644 --- a/src/main.cc +++ b/src/main.cc @@ -130,7 +130,10 @@ float* generate_tone(float* buffer, float freq) { int main(int argc, char** argv) { bool fullscreen_enabled = false; - double seek_time = 0.0; + float seek_time = 0.0f; + int* width_ptr = nullptr; + int* height_ptr = nullptr; + int custom_width, custom_height; #if !defined(STRIP_ALL) for (int i = 1; i < argc; ++i) { @@ -139,6 +142,12 @@ int main(int argc, char** argv) { } else if (strcmp(argv[i], "--seek") == 0 && i + 1 < argc) { seek_time = atof(argv[i + 1]); ++i; + } else if (strcmp(argv[i], "--resolution") == 0 && i + 1 < argc) { + const char* res_str = argv[++i]; + if (sscanf(res_str, "%dx%d", &custom_width, &custom_height) == 2) { + width_ptr = &custom_width; + height_ptr = &custom_height; + } } } #else @@ -147,10 +156,8 @@ int main(int argc, char** argv) { fullscreen_enabled = true; #endif /* STRIP_ALL */ - platform_init_window(fullscreen_enabled); - int width, height; - glfwGetFramebufferSize(platform_get_window(), &width, &height); - gpu_init(platform_get_window(), width, height); + platform_init_window(fullscreen_enabled, width_ptr, height_ptr); + gpu_init(platform_get_window(), platform_get_width(), platform_get_height()); audio_init(); // Register drum assets @@ -234,9 +241,7 @@ int main(int argc, char** argv) { update_game_logic(current_time); - int width, height; - glfwGetFramebufferSize(platform_get_window(), &width, &height); - float aspect_ratio = (float)width / (float)height; + float aspect_ratio = platform_get_aspect_ratio(); // Adjusted multiplier for visuals (preventing constant 1.0 saturation) float raw_peak = synth_get_output_peak(); diff --git a/src/platform.cc b/src/platform.cc index ff45964..464003f 100644 --- a/src/platform.cc +++ b/src/platform.cc @@ -11,6 +11,22 @@ static GLFWwindow* window = nullptr; static int windowed_x, windowed_y, windowed_w, windowed_h; static bool g_is_fullscreen = false; +// --- New state for framebuffer size --- +static int g_width = 1280; +static int g_height = 720; + +// Forward declaration for callback +void platform_toggle_fullscreen(); + +// --- Callbacks --- + +static void framebuffer_size_callback(GLFWwindow* cb_window, int width, int height) { + (void)cb_window; // Unused + g_width = width; + g_height = height; + // Note: We would trigger a swap chain resize here, but our demo handles it implicitly. +} + static void glfw_key_callback(GLFWwindow* cb_window, int key, int scancode, int action, int mods) { if (action == GLFW_PRESS) { @@ -22,11 +38,21 @@ static void glfw_key_callback(GLFWwindow* cb_window, int key, int scancode, } } -void platform_init_window(bool fullscreen) { +void platform_init_window(bool fullscreen, int* width_ptr, int* height_ptr) { + if (width_ptr && height_ptr) { + g_width = *width_ptr; + g_height = *height_ptr; + } + glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); - window = glfwCreateWindow(1280, 720, "demo64k", nullptr, nullptr); + window = glfwCreateWindow(g_width, g_height, "demo64k", nullptr, nullptr); + + // Immediately query the actual framebuffer size for high-DPI displays + glfwGetFramebufferSize(window, &g_width, &g_height); + glfwSetKeyCallback(window, glfw_key_callback); + glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); g_is_fullscreen = fullscreen; if (fullscreen) { @@ -78,6 +104,20 @@ double platform_get_time() { return glfwGetTime(); } +// --- New dimension getters --- +int platform_get_width() { + return g_width; +} + +int platform_get_height() { + return g_height; +} + +float platform_get_aspect_ratio() { + if (g_height == 0) return 1.0f; + return (float)g_width / (float)g_height; +} + WGPUSurface platform_create_wgpu_surface(WGPUInstance instance) { return glfwCreateWindowWGPUSurface(instance, window); } diff --git a/src/platform.h b/src/platform.h index 9cfaf00..38a0568 100644 --- a/src/platform.h +++ b/src/platform.h @@ -6,16 +6,20 @@ #include <webgpu.h> +// Forward declare GLFWwindow to avoid including the full header here. struct GLFWwindow; -void platform_init_window(bool fullscreen); +void platform_init_window(bool fullscreen, int* width_ptr, int* height_ptr); void platform_shutdown(); void platform_poll(); bool platform_should_close(); -void platform_toggle_fullscreen(); - GLFWwindow* platform_get_window(); double platform_get_time(); +// Add dimension getters +int platform_get_width(); +int platform_get_height(); +float platform_get_aspect_ratio(); + WGPUSurface platform_create_wgpu_surface(WGPUInstance instance); diff --git a/src/tests/test_3d_render.cc b/src/tests/test_3d_render.cc index e4477a0..0a809c4 100644 --- a/src/tests/test_3d_render.cc +++ b/src/tests/test_3d_render.cc @@ -174,8 +174,13 @@ void gen_periodic_noise(uint8_t* buffer, int w, int h, const float* params, } int main() { - platform_init_window(false); - init_wgpu(); + printf("Running 3D Renderer Test...\n"); + + platform_init_window(false, nullptr, nullptr); + gpu_init(platform_get_window(), platform_get_width(), platform_get_height()); + + // Create Renderer and Scene + Renderer3D renderer; g_renderer.init(g_device, g_queue, g_format); g_renderer.resize(g_width, g_height); diff --git a/tools/spectool.cc b/tools/spectool.cc index 80a970e..dfb00de 100644 --- a/tools/spectool.cc +++ b/tools/spectool.cc @@ -131,7 +131,7 @@ int play_spec(const char* in_path) { fread(spec_data.data(), sizeof(float), spec_data.size(), f_in); fclose(f_in); - platform_init_window(false); + platform_init_window(false, nullptr, nullptr); audio_init(); audio_start(); Spectrogram spec; |
