Rust library to create a Good Game Easily

Overview

Maintenance

ggez

ggez logo

What is this?

Build Status Build status Docs Status license Crates.io Crates.io

ggez is a Rust library to create a Good Game Easily.

The current version is 0.6.0-rc0. This is a RELEASE CANDIDATE version, which means that the API should be stable but there are still known bugs to address. See the release milestone on the issue tracker for details.

More specifically, ggez is a lightweight cross-platform game framework for making 2D games with minimum friction. It aims to implement an API based on (a Rustified version of) the LÖVE game framework. This means it contains basic and portable 2D drawing, sound, resource loading and event handling, but finer details and performance characteristics may be different than LÖVE.

ggez is not meant to be everything to everyone, but rather a good base upon which to build. Thus it takes a fairly batteries-included approach without needing a million additions and plugins for everything imaginable, but also does not dictate higher-level functionality such as physics engine or entity component system. Instead the goal is to allow you to use whichever libraries you want to provide these functions, or build your own libraries atop ggez.

Features

  • Filesystem abstraction that lets you load resources from folders or zip files
  • Hardware-accelerated 2D rendering built on the gfx-rs graphics engine
  • Loading and playing .ogg, .wav and .flac files via the rodio crate
  • TTF font rendering with rusttype and glyph_brush.
  • Interface for handling keyboard and mouse events easily through callbacks
  • Config file for defining engine and game settings
  • Easy timing and FPS measurement functions.
  • Math library integration with mint.
  • Some more advanced graphics options: shaders, sprite batches and render targets

Supported platforms

  • Fully supported: Windows, Linux
  • Not officially supported but might work anyway: Mac, iOS
  • Work in progress: WebAssembly
  • Not officially supported yet (but maybe you can help!): Android

For details, see docs/BuildingForEveryPlatform.md

Who's using ggez?

Check out the projects list!

Usage

ggez requires rustc >= 1.40 and is distributed on crates.io. To include it in your project, just add the dependency line to your Cargo.toml file:

ggez = "0.6"

ggez consists of three main parts: A Context object which contains all the state required to interface with the computer's hardware, an EventHandler trait that the user implements to register callbacks for events, and various sub-modules such as graphics and audio that provide the functionality to actually get stuff done. The general pattern is to create a struct holding your game's data which implements the EventHandler trait. Create a new Context object with default objects from a ContextBuilder or Conf object, and then call event::run() with the Context and an instance of your EventHandler to run your game's main loop.

See the API docs for full documentation, or the examples directory for a number of commented examples of varying complexity. Most examples show off a single feature of ggez, while astroblasto and snake are small but complete games.

Getting started

For a quick tutorial on ggez, see the Hello ggez guide in the docs/ directory.

Examples

See the examples/ directory in the source. Most examples show off a single feature of ggez, while astroblasto is a small but complete Asteroids-like game.

To run the examples, just check out the source and execute cargo run --example in the root directory:

git clone https://github.com/ggez/ggez.git
cd ggez
cargo run --example 05_astroblasto

If this doesn't work, see the FAQ for solutions to common problems.

Basic Project Template

use ggez::{graphics, Context, ContextBuilder, GameResult};
use ggez::event::{self, EventHandler};

fn main() {
    // Make a Context.
    let (mut ctx, event_loop) = ContextBuilder::new("my_game", "Cool Game Author")
        .build()
        .expect("aieee, could not create ggez context!");

    // Create an instance of your event handler.
    // Usually, you should provide it with the Context object to
    // use when setting your game up.
    let my_game = MyGame::new(&mut ctx);

    // Run!
    event::run(ctx, event_loop, my_game);
}

struct MyGame {
    // Your state here...
}

impl MyGame {
    pub fn new(_ctx: &mut Context) -> MyGame {
        // Load/create resources such as images here.
        MyGame {
            // ...
        }
    }
}

impl EventHandler for MyGame {
    fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
        // Update code here...
        Ok(())
    }

    fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
        graphics::clear(ctx, graphics::WHITE);
        // Draw code here...
        graphics::present(ctx)
    }
}

Implementation details

ggez is built upon winit for windowing and events, rodio for sound, and a 2D drawing engine implemented in gfx using the OpenGL backend (which currently defaults to use OpenGL 3.2). It is entirely thread-safe (though platform constraints mean the event-handling loop and drawing must be done in the main thread), and portable to Windows and Linux.

ggez is Pure Rust(tm).

Help!

Sources of information:

  • The FAQ has answers to common questions and problems.
  • The API docs, a lot of design stuff is explained there.
  • Check out the examples.

If you still have problems or questions, feel free to ask! Easiest ways are:

License: MIT

Comments
  • WGPU refactor

    WGPU refactor

    • Closes #1012
    • Closes #962
    • Closes #562
    • Closes #1007
    • Closes #989
    • Closes #951
    • Closes #1003
    • Closes #751
    • Closes #594
    • Closes #441 Possibly also https://github.com/ggez/ggez/issues/921, https://github.com/ggez/ggez/issues/560, https://github.com/ggez/ggez/issues/368.
    opened by aleokdev 68
  • Fixes canvas being upside down

    Fixes canvas being upside down

    This seems too obvious considering icefoxen marked it as HARD, does it not work as it should on some platforms? It seems to work for me. closes #693 tested using code below modified from #693

    use ggez::event::{self, EventHandler};
    use ggez::graphics::{self, Canvas, Color, DrawParam, Image};
    use ggez::Context;
    use ggez::ContextBuilder;
    use ggez::GameResult;
    use ggez::{conf::Conf, graphics::Drawable};
    use glam::vec2;
    
    struct Application {
        dark_image: Image,
        dark_canvas: Canvas,
        canvas_image: Image,
    }
    
    impl Application {
        fn new(ctx: &mut Context) -> Self {
            let (dark_image, dark_canvas) = Self::image_canvas(ctx, "/download.png");
    
            let canvas_image = Self::canvas(ctx, &dark_image).into_inner();
    
            Self {
                dark_image,
                dark_canvas,
                canvas_image,
            }
        }
    
        fn image_canvas(ctx: &mut Context, file: &str) -> (Image, Canvas) {
            let image = Image::new(ctx, file).unwrap();
            let canvas = Self::canvas(ctx, &image);
            (image, canvas)
        }
    
        fn canvas(ctx: &mut Context, image: &Image) -> Canvas {
            let canvas = Canvas::with_window_size(ctx).unwrap();
            graphics::set_canvas(ctx, Some(&canvas));
            graphics::draw(ctx, image, DrawParam::new()).unwrap();
            graphics::set_canvas(ctx, None);
    
            canvas
        }
    }
    
    impl EventHandler for Application {
        fn update(&mut self, _: &mut Context) -> GameResult<()> {
            Ok(())
        }
    
        fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
            graphics::clear(
                ctx,
                Color {
                    r: 0.,
                    g: 0.3,
                    b: 0.,
                    a: 1.,
                },
            );
    
            graphics::draw(ctx, &self.dark_image, DrawParam::new()).unwrap();
            graphics::draw(ctx, &self.canvas_image, DrawParam::new().dest([400.0, 0.0])).unwrap();
    
            graphics::present(ctx).unwrap();
            Ok(())
        }
    }
    
    pub fn main() {
        let (mut ctx, event_loop) = ContextBuilder::new("canvas", "athorus").build().unwrap();
        let app = Application::new(&mut ctx);
        event::run(ctx, event_loop, app);
    }
    
    opened by nobbele 58
  • ggez doesn't work with optimus (`optirun`)

    ggez doesn't work with optimus (`optirun`)

    Describe the bug Ggez seems to not work on optimus systems on discrete GPU. Program fails on call ContextBuilder::build (NOTE: build don't return error, program just fails)

    To Reproduce

    1. create a simple project with this in main.rs:
    fn main() {
        let cb = ggez::ContextBuilder::new("ggez_optimus", "Waffle");
        println!("before build");
        cb.build().unwrap();
        println!("after build");
    }
    
    1. build it: cargo build
    2. run it with optirun: optirun -v target/debug/ggez_optimus the output will be like that:
    [28698.115643] [INFO]Response: Yes. X is active.
    
    [28698.115677] [INFO]Running application using virtualgl.
    before build
    

    Hardware and Software:

    • ggez version: 0.5.0-rc.2
    • OS: Arch Linux
    • Graphics card: GeForce MX150 and Mesa DRI Intel(R) UHD Graphics 620 (Kabylake GT2) I guess
    • Graphics card drivers: nvidia / Mesa
    Type-CODE *HARD* dependency bug 
    opened by WaffleLapkin 57
  • Looking for maintainer

    Looking for maintainer

    Been thinking about this for a while, but it's time for me to officially step down from maintaining ggez. It's been a rough year, work is probably going to consume even more of my time and energy in 2021, and I really want to be able to move on to spending time on other projects. Maybe even make a game for once!

    So it's been a good ride, but when you spend multiple months actively avoiding looking at github issues, it's time to step down. I wouldn't trade this for the world, but I've been doing it for over four years now, so it's time to move on. So after the 0.6.0 release any active development, responses to issues or pull requests will be on a 100% "if I feel like it" basis with no commitments. I'll probably honestly stop following the issue tracker.

    If anyone wants to step up and take over maintainership of ggez, reply here and we'll talk.

    *HARD* 
    opened by icefoxen 52
  • WindowError(SdlError(

    WindowError(SdlError("Could not create GL context"))

    I compiled this code (the example from the website),

    extern crate ggez;
    use ggez::conf;
    use ggez::event;
    use ggez::{GameResult, Context};
    use ggez::graphics;
    use ggez::graphics::{Color, DrawMode, Point};
    use std::time::Duration;
    
    struct MainState {
        pos_x: f32,
    }
    
    impl MainState {
        fn new(ctx: &mut Context) -> GameResult<MainState> {
            let s = MainState { pos_x: 0.0 };
            Ok(s)
        }
    }
    
    impl event::EventHandler for MainState {
        fn update(&mut self, _ctx: &mut Context, _dt: Duration) -> GameResult<()> {
            self.pos_x = self.pos_x % 800.0 + 1.0;
            Ok(())
        }
    
        fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
            graphics::clear(ctx);
            graphics::circle(ctx, DrawMode::Fill, Point { x: self.pos_x, y: 380.0 }, 100.0, 32)?;
            graphics::present(ctx);
            Ok(())
        }
    }
    
    pub fn main() {
        let c = conf::Conf::new();
        let ctx = &mut Context::load_from_conf("super_simple", "ggez", c).unwrap();
        let state = &mut MainState::new(ctx).unwrap();
        event::run(ctx, state).unwrap();
    }
    

    and it compiles fine, but when I try to run it, I get the following error:

    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: WindowError(SdlError("Could not create GL context"))', /checkout/src/libcore/result.rs:906:4
    note: Run with `RUST_BACKTRACE=1` for a backtrace.
    

    I have tried a bunch of different examples and nothing seems to run. This seems to be related to #143 but I'm running on a pretty new machine, specs bellow.

    OS: Arch Linux 
    Kernel: x86_64 Linux 4.13.7-1-ARCH
    WM: i3
    CPU: Intel Core i5-7200U @ 4x 3.1GHz [40.0°C]
    GPU: Mesa DRI Intel(R) HD Graphics 620 (Kaby Lake GT2) 
    RAM: 2119MiB / 7856MiB
    
    bug Type-DOCS driver bug 
    opened by FuzzyLitchi 48
  • Scaling issue when resizing window on macOS

    Scaling issue when resizing window on macOS

    Describe the bug When any ggez program is run and the window is resized the graphics appear incorrectly.

    To Reproduce Run this:

    use ggez::{Context, ContextBuilder, GameResult, graphics};
    use ggez::event::{self, EventHandler};
    use ggez::conf::WindowMode;
    use ggez::graphics::{MeshBuilder, DrawMode, Rect};
    use ggez::mint::Point2;
    
    fn main() {
        let (ctx, event_loop) = &mut ContextBuilder::new("resize_test", "Ray Britton")
            .window_mode(WindowMode {
                resizable: true,
                ..WindowMode::default()
            })
            .build()
            .expect("aieee, could not create ggez context!");
    
        let mut my_game = MyGame {};
    
        match event::run(ctx, event_loop, &mut my_game) {
            Ok(_) => println!("Exited cleanly."),
            Err(e) => println!("Error occured: {}", e)
        }
    }
    
    struct MyGame {}
    
    impl EventHandler for MyGame {
        fn update(&mut self,_ctx: &mut Context) -> GameResult<()> { Ok(()) }
    
        fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
            graphics::clear(ctx, (0.,0.,0.,1.).into());
    
            let mesh = MeshBuilder::new()
                .rectangle(DrawMode::fill(), Rect::new(0.,0.,8.,8.), (1.,1.,1.,1.).into())
                .build(ctx)?;
    
            let size = graphics::window(ctx).get_inner_size().expect("failed to get window size");
            let dpi = graphics::window(ctx).get_hidpi_factor();
    
            let sw = (size.width * dpi) as f32;
            let sh = (size.height * dpi) as f32;
    
            graphics::draw(ctx, &mesh, (Point2 {x: 0., y: 0.},))?;
            graphics::draw(ctx, &mesh, (Point2 {x: sw - 8.,y: sh - 8.},))?;
    
            graphics::present(ctx)?;
    
            Ok(())
        }
    }
    

    and then resize the window

    Expected behavior The boxes should continue to appear in the corners of the window

    Screenshots or pasted code Initial window: initial If made bigger: bigger If made smaller: smaller

    Hardware and Software:

    • ggez version: 0.5.0-rc.2
    • OS: macOS Mojave 10.14.4, 13.3-inch (2560 x 1600) - DPI is 2
    • Graphics card: Intel Iris Plus Graphics 640
    bug Type-CODE 
    opened by emmabritton 44
  • Rewrite renderer to use gfx-hal

    Rewrite renderer to use gfx-hal

    This is something I'm interested in working on. Possible resources to look at:

    • https://github.com/omni-viral/gfx-render
    • https://github.com/omni-viral/gfx-memory
    • https://github.com/omni-viral/gfx-chain
    • https://github.com/omni-viral/gfx-mesh
    • https://github.com/omni-viral/gfx-texture
    enhancement Type-CODE 
    opened by fu5ha 43
  • Vectors should be included in the framework.

    Vectors should be included in the framework.

    They're an extremely basic building block of video games, and almost every project is going to (re)implement them.

    Not including them will only reduce ease of integration between libraries, increase code duplication and the amount of work that has to be done when setting up a project.

    enhancement 
    opened by Asmageddon 33
  • Add

    Add "sprite batching"

    As referenced in #127, I thought I'd open up its own issue as it's something I'd be interested in contributing to, so we can discuss how to do it The Right Way TM :P

    One thing I'd like to know people's thoughts on is if you think it would be good to try to implement generic automatic sprite batching for objects with some set of common characteristics that would lend themselves to be batched or if we want to make the user manually use a SpriteBatch?

    enhancement Type-CODE 
    opened by fu5ha 32
  • canvas image is serialized in to_image before being updated

    canvas image is serialized in to_image before being updated

    Describe the bug Turning an image into a vector and back again appears to clear the image.

    To Reproduce Here's a slightly modified version of the ggez basic project template, demonstrating the issue.

    use ggez::event::{self, EventHandler};
    use ggez::{graphics, Context, ContextBuilder, GameResult};
    use graphics::Drawable;
    
    fn main() {
        // Make a Context.
        let (mut ctx, mut event_loop) = ContextBuilder::new("my_game", "Cool Game Author")
            .build()
            .expect("aieee, could not create ggez context!");
    
        // Create an instance of your event handler.
        // Usually, you should provide it with the Context object to
        // use when setting your game up.
        let mut my_game = MyGame::new(&mut ctx);
    
        // Run!
        match event::run(&mut ctx, &mut event_loop, &mut my_game) {
            Ok(_) => println!("Exited cleanly."),
            Err(e) => println!("Error occured: {}", e),
        }
    }
    
    struct MyGame {
        // Your state here...
    }
    
    impl MyGame {
        pub fn new(_ctx: &mut Context) -> MyGame {
            // Load/create resources such as images here.
            MyGame {
    		    // ...
    		}
        }
    }
    
    impl EventHandler for MyGame {
        fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
            // Update code here...
            Ok(())
        }
    
        fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
            graphics::clear(ctx, graphics::WHITE);
            // Draw code here...
            let canvas = graphics::Canvas::with_window_size(ctx)?;
            graphics::set_canvas(ctx, Some(&canvas));
            graphics::Mesh::new_rectangle(
                ctx,
                graphics::DrawMode::fill(),
                graphics::Rect::new(10., 10., 100., 100.),
                graphics::BLACK,
            )?
            .draw(ctx, graphics::DrawParam::new())?;
            graphics::set_canvas(ctx, None);
            let image = canvas.into_inner();
            let image = break_everything(ctx, image)?; //Comment this line out to get expected behavior
            image.draw(ctx, graphics::DrawParam::new())?;
            graphics::present(ctx)
        }
    }
    
    fn break_everything(ctx: &mut Context, img: graphics::Image) -> GameResult<graphics::Image> {
        let w = img.width();
        let h = img.height();
        let pixels = img.to_rgba8(ctx)?;
        graphics::Image::from_rgba8(ctx, w, h, &pixels)
    }
    

    Expected behavior A black rectangle to appear on the screen, instead of nothing. The rectangle would be flipped, as per #693, but would exist.

    Hardware and Software:

    • ggez version: 0.51
    • OS: Linux (Mint, 19)
    • Graphics card: Intel HD Graphics 5500
    • Graphics card drivers: i915
    bug Type-CODE 
    opened by rocurley 30
  • the trait `ggez::graphics::Drawable` is not implemented for `Result<Mesh, ggez::GameError>`

    the trait `ggez::graphics::Drawable` is not implemented for `Result`

    Describe the bug I am trying to draw graphics with a mesh containing draw_polygon but the title error is displayed.

    To Reproduce See code

    Expected behavior Multiple voronoi polygons in a rectangle.

    Screenshots or pasted code culprit code:

    impl ggez::event::EventHandler<GameError> for State {
        fn update(&mut self, _ctx: &mut ggez::Context) -> GameResult {
            Ok(())
        }
        fn draw(&mut self, ctx: &mut ggez::Context) -> GameResult {
            ggez::graphics::clear(ctx, ggez::graphics::Color::BLACK);
            for shape in &self.shapes {
                // Make the shape...
                let mesh = match shape {
                    &Shape::Rectangle(rect) => {
                        ggez::graphics::Mesh::new_rectangle(ctx, ggez::graphics::DrawMode::fill(), rect, ggez::graphics::Color::WHITE)?
                    }
                    &Shape::Circle(origin, radius) => {
                        ggez::graphics::Mesh::new_circle(ctx, ggez::graphics::DrawMode::fill(), origin, radius, 0.1, ggez::graphics::Color::BLACK)?
                    }
                };
                // ...and then draw it.
                ggez::graphics::draw(ctx, &mesh, ggez::graphics::DrawParam::default())?;
            }
            for (i, poly) in self.vor_polys.iter().enumerate() {
                let mut mint = Vec::new();
                for p in poly {
                    mint.push(
                        mint::Point2{
                        x: p.x.into_inner() as f32,
                        y: p.y.into_inner() as f32,
                        }
                    );
                }
                mint.sort_unstable_by(|a, b| sort_clockwise(Point2::new(a.x as i32, a.y as i32), Point2::new(b.x as i32, b.y as i32),  Point2::new(1920/2, 1080/2)));
                let poly_mesh = ggez::graphics::Mesh::new_polygon(ctx, ggez::graphics::DrawMode::fill() , &mint, ggez::graphics::Color::BLUE);
                ggez::graphics::draw(ctx, &poly_mesh, ggez::graphics::DrawParam::default())?;
            }
            ggez::graphics::present(ctx)?;
            Ok(())
        }
    
    }
    

    Hardware and Software:

    • ggez version: For example, release 0.7.0, latest release
    • OS: Windows 11
    • Graphics card: RTX 3080 laptop
    • Graphics card drivers: 512.15
    question 
    opened by Mergpijp 29
  • ggez does not work on WSL2

    ggez does not work on WSL2

    Describe the bug I am attempting to make a cross-platform application on my windows computer. I can cargo run in cmd.exe, and the window opens. When I cargo run in my Ubuntu terminal I get this error: WARNING: lavapipe is not a conformant vulkan implementation, testing use only. and the app crashes

    If I export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/radeon_icd.x86_64.json then the program will run, but it is glitchy and shows this message: Failed to initialize graphics, trying secondary backends.. Please mention this if you encounter any bugs!

    To Reproduce Run a ggez application in WSL2.

    Expected behavior A window should open, and stay open.

    Hardware and Software:

    • ggez version: 0.8.1
    • OS: Windows 10 With Ubuntu WSL2
    • Graphics card: NVidia RTX 3070
    opened by wk1093 1
  • Present mode 'Mailbox' is not in the list of supported present modes

    Present mode 'Mailbox' is not in the list of supported present modes

    Describe the bug When sending a project to a friend, he got this error at runtime, it comes from wgpu-0.14.0\src\backend\direct.rs:274:9

    the only way he could run the game was by setting the backed to Dx12 (tried: All, Dx12, Vulkan and default) but had shit fps (2 to 5 percent the usual)

    To Reproduce it only happened on my project so, it might come from me. i'll tell him to run the first ggez example and give you an update here:

    • update: Empty for now

    Expected behavior I'd expect the game to run

    Screenshots or pasted code Nothing for now

    Hardware and Software:

    • ggez version: 0.8.1
    • OS: w10
    • Graphics card: AMD Radeon RX 6500 XT
    • Graphics card drivers: 'latests' 10/12/22
    opened by Bowarc 1
  • ggez/rustc nightly regression

    ggez/rustc nightly regression

    Describe the bug Simple white square on black canvas demo app fails on nightly rustc (tested on 1.67.0-2022-12-05 and 1.67.0-2022-12-08), yet works on stable (1.65.0).

    To Reproduce

    1. Clone and cargo run this project
    2. Note the window contains a white square
    3. Change rust-toolchain.toml to channel = "nightly"
    4. cargo run again
    5. Note the window no longer contains the white square

    Expected behavior Window should contain the white square.

    Hardware and Software:

    • ggez version: 0.8.1
    • OS: Mac OS Ventura 13.0.1
    • Graphics card: Radeon Pro 560X 4GB & Intel UHD Graphics 630 1536MB
    • Graphics card drivers:
    Radeon Pro 560X:
    
     Chipset Model:	Radeon Pro 560X
     Type:	GPU
     Bus:	PCIe
     PCIe Lane Width:	x8
     VRAM (Total):	4 GB
     Vendor:	AMD (0x1002)
     Device ID:	0x67ef
     Revision ID:	0x00c2
     ROM Revision:	113-C980AL-075
     VBIOS Version:	113-C97501U-005
     EFI Driver Version:	01.A1.075
     Automatic Graphics Switching:	Supported
     gMux Version:	5.0.0
     Metal Support:	Metal 2
     Displays:
    Color LCD:
     Display Type:	Built-In Retina LCD
     Resolution:	2880 x 1800 Retina
     Framebuffer Depth:	30-Bit Color (ARGB2101010)
     Mirror:	On
     Mirror Status:	Hardware Mirror
     Online:	Yes
     Automatically Adjust Brightness:	No
     Connection Type:	Internal
    S32D850:
     Resolution:	2560 x 1440 (QHD/WQHD - Wide Quad High Definition)
     UI Looks like:	2560 x 1440 @ 60.00Hz
     Framebuffer Depth:	30-Bit Color (ARGB2101010)
     Main Display:	Yes
     Mirror:	On
     Mirror Status:	Master Mirror
     Online:	Yes
     Rotation:	Supported
     Connection Type:	DVI or HDMI
     Adapter Firmware Version:	7.55
    
    opened by U007D 2
  • `Image::to_pixels` results in

    `Image::to_pixels` results in "bytes per row does not respect `COPY_BYTES_PER_ROW_ALIGNMENT`" error

    Attempting to call Image::to_pixels results in this error:

    thread 'main' panicked at 'wgpu error: Validation Error
    
    Caused by:
        In CommandEncoder::copy_texture_to_buffer
        Copy error
        bytes per row does not respect `COPY_BYTES_PER_ROW_ALIGNMENT`
    

    To Reproduce

    use std::{env, path};
    
    use ggez::{ContextBuilder, GameResult};
    
    fn main() -> GameResult<()> {
        let resource_dir = if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
            let mut path = path::PathBuf::from(manifest_dir);
            path.push("resources");
            path
        } else {
            path::PathBuf::from("./resources")
        };
    
        let mut builder = ContextBuilder::new("test", "brakts").add_resource_path(resource_dir);
        let (mut ctx, event_loop) = builder.build()?;
        let image = ggez::graphics::Image::from_path(&mut ctx, "/palette0.png")?;
        let pixels = image.to_pixels(&mut ctx)?;
        println!("Hello, world!");
        Ok(())
    }
    

    Example image: palette0

    Hardware and Software:

    • ggez version: 0.8.1
    • OS: Windows 11
    • Graphics card: Radeon 6900 XT
    bug Type-CODE 
    opened by 0----0 1
  • memory leak (probably command encoders not getting cleaned up)

    memory leak (probably command encoders not getting cleaned up)

    Describe the bug Meshes are not cleaned up after they go out of scope

    To Reproduce Create a Mesh and drop it

    Expected behavior The mesh should be dropped on the GPU

    Screenshots or pasted code Adapted from the "super_simple" example

    use ggez::{
        event,
        glam::*,
        graphics::{self, Color},
        Context, GameResult,
    };
    use log::LevelFilter;
    use simplelog::{ColorChoice, TermLogger, TerminalMode};
    
    struct MainState {}
    
    impl event::EventHandler<ggez::GameError> for MainState {
        fn update(&mut self, _ctx: &mut Context) -> GameResult {
            Ok(())
        }
    
        fn draw(&mut self, ctx: &mut Context) -> GameResult {
            let mut canvas =
                graphics::Canvas::from_frame(ctx, graphics::Color::from([0.1, 0.2, 0.3, 1.0]));
    
            let circle = graphics::Mesh::new_circle(
                ctx,
                graphics::DrawMode::fill(),
                vec2(0., 0.),
                100.0,
                2.0,
                Color::WHITE,
            )?;
    
            canvas.draw(&circle, Vec2::new(0., 380.0));
    
            canvas.finish(ctx)?;
    
            Ok(())
        }
    }
    
    pub fn main() -> GameResult {
        TermLogger::init(
            LevelFilter::Info,
            simplelog::Config::default(),
            TerminalMode::Stdout,
            ColorChoice::Auto,
        )
        .unwrap();
    
        let cb = ggez::ContextBuilder::new("super_simple", "ggez");
        let (ctx, event_loop) = cb.build()?;
        let state = MainState {};
        event::run(ctx, event_loop, state)
    }
    
    

    Hardware and Software:

    • ggez version: 0.8.1
    • OS: Archlinux
    • Graphics card: Nvidia RTX 3070
    • Graphics card drivers: nvidia proprietary driver, version 520.56.06, from nvidia-all
    Type-CODE *HELP WANTED* 
    opened by Dumdidldum 13
  • GraphicsInitializationError on Raspberry Pi 4

    GraphicsInitializationError on Raspberry Pi 4

    Describe the bug Attempting to run the devel branch's 01_super_simple example on a Raspberry Pi 4 fails with the error message:

    $ cargo run --example=01_super_simple
        Finished dev [unoptimized + debuginfo] target(s) in 1.23s
         Running `target/debug/examples/01_super_simple`
    Failed to initialize graphics, trying secondary backends.. Please mention this if you encounter any bugs!
    Error: GraphicsInitializationError
    

    To Reproduce

    1. Install a fresh Raspberry Pi OS (64-bit) on a Raspberry Pi 4
    2. Install Rust and the ggez prerequisites
    3. git clone https://github.com/ggez/ggez.git --branch=devel
    4. cargo run --example=01_super_simple

    Expected behavior A window showing a circle appears.

    Hardware and Software:

    • ggez version: current git devel branch (160413d32e88dacf4cb608900191e5ced2b4cca9)
    • OS: Raspberry Pi OS (64-bit) based on Debian GNU/Linux 11 (bullseye)
    • Graphics card: Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @ 1.5GHz
    • Graphics card drivers: unknown (lspci | grep VGA returns no output)
    driver bug dependency bug 
    opened by fenhl 3
Releases(0.8.1)
Planetoid is a toy project to demonstrate and learn several technologies. The goal is to create a little multiplayer asteriod game clone.

Planetoid is a toy project to demonstrate and learn several technologies. The goal is to create a little multiplayer asteriod game clone.

René Ribaud 8 Aug 23, 2022
The video game for Fonts of Power. A tabletop roleplaying game made in Rust with Bevy!

The code and rules for Fonts of Power, a tactical TTRPG / video game about exploring magical places. You can follow its development in our Discord ser

null 25 Dec 23, 2022
Red Light, Green Light is a traditional Korean children's game, popularised by the Squid Game TV series.

Red Light, Green Light Red Light, Green Light is a traditional Korean children's game, popularised by the Squid Game TV series. This project is the di

Cedric Chee 1 Jan 10, 2022
A game inspired by the classic atari game: demon attack

rusty_demon_attack A game inspired by the classic atari game: demon attack You can play the game in the web!

null 58 Jan 4, 2023
A roguelike game in Rust

A fantasy deathcrawl in Rust Work in progress. To run, with Rust compiler and Cargo package manager installed: cargo run --release When building on W

Risto Saarelma 347 Nov 21, 2022
😠⚔️😈 A minimalistic 2D turn-based tactical game in Rust

Zemeroth is a turn-based hexagonal tactical game written in Rust. Support: patreon.com/ozkriff News: @ozkriff on twitter | ozkriff.games | facebook |

Andrey Lesnikóv 1.3k Jan 5, 2023
⬡ Zone of Control is a hexagonal turn-based strategy game written in Rust. [DISCONTINUED]

Zone of Control The project is discontinued Sorry, friends. ZoC is discontinued. See https://ozkriff.github.io/2017-08-17--devlog.html Downloads Preco

Andrey Lesnikóv 354 Nov 14, 2022
This is a simple implementation of the classic snake game in rust

My snake game Looks like this. This is with Roboto Mono Nerd Font. If you use a different font it may look different or distorted. Install rust In ord

Konstantinos Kyriakou 16 Apr 4, 2021
The classic tetris game written in Rust using ncurses

tetris.rs This is the classic tetris game I wrote to have a bit of fun with Rust. Installation and playing cargo install --

null 71 Jul 25, 2022
A refreshingly simple data-driven game engine built in Rust

What is Bevy? Bevy is a refreshingly simple data-driven game engine built in Rust. It is free and open-source forever! WARNING Bevy is still in the ve

Bevy Engine 21.1k Jan 3, 2023
Data-oriented and data-driven game engine written in Rust

What is Amethyst? Amethyst is a data-driven and data-oriented game engine aiming to be fast and as configurable as possible. Principles These principl

Amethyst Engine 7.9k Dec 31, 2022
Minesweeper game developed with Rust, WebAssembly (Wasm), and Canvas

?? click here to play the game ?? Minesweeper game Revealing all the cells without hitting the mines is the task. Each number in the cell denotes how

Karthik Nedunchezhiyan 23 Dec 28, 2022
Snake Game in rust for the web

About This template shows how to create a web app using Yew and wasm-pack. ?? Usage ??️ Build When building for the first time, ensure to install depe

PsiAphex 1 Oct 24, 2021
A solver for the popular Wordle game written in Rust.

Wordle Solver A solver for the popular Wordle game written in Rust. It does not attempt to be the most efficient solver possible but tries to avoid us

William Hoggarth 2 Jul 1, 2022
A simple power 4 game wrote in Rust.

?? ?? Power 4 This is a simple power 4 game wrote in native Rust. There's only one dependencie for colored terminal. ❓ How to try it? To try this game

null 1 Apr 25, 2022
A finnish version of the word guessing game Wordle implemented in Rust.

Sanuli A finnish version of the word guessing game Wordle implemented in Rust. Live version running at sanuli.fi. Quick start Follow Rust installation

Jaakko Husso 59 Nov 29, 2022
👾 The classic Space Invaders game made in rust!

?? Invaders The classic space-shooter game now in your terminal! And the good part: made in Rust! ❕ This game was made during the course Ultimate Rust

João Augusto Perin 1 Feb 8, 2022
A block game made in Rust and SFML

septadrop A block game made in Rust and SFML. For packaging instructions, see the build folder. Game Controls ??/?? arrow keys: horizontal movement ??

Elnu 1 Dec 19, 2022
🚢 Battleship game implemented in Rust

?? Battleship game implemented in Rust. Fully playable between 2 players on the terminal. To play on the public instance: $ nc battleship.o

Orhun Parmaksız 55 Jan 2, 2023