{"id":13822374,"url":"https://github.com/QuantumBadger/Speedy2D","last_synced_at":"2025-05-16T15:34:15.770Z","repository":{"id":38027448,"uuid":"342600699","full_name":"QuantumBadger/Speedy2D","owner":"QuantumBadger","description":"Rust library for hardware accelerated drawing of 2D shapes, images, and text, with an easy to use API.","archived":false,"fork":false,"pushed_at":"2024-08-06T08:34:04.000Z","size":1675,"stargazers_count":387,"open_issues_count":49,"forks_count":42,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-11-11T19:11:48.843Z","etag":null,"topics":["graphics","opengl","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/QuantumBadger.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"QuantumBadger"}},"created_at":"2021-02-26T14:29:34.000Z","updated_at":"2024-11-10T22:34:23.000Z","dependencies_parsed_at":"2024-03-25T20:33:53.474Z","dependency_job_id":"b7f091b7-c85a-4981-93b3-bf3d2cd620d0","html_url":"https://github.com/QuantumBadger/Speedy2D","commit_stats":{"total_commits":148,"total_committers":11,"mean_commits":"13.454545454545455","dds":0.08108108108108103,"last_synced_commit":"114358c3ce2436f4f16153bce02e3a89a28d00e3"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuantumBadger%2FSpeedy2D","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuantumBadger%2FSpeedy2D/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuantumBadger%2FSpeedy2D/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuantumBadger%2FSpeedy2D/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/QuantumBadger","download_url":"https://codeload.github.com/QuantumBadger/Speedy2D/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225436686,"owners_count":17474196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphics","opengl","rust"],"created_at":"2024-08-04T08:01:57.511Z","updated_at":"2024-11-19T22:33:05.970Z","avatar_url":"https://github.com/QuantumBadger.png","language":"Rust","funding_links":["https://github.com/sponsors/QuantumBadger"],"categories":["Rust"],"sub_categories":[],"readme":"# Speedy2D\n\n[![Crate](https://img.shields.io/crates/v/speedy2d.svg)](https://crates.io/crates/speedy2d)\n[![Documentation](https://docs.rs/speedy2d/badge.svg)](https://docs.rs/speedy2d)\n[![CI](https://github.com/QuantumBadger/Speedy2D/actions/workflows/build.yml/badge.svg)](hhttps://github.com/QuantumBadger/Speedy2D/actions)\n\nHardware-accelerated drawing of shapes, images, and text, with an easy to\nuse API.\n\nSpeedy2D aims to be:\n\n - The simplest Rust API for creating a window, rendering graphics/text, and\n   handling input\n - Compatible with any device supporting OpenGL 2.0+ or WebGL 2.0. Support for\n   OpenGL ES 2.0+ is planned\n - Very fast\n\nSupports Windows, Mac, Linux, and WebGL. Support for Android and iOS is in\ndevelopment.\n\nBy default, Speedy2D contains support for setting up a window with an OpenGL\ncontext, and receiving input events. If you'd like to handle this yourself, and\nuse Speedy2D only for rendering, you can disable the `windowing` feature.\n\n\n## Useful Links\n\n* Documentation and getting started guide: https://docs.rs/speedy2d\n* Crate: https://crates.io/crates/speedy2d\n\n## Features\n\n|                          | Windows | Mac | Linux | Web        |\n|--------------------------|---------|-----|-------|:-----------|\n| Draw 2D shapes           | ✔️      | ✔️  | ✔️    | ✔️         |\n| Load fonts and draw text | ✔️      | ✔️  | ✔️    | ✔️         |\n| Load and draw images     | ✔️      | ✔️  | ✔️    | ✔️         |\n| Mouse events             | ✔️      | ✔️  | ✔️    | ✔️         |\n| Keyboard events          | ✔️      | ✔️  | ✔️    | ✔️         |\n| Fullscreen               | ✔️      | ✔️  | ✔️    | ✔️         |\n| Window control           | ✔️      | ✔️  | ✔️    | ℹ️ Partial |\n| DPI/scale change events  | ✔️      | ✔️  | ✔️    | ✔️         |\n| System clock/timer       | ✔️      | ✔️  | ✔️    | ✔️         |\n\n## Example code\n\n* [Hello world, with text rendering](examples/hello_world.rs)\n* [Animation](examples/animation.rs)\n* [All input callbacks](examples/input_callbacks.rs)\n* [User-generated events](examples/user_events.rs)\n* [WebGL](examples/webgl) (see the [WebGL](#webgl) section below for details)\n\nThe example projects can be run using `cargo run --example=hello_world` (just\nchange `hello_world` to the name of the example source file).\n\n[![Screenshot](assets/screenshots/hello_world.png)](examples/hello_world.rs)\n\n## Quick Start (Windows/Mac/Linux)\n\n**Step 1:** Add Speedy2D to your `Cargo.toml` dependencies:\n\n```toml\n[dependencies]\nspeedy2d = \"2.1.0\"\n```\n\n**Step 2:** Create a window:\n\n```rust\nuse speedy2d::Window;\n\nlet window = Window::new_centered(\"Title\", (640, 480)).unwrap();\n```\n\n**Step 3:** Create a struct implementing the `WindowHandler` trait. Override\nwhichever callbacks you're interested in, for example `on_draw()`,\n`on_mouse_move()`, or `on_key_down()`.\n\n```rust\nuse speedy2d::color::Color;\nuse speedy2d::window::{WindowHandler, WindowHelper};\nuse speedy2d::Graphics2D;\n\nstruct MyWindowHandler {}\n\nimpl WindowHandler for MyWindowHandler\n{\n    fn on_draw(\u0026mut self, helper: \u0026mut WindowHelper, graphics: \u0026mut Graphics2D)\n    {\n        graphics.clear_screen(Color::from_rgb(0.8, 0.9, 1.0));\n        graphics.draw_circle((100.0, 100.0), 75.0, Color::BLUE);\n\n        // Request that we draw another frame once this one has finished\n        helper.request_redraw();\n    }\n\n   // If desired, on_mouse_move(), on_key_down(), etc...\n}\n```\n\n**Step 4:** Finally, start the event loop by passing your new `WindowHandler`\nto the `run_loop()` function. \n\n```rust\nwindow.run_loop(MyWindowHandler{});\n```\n\n**That's it!**\n\nFor a more detailed getting started guide, including a full list of `WindowHandler`\ncallbacks, and how to render text, go to\n[docs.rs/speedy2d](https://docs.rs/speedy2d).\n\nThe full code of the above example is below for your convenience:\n\n```rust\nuse speedy2d::color::Color;\nuse speedy2d::{Graphics2D, Window};\nuse speedy2d::window::{WindowHandler, WindowHelper};\n\nfn main() {\n    let window = Window::new_centered(\"Title\", (640, 480)).unwrap();\n    window.run_loop(MyWindowHandler{});\n}\n\nstruct MyWindowHandler {}\n\nimpl WindowHandler for MyWindowHandler\n{\n    fn on_draw(\u0026mut self, helper: \u0026mut WindowHelper, graphics: \u0026mut Graphics2D)\n    {\n        graphics.clear_screen(Color::from_rgb(0.8, 0.9, 1.0));\n        graphics.draw_circle((100.0, 100.0), 75.0, Color::BLUE);\n        helper.request_redraw();\n    }\n}\n```\n\n### Alternative: Managing the GL context yourself\n\nIf you'd rather handle the window creation and OpenGL context management\nyourself, simply disable Speedy2D's `windowing` feature in your `Cargo.toml`\nfile, and create a context as follows. You will need to specify a loader\nfunction to allow Speedy2D to obtain the OpenGL function pointers.\n\n```rust\nuse speedy2d::GLRenderer;\n\nlet mut renderer = unsafe {\n    GLRenderer::new_for_gl_context((640, 480), |fn_name| {\n        window_context.get_proc_address(fn_name) as *const _\n    })\n}.unwrap();\n```\n\nThen, draw a frame using `GLRenderer::draw_frame()`:\n\n```rust\nrenderer.draw_frame(|graphics| {\n    graphics.clear_screen(Color::WHITE);\n    graphics.draw_circle((100.0, 100.0), 75.0, Color::BLUE);\n});\n```\n\n## \u003ca name=\"webgl\"\u003e\u003c/a\u003eWebGL\n\n[Full tutorial for using Speedy2D with WebGL](https://quantumbadger.com/2021/12/using-webgl-with-speedy2d.html)\n\nTo use Speedy2D with WebGL, your app must be compiled for WebAssembly.\nSpeedy2D can attach itself to a `canvas` on the page using an ID you\nspecify.\n\nAs with Windows/Mac/Linux targets, it's possible to use Speedy2D either in a\nfull rendering and event handling configuation, or for rendering only.\n\nFor rendering only, use the following API:\n\n* `GLRenderer::new_for_web_canvas_by_id()`\n\nFor full keyboard/mouse/etc event handling in addition to rendering, use:\n\n* `WebCanvas::new_for_id()`\n* `WebCanvas::new_for_id_with_user_events()`\n\nAfter initialization, the usual `WindowHandler` callbacks and\n`WindowHelper`/`Graphics2D` APIs should operate as on other platforms.\n\nFor an example, see the `examples/webgl` directory. To build this, first install\nthe prerequisites:\n\n```shell\ncargo install wasm-bindgen-cli just\n```\n\nThen use the following command to run the build:\n\n```shell\njust build-example-webgl\n```\n\n## License\n\nSpeedy2D is licensed under the Apache license, version 2.0. See\n[LICENSE](LICENSE) for more details.\n\n## Contributing\n\nPull requests for Speedy2D are always welcome. Please ensure the following\nchecks pass locally before submitting.\n\nNote: the automated tests currently only run on Linux.\n\n```shell\ncargo test\ncargo test --no-default-features --lib --examples --tests\ncargo clippy\ncargo +nightly fmt -- --check\ncargo doc\ncargo build --target wasm32-unknown-unknown\ncargo build --target wasm32-unknown-unknown --no-default-features\n```\n\nThese commands can be run automatically using `just`:\n\n```shell\njust precommit\n```\n\nSome tests require the ability to create a headless OpenGL context.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FQuantumBadger%2FSpeedy2D","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FQuantumBadger%2FSpeedy2D","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FQuantumBadger%2FSpeedy2D/lists"}