SFML bindings for Rust

Related tags

Emulators rust-sfml
Overview

rust-sfml Build Status crates.io Discord

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

Requirements

  • Linux, Windows, or OS X
  • Rust 1.56 or later
  • SFML 2.5
  • A C++ compiler for building CSFML
  • libclang for generating the low level bindings (See bindgen instructions)

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.

Discord

rust-sfml users are welcome on the Official SFML Discord server

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
Unicorn Emulator Debug Server - Written in Rust, with bindings of C, Go, Java and Python

udbserver - Unicorn Emulator Debug Server When you do emulation with Unicorn Engine, do you want to inspect the inner state during every step? udbserv

Bet4 246 Dec 27, 2022
NES emulator written in Rust to learn Rust

OxideNES A NES emulator in Rust. CPU should be accurate, PPU is mostly accurate, timing between the 2 is off for some corner cases and hardware qui

null 37 Nov 7, 2022
Chip8 emulator written in pure rust, using rust-sdl2 for graphics

Rust-8 chip8 emulator written in rust, using rust-sdl2 for graphics. Features Fully implemented all 35 original chip8 opcodes. This emulator does NOT

Chris Hinson 7 Dec 28, 2022
Commodore 64 emulator written in Rust

Rust64 - a C64 emulator written in Rust This is my attempt to study the Rust programming language and have fun at the same time. The goal is to presen

Krzysztof Kondrak 214 Dec 27, 2022
A Flash Player emulator written in Rust

website | demo | nightly builds | wiki Ruffle Ruffle is an Adobe Flash Player emulator written in the Rust programming language. Ruffle targets both t

Ruffle 11.2k Jan 8, 2023
A Game Boy research project and emulator written in Rust

Mooneye GB Mooneye GB is a Game Boy research project and emulator written in Rust. The main goals of this project are accuracy and documentation. Some

Joonas Javanainen 802 Dec 28, 2022
A Gameboy Emulator in Rust

RBoy A Gameboy Color Emulator written in Rust Implemented CPU All instructions correct All timings correct Double speed mode GPU Normal mode Color mod

Mathijs van de Nes 512 Dec 23, 2022
RGB (Rust Game Boy) is a simple emulator for the original game boy

RGB RGB (Rust Game Boy) is a simple emulator for the original game boy and the color game boy. Warning: This no longer compiles in the latest versions

Niven Achenjang 18 Dec 2, 2022
Full featured Cross-platform GameBoy emulator by Rust. Forever boys!.

Gameboy Full featured Cross-platform GameBoy emulator. Forever boys!. You can start a game with the following command, here with a built-in game "Boxe

Mohanson 1.2k Jan 2, 2023
RustBoyAdvance-NG is a Nintendo™ Game Boy Advance emulator and debugger, written in the rust programming language.

RustBoyAdvance-NG Nintendo GameBoy Advance ™ emulator and debugger, written in rust. WebAssembly Demo: https://michelhe.github.io/rustboyadvance-ng/ P

MishMish 510 Dec 30, 2022
An NES emulator written in Rust

Pinky Pinky is an NES emulator written in Rust completely from scratch based only on publicly available documentation. You can run it in your Web brow

Koute 709 Dec 23, 2022
NES emulator written in Rust

sprocketnes is an emulator for the Nintendo Entertainment System written in the Rust programming language. Its purpose is to serve as a technology dem

Patrick Walton 725 Dec 27, 2022
NES emulator in rust

NES emulator in Rust plastic is a NES emulator built from scratch using Rust. This is a personal project for fun and to experience emulating hardware

Amjad Alsharafi 27 Dec 15, 2022
ZX Spectrum emulator written in Rust

rustzx ZX Spectrum emulator which I writing in rust. I develop this project just for fun and for learning the basics of computer architecture. License

Vladislav Nikonov 162 Dec 27, 2022
Intel 8080 cpu emulator by Rust

i8080 i8080 is a emulator for Intel 8080 cpu. 8080 Programmers Manual 8080 opcodes [dependencies] i8080 = { git = "https://github.com/mohanson/i8080"

Mohanson 83 Dec 27, 2022
CHIP-8 emulator written in Rust

CHIP-8 emulator written in Rust. This is intended to be a project for gaining experience writing emulators and practice Rust.

Pedro Rodrigues 4 May 21, 2021
A CHIP-8 emulator for Rust in ~350 LOC

chip8 An implementation of the CHIP-8 for Rust in ~350 lines of code. What is CHIP-8? CHIP-8 is a virtual machine (along with a supporting programming

Daniel Gatis 8 Apr 23, 2022
Rudroid - Writing the World's worst Android Emulator in Rust 🦀

Rudroid - Writing the World's worst Android Emulator in Rust ?? Introduction Rudroid - this might arguably be one of the worst Android emulators possi

Chaithu 102 Dec 23, 2022
A 6502 emulator written in Rust.

v6502 This package contains an emulator for the 6502 microprocessor. It doesn't support binary decimal (BCD) mode yet. To run the debug version: cargo

Andrew Young 4 Nov 14, 2021