SFML bindings for Rust

Overview

rust-sfml Build Status crates.io

Rust bindings for SFML, the Simple and Fast Multimedia Library.

Requirements

Documentation

The API documentation is available at: https://docs.rs/sfml/

If you need help with setting up rust-sfml on your system, you can take a look at the wiki.
Please take note that:

  • This wiki is supported by the community
  • The rust-sfml core team doesn't review it
  • Your contribution is welcome

License

This software is a binding of the SFML library created by Laurent Gomila, which is provided under the Zlib/png license.

This software is provided under the same license as SFML, the Zlib/png license.

Comments
  • [WIP] Add SoundRecorder

    [WIP] Add SoundRecorder

    Fixes #170. This is work in progress PR for adding SoundRecorder functionality to rust-sfml. I also created an example on how the the functionality could be used. I welcome any suggestions on how to improve the API. I still need to add documentation and work a bit more on the unsafe functions. Now the compiler is optimizing the closures during monomorphisation so much that I don't even need the void* because the function call gets inlined directly. But syntactically I still need an instance of the type of the closure to call it (I think). If there is a way to call a closure just by knowing it's type please let me know ๐Ÿ˜ƒ.

    opened by petoknm 20
  • Rendering issue on win 7

    Rendering issue on win 7

    Having issues with rendering on the windows 7 platform. The example provided which is supposed to draw a red cricle on a greenish-blue background just draws a black screen. Changing the colours used result in the same black screen. Although drawing the shape when a colour has not been assigned results in a white circle with a black background.

    I have tried rsfml on two windows 7 machines, same result. I have also tried rsfml in Ubuntu (same machine), no problems and works as intended. I have tried the c++-sfml build on windows 7 (same machine), no problems and works as intended.

    Not sure where this issues is coming from, thanks.

    opened by kylepink 19
  • Music::from_stream and from_memory are unsound

    Music::from_stream and from_memory are unsound

    Got the following message in debug mode after creating the music with helper function, which has a shorter scope for its Vec/Cursor, and trying to play it afterwards. error: process didn't exit successfully: target\debug\sfml_test.exe (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION). Supposedly, it's CSFML/SFML fault for no indication of pointer's lifetime in documentation or elsewhere. Though I don't have a clear solution. At least impl Into<Box<[u8]>> with pinning should suffice for from_memory.

    unsound needs-testing 
    opened by Kolsky 17
  • Undefined references when linking on Linux

    Undefined references when linking on Linux

    I'm having trouble linking rust-sfml on Linux. I'm using the same ppa as rust-sfml is using for Travis, but when it reaches the linking stage, a bunch of undefined reference errors are thrown: https://travis-ci.org/dguenther/rustchip/builds/14399546

    I've had the same trouble on my local build server. Does anyone have any ideas how to debug this?

    opened by dguenther 15
  • Remove borrow who are too restrictive

    Remove borrow who are too restrictive

    Borrow pointer seems to be too restrictive, I've made a branch with a replacement using Rc< Refcell< Resource>> to handle SFML resource.

    Someone had Review on this?

    @darnuria? @krzat? @KarlZylinski you seems to have problems with borrow pointers, is Rc a good replacement?

    opened by jeremyletang 13
  • SFML not compiling on windows 10 with new 0.16.0

    SFML not compiling on windows 10 with new 0.16.0

    Tryed to compile some samples on windows 10 x64 with the new 0.16.0 and got the following stack trace:

    w" "-lcsfml-audio" "-lcsfml-system" "-ladvapi32" "-lws2_32" "-luserenv" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "C:\\Users\\jcbri\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o"
      = note: C:/Bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Workspace\rust\sfml\target\debug\deps\libsfml-630982b2ac42bd62.rlib(sfml-630982b2ac42bd62.sfml.325wk4ff-cgu.15.rcgu.o): in function `sfml::graphics::render_texture::RenderTexture::with_settings':
              C:\Users\jcbri\.cargo\registry\src\github.com-1ecc6299db9ec823\sfml-0.16.0\src\graphics\render_texture.rs:57: undefined reference to `sfRenderTexture_createWithSettings'
              collect2.exe: error: ld returned 1 exit status
    ``ยด
    
    This happens on both msvc and gnu toolchains.
    opened by jcbritobr 12
  • Added antialiasing, and a new pong example using AA

    Added antialiasing, and a new pong example using AA

    Here are two pictures, with a pair of modified Pong examples with a ball radius of 30. and antialiasing levels 0 and 8 respectively.

    Without AA

    With 8xAA

    I have a low-res monitor, but I think the difference is clearly visible.

    opened by mrkgnao 12
  • 2.3 update tracking

    2.3 update tracking

    Here we will list the different item who have change since SFML 2.1 and that we need to update for the 2.3 release:

    • Graphics
      • [x] BlendMode
      • [ ] CircleShape
      • [ ] Color
      • [ ] ConvexShape
      • [ ] Font
      • [ ] FontInfo
      • [ ] Glyph
      • [ ] RectangleShape
      • [ ] RenderTexture
      • [ ] RenderWindow
      • [ ] Shape
      • [ ] Text/TextStyle
      • [ ] VertexArray
    • Window (need to evaluate if we can support touch / mobile device)
      • [ ] events
      • [ ] Joystick
      • [ ] Mouse
      • [ ] Sensor
      • [ ] Touch
      • [ ] Window
    • Audio
      • [ ] Listener
      • [ ] SoundBuffer
      • [ ] SoundRecorder
      • [ ] SoundBufferRecorder
      • [ ] SoundStream
    opened by jeremyletang 11
  • Finding CSFML and SFML dependencies on Windows

    Finding CSFML and SFML dependencies on Windows

    When building on Windows rust-sfml wasn't able to find my CSFML and SFML libraries. Found out that the paths in the build scripts were using forward slashes, not back slashes. Updated them, and also had them look for SFML libraries at SFML_HOME, not just CSFML libraries at CSFML_HOME.

    This addresses #138 (I think). I bumped the versions; can change back if you want.

    opened by bookdude13 10
  • Consider panicking instead of returning None on allocation failures

    Consider panicking instead of returning None on allocation failures

    I'm not sure if other object behave in this manor, but for something as simple as a shape constructor, is returning Option the best option (no pun intended)? As far as I can tell, the only reason None would be returned would be due to an allocation error, and that would imply the program is out of memory. If that's the case, then there are a lot bigger problems at hand that shouldn't be dealt with wherever a shape is getting created. I feel a fail!() if the shape is null when created would make more sense, but that's just my opinion.

    opened by tVoss 10
  • Issue Running under macOS

    Issue Running under macOS

    I have just installed the library and fixed some issues linking SFML and CSFML. When running the program, I get this error:

    error[E0061]: this function takes 3 parameters but 2 parameters were supplied
     --> src/main.rs:7:55
      |
    7 |     let mut window = RenderWindow::new(VideoMode::new(800, 600), "Hello", style::CLOSE, &Default::default());
      |                                                       ^^^^^^^^ expected 3 parameters
    
    error: no method named `poll_event` found for type `std::option::Option<sfml::graphics::RenderWindow>` in the current scope
      --> src/main.rs:10:37
       |
    10 |         while let Some(ev) = window.poll_event() {
       |                                     ^^^^^^^^^^
    
    error: no method named `clear` found for type `std::option::Option<sfml::graphics::RenderWindow>` in the current scope
      --> src/main.rs:17:16
       |
    17 |         window.clear();
       |                ^^^^^
    
    error: no method named `display` found for type `std::option::Option<sfml::graphics::RenderWindow>` in the current scope
      --> src/main.rs:20:16
       |
    20 |         window.display();
       |                ^^^^^^^
    
    error: aborting due to 4 previous errors
    
    error: Could not compile `retro`.
    

    This is my code:

    extern crate sfml;
    
    use sfml::graphics::*;
    use sfml::window::*;
    
    fn main() {
        let mut window = RenderWindow::new((800, 600), "Hello", style::CLOSE, &Default::default());
    
        loop {
            while let Some(ev) = window.poll_event() {
                match ev {
                    Event::Closed => return,
                    _ => {}
                }
            }
    
            window.clear();
            
    
            window.display();
        }
    }
    
    

    I installed SFML and CSFML via brew.

    Thank you

    opened by gmisail 8
  • Cannot statically link in mingw missing sfml-system-s

    Cannot statically link in mingw missing sfml-system-s

    I have both a dev environment in Ubuntu and Windows10, I am trying to cross-compile a binary for windows. When I set SFML_STATIC I get this error:

    error: could not find native static library `sfml-system-s`, perhaps an -L flag is missing?
    

    I have both tried using the information in the Wiki (both installing via pacman and manually). I can see that the sfml-system-s.a and sfml-system-s-d.a` both exist in the libs folder.

    I'm not really sure how to coax the build to complete so that I don't have have SFML DLLS installed in order for my program to run

    opened by donicrosby 0
  • Fonts loaded from memory require the source data buffer to be kept available

    Fonts loaded from memory require the source data buffer to be kept available

    There is a warning about this on sfml documentation

    When using this with rust, the font does not work if the buffer is dropped. This should be in the documentation.

    opened by cpardotortosa 2
  • Suggest + volunteer: add more doc examples

    Suggest + volunteer: add more doc examples

    Dear rust-sfml maintainers, hi @jeremyletang,

    Thanks for rust-SFML: I am very happy I can use one of my favorite graphics libraries on Rust :-)

    One of the cool things of Rust is that one can add examples to the documentation, as already done, for example, for the Window struct.

    However, for simpler types, the documentation feels incomplete.

    For me, a rustling, I would enjoy seeing more examples in the documentation rust-sfml. I even volunteer to do so (sure, we'll probably schedule a quick chat, I will use Pull Requests, etc). The CONTRIBUTING.md could be more helpful in telling me when a PR is likely to be accepted and when not :-)

    How do we proceed from here?

    opened by richelbilderbeek 2
  • Meta: Activate Github Discussions feature

    Meta: Activate Github Discussions feature

    It would be nice to have a more casual way for users to ask questions.

    Pinging repo owner @jeremyletang. I would be grateful if you enabled that feature in the repository settings! Thank you very much in advance!

    opened by crumblingstatue 1
  • Investigate thread safety of rust-sfml

    Investigate thread safety of rust-sfml

    So far most of the effort has been to make the library safe to use in a single-threaded context, but there haven't been much investigation on how it behaves when multiple threads are involved.

    Related/sub issues:

    • #226 Related pull requests:
    • #227
    thread-safety 
    opened by crumblingstatue 5
  • Key/Button::is_pressed are not thread safe

    Key/Button::is_pressed are not thread safe

    At least on X11, it can trigger all kinds of errors to call them from a different thread. And someone messaged me that it can cause segfaults for them to do so.

    unsound thread-safety 
    opened by crumblingstatue 4
Releases(v0.19.0)
  • v0.19.0(Oct 31, 2022)

    Added

    • Basic support for statically linking SFML

    Fixed

    • Wrong doc comment for RenderTexture::new
    • Joystick axis was inacessible in the JoystickMoved event

    Changed

    • joystick::Axis is now a proper enum
    Source code(tar.gz)
    Source code(zip)
  • v0.18.0(Aug 20, 2022)

    Added

    • Examples for Vector3
    • Examples for Vector2
    • Examples for Rect
    • Examples for RenderWindow
    • Examples for Font
    • Info about SFML_INCLUDE_DIR and SFML_LIBS_DIR environment variables

    Changed

    • window::clipboard::get_string() now returns String instead of &'static SfStr
    • Color now has public fields, removed the unnecessary getter/setter methods.

    Fixed

    • Update requirements in the crate documentation
    • Make set_mouse_cursor unsafe, as the cursor must stay alive while in use.
    • Fix wrong Vector3::{AddAssign, SubAssign} impls
    • Add Hash impl for CursorType
    Source code(tar.gz)
    Source code(zip)
  • v0.17.0(Aug 3, 2022)

    Changelog

    • Replaced CSFML dependency with a vendored CSFML fork, which is built by rust-sfml and linked statically. Now there is no dependency on CSFML anymore. However, a C++ compiler is now required to build-rust SFML, as we are building our own CSFML-like binding.
    • Added spritemark example to show off the rendering speed that can be achieved with vertex arrays.
    • Fixed unsoundness in InputStream
    • Added RectangleShape::from_rect
    • Removed VertexArray in favor of RenderTarget::draw_primitives, which takes a slice of vertices.
    • Added graphics::vertex_array_bounds to replace VertexArray::get_bounds
    • Enabled null pointer optimization to a bunch of types that are never null
    • Added Rust version of the SFML OpenGL example
    • Made Shader constructors only allow valid combinations of vertex/fragment/geometry
    • Made pong example more exciting. It speeds up as the game goes on.
    • Derived a bunch more traits like Hash for some types
    • Made a bunch of previously wrongly-safe functions unsafe
    • Added a bunch of conversion functions for conversion between different Vector2/Vector3 types
    • Added optional support for serde for a few types, like Rect
    • Removed SfBool completely. Now you can just use bool everywhere.
    • Once again, a bunch of other various (breaking) changes. Sorry.
    Source code(tar.gz)
    Source code(zip)
  • v0.16.0(Mar 28, 2021)

    New features

    • Implement VertexBuffer
    • Add a few previously missing derives to a few types
    • Add system_handle method to Window and RenderWindow.

    Soundness fixes

    • Add some thread safety checks for the window module. See https://github.com/jeremyletang/rust-sfml/pull/227.
    • CircleShape::set_radius now takes &mut self

    API improvements

    • Add #[must_use] attribute to APIs that return things that should not be ignored.
    • Make a bunch of APIs const fn
    • Allow SfBox to be used in generic contexts, using the SfResource trait.

    Refactorings/Breaking changes

    • Transition various enums that were previously transmuted to associated consts. This avoids unnecessary unsafe code and maps more cleanly to the underlying C API of CSFML. This means a bunch of names are now UPPER_CASE instead of CamelCase. For example Key::Equal becomes Key::EQUAL, because it's an associated const.
    • Remove a few API elements that are deprecated in SFML, like Key::Return. Use Key::ENTER instead.
    • Network module is removed entirely. It has been broken and unmaintained for a long time, and there are much better alternatives when using Rust, including the standard library.
    • SfBox now lives in the crate root, not system.
    • Due to the thread safety fixes, Window/RenderWindow can only be used on the main thread. They can't be accessed from different threads.
    • Various minor refactorings/improvements
    Source code(tar.gz)
    Source code(zip)
  • v0.15.1(Oct 26, 2019)

  • v0.15.0(Oct 19, 2019)

  • v0.13.2(Sep 9, 2017)

    Various API changes, including using associated consts where possible.

    For example, the various predefined colors are now proper associated consts, instead of methods on Color.

    This also removes some unnecessary submodules, like the style module that holds the constants for the Style type. They are not associated consts on Style itself.

    Source code(tar.gz)
    Source code(zip)
  • v0.12.0(Mar 25, 2017)

  • v0.11.1(Mar 3, 2016)

  • v0.10.1(Feb 13, 2016)

  • rust0.11(Jul 3, 2014)

  • rust0.10(Apr 3, 2014)

  • rust0.8(Sep 27, 2013)

Owner
Jeremy Letang
Jeremy Letang
Rust bindings for GDNative

GDNative bindings for Rust Rust bindings to the Godot game engine. Website | User Guide | API Documentation Stability The bindings cover most of the e

null 3.2k Jan 9, 2023
SDL bindings for Rust

Rust-SDL Bindings for SDL in Rust Overview Rust-SDL is a library for talking to SDL from Rust. Low-level C components are wrapped in Rust code to make

Brian Anderson 174 Nov 22, 2022
SDL2 bindings for Rust

Rust-SDL2 Bindings for SDL2 in Rust Changelog for 0.34.2 Overview Rust-SDL2 is a library for talking to the new SDL2.0 libraries from Rust. Low-level

null 2.2k Jan 5, 2023
Rust bindings for libtcod 1.6.3 (the Doryen library/roguelike toolkit)

Warning: Not Maintained This project is no longer actively developed or maintained. Please accept our apologies. Open pull requests may still get merg

Tomas Sedovic 226 Nov 17, 2022
Some Rust bindings for Binary Ninja

Binary Ninja Rust Bindings Work in progress Rust bindings geared towards analysis. Features added as they come up. No promises anything works at this

Cory Duplantis 21 May 5, 2022
Qt Quick / QML bindings for Rust

qmlrsng Qt Quick bindings for Rust, based on libqmlbind. The crate libqmlbind-sys wraps libqmlbind C library in Rust and exposes an unsafe API. The go

Nicolas Bigaouette 5 Jul 13, 2017
Idiomatic Rust bindings for Pdfium

Idiomatic Rust bindings for Pdfium pdfium-render provides an idiomatic high-level Rust interface around the low-level bindings to Pdfium exposed by th

Alastair Carey 65 Jan 8, 2023
Wein2D.js bindings for creating browser games in Rust using WebAssembly.

Wein2D.js-WASM Wein2D.js bindings for creating browser games in Rust using WebAssembly. Wein2D.js-WASM requires Wein2d.js to be loaded in the same doc

DevTaube 1 Apr 14, 2022
A simple Verlet integration solver written using the Rust SDL2 bindings.

Rust Verlet Solver A simple Verlet integration solver written using the Rust SDL2 bindings. Where's the friction?! Building cargo-vcpkg is required in

Will 8 Jun 6, 2022
MMDeploy bindings for Rust.

rust-mmdeploy-sys MMDeploy bindings for Rust. ?? THIS REPO IS STILL UNDER CONSTRUCTION! Prerequisites NOTICE: Linux only. Onnxruntime only. In order t

ๆขฆ้˜ณ 2 Sep 29, 2022
Rust bindings for googleprojectzero/TinyInst

tinyinst-rs FFI to TinyInst. Created for LibAFL. Dependencies cxxbridge cargo-make python3 git Running the test Open a terminal and set up your build

Advanced Fuzzing League ++ 12 Jan 20, 2023
Rust bindings for entity-gym.

EntityGym for Rust EntityGym is a Python library that defines a novel entity-based abstraction for reinforcement learning environments which enables h

null 18 Apr 15, 2023
A simple Verlet integration solver written using the Rust SDL2 bindings.

Rust Verlet Solver A simple Verlet integration solver written using the Rust SDL2 bindings. Where's the friction?! Building cargo-vcpkg is required in

Will 8 Jun 6, 2022
corange-rs CorangeCorange lucidscape/corange-rs โ€” Corange bindings

CORANGE-RS This crate provides an interface to the Corange game engine, written in Pure C, SDL and OpenGL by Daniel Holden. Features include: deferred

null 43 Jul 22, 2022
Pure and simple Vulkan bindings generated from Vulkan-Headers!

mira Pure and simple Vulkan bindings generated from Vulkan-Headers! Mira provides a simple and straightforward way to interact with Vulkan. Everything

maresia 3 Mar 3, 2022
Python bindings for egg

Python bindings for egg Installing Install maturin, a cool Rust/Python builder thingy. Download from their site or just pip install maturin. Type make

null 28 Dec 25, 2022
Bindings to TinyGL, a Small, Free and Fast Subset of OpenGL

TinyGL is a very lightweight partial OpenGL implementation. Its small size makes it ideal for static linking.

null 12 Oct 13, 2022
Safe, fully-featured bindings to the Tracy profiler

Complete Rust bindings for the Tracy profiler. Getting Started Just add the following to your Cargo.toml: [dependencies.tracy] package = "tracy_full"

Shaye Garg 12 May 6, 2023
Rust-raytracer - ๐Ÿ”ญ A simple ray tracer in Rust ๐Ÿฆ€

rust-raytracer An implementation of a very simple raytracer based on Ray Tracing in One Weekend by Peter Shirley in Rust. I used this project to learn

David Singleton 159 Nov 28, 2022