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

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

  • Implement Mul for Transform
    Implement Mul for Transform

    Jun 2, 2019

    Since chaining multiple calls to Transform::combine is inconvenient, imho the usability of Transform would benefit from having the Mul trait implemented.

    I'm guessing the implementation would go something like this:

    impl Mul for Transform {
        type Output = Transform;
    
        fn mul(mut self, rhs: Transform) -> Transform {
            self.combine(&rhs);
            self
        }
    }
    

    (However, being relatively new to Rust I don't know if there are any caveats preventing this implementation from working correctly.)

    Reply
  • Progress and implementation of RcSprite
    Progress and implementation of RcSprite

    Jun 29, 2019

    I'd like to know. What prevents RcSprite from being published in a new version of rust-sfml ? I've been struggling for two days over storing a Texture and a Sprite side by side, and I think RcSprite is what I need to not go insane in developing using rust-sfml.

    Is it safe to copy the implementation of the branch rcsprite in my code or is it still an incomplete prototype ? What could I do to help develop this feature ?

    Reply
  • Shader.set_uniform_texture() texture borrow lifetime is too restrictive
    Shader.set_uniform_texture() texture borrow lifetime is too restrictive

    Jan 5, 2020

    Borrowing the texture for its entire lifetime renders this method unusable:

    1. It means the texture can not be updated anymore.
    2. Even if the texture is created just for the call, it can not be discarded anymore because: borrow might be used here, when 'shader' is dropped and runs the 'Drop' code for type 'sfml::graphics::Shader'
    3. Thus, the shader needs to be recompiled for every texture update, which is not acceptable.
    Reply
  • Vertex::new has inconsistent constructors
    Vertex::new has inconsistent constructors

    Mar 21, 2020

    Currently, sfml::graphics::Vertex has several constructors:

        pub fn new<P: Into<Vector2f>>(position: P, color: Color, tex_coords: Vector2f) -> Self;
        pub fn with_pos<P: Into<Vector2f>>(position: P) -> Self;
        pub fn with_pos_color<P: Into<Vector2f>>(position: P, color: Color) -> Vertex;
        pub fn with_pos_coords<P: Into<Vector2f>>(position: P, tex_coords: Vector2f) -> Vertex;
    

    I see a couple of problems with this interface:

    1. why is position a generic type but the other ones aren't?
    2. these constructors don't cover all cases (where is with_color?)

    Problem 2. is minor (it's arguably rarely needed), but problem 1. is a bit annoying. If I want to interface with SFML from my own application - using a different Vector2 type - I cannot just do Vertex::new(v, color, v) if v is my Vector type (with impl Into<sfml::system::Vector2f>): I'm forced to convert it myself or it won't be accepted as the third argument. The same goes for color.

    Moreover, having a trait bound on the generic type prevents these constructors to be const functions (today trait bounds on const fn are unstable).

    So my proposal is:

    1. either remove the genericity and only accept Vector2f - and in the process, make the functions const (my favourite solution), or
    2. make every argument generic.

    Of course proposal 1. breaks retrocompatibility, but I think it would be an acceptable tradeoff (sfml-rust is still 0.x after all).

    Reply
  • [Question] loading sRGB textures
    [Question] loading sRGB textures

    May 11, 2020

    I cannot figure out how you're supposed to load an sRGB texture from disk (or memory, or image). In SFML, you would do:

    sf::Texture texture;
    texture.setSrgb(true);
    texture.loadFromFile(...);
    

    But in rust-sfml this is not possible as from_file (and all the from_ functions) are static. Am I missing something here?

    Edit: I peeked into the CSFML API and apparently it's more of a CSFML issue, as the loadFrom* functions are not exposed for some reason, so I'm gonna open this issue in the CSFML repo.

    Reply
  • Question: How to open opengl inside sfml window with rust
    Question: How to open opengl inside sfml window with rust

    May 19, 2020

    I was just wondering how I can use opengl within rust-sfml...with cpp I could include the sfml/opengl.hpp header but I can't find documentation on how to do it with rust.

    Reply
  • Added antialiasing, and a new pong example using AA
    Added antialiasing, and a new pong example using AA

    Mar 29, 2016

    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.

    Reply
  • Remove borrow who are too restrictive
    Remove borrow who are too restrictive

    Jan 28, 2014

    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?

    Reply
  • Undefined references when linking on Linux
    Undefined references when linking on Linux

    Nov 22, 2013

    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?

    Reply
  • Add input stream functionality
    Add input stream functionality

    Aug 1, 2015

                                                                                                                                                                                                           
    Reply
  • Rendering issue on win 7
    Rendering issue on win 7

    Oct 25, 2013

    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.

    Reply
  • [WIP] Add SoundRecorder
    [WIP] Add SoundRecorder

    Oct 7, 2017

    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 ?.

    Reply