Code Monkey home page Code Monkey logo

rust-sfml's Introduction

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.70 or later
  • SFML 2.6
  • A C++ compiler for building CSFML

Environment variables

If you get errors about SFML headers not being found, or linker errors, that probably means SFML is not installed in a global location. In that case, you can set two environment variables to help rust-sfml find the required files:

  • SFML_INCLUDE_DIR. Set this to the include folder of your SFML location.
  • SFML_LIBS_DIR. Set this to the lib folder of your SFML location.

To help debugging environment variables, you can try building with cargo build -vv. If the environment variables are set correctly, you should get warnings like this:

warning: Custom SFML include dir: C:\Users\You\sfml\include
warning: Adding custom SFML libs search path C:\Users\You\sfml\lib

TIP: To set the environment variables of a cargo project, you can use the {project_dir}/.cargo/config.toml file documented here: https://doc.rust-lang.org/cargo/reference/config.html#env

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

rust-sfml's People

Contributors

akunaatrium avatar aleokdev avatar arm32x avatar bastacyclop avatar bookdude13 avatar brandonson avatar cpardotortosa avatar crumblingstatue avatar datmaffin avatar dguenther avatar dogunbound avatar donicrosby avatar jeremyletang avatar kmdreko avatar memoryleak47 avatar mrkgnao avatar owwk avatar petoknm avatar sebcrozet avatar silverweed avatar sindreij avatar sp0 avatar spacemaniac avatar steveklabnik avatar tomjakubowski avatar truenotzero avatar tyrannosaurus avatar ulel avatar wanzzhehe avatar zstewar1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-sfml's Issues

rust is unable to find SFML libraries

Hey! I've been trying to build rust-sfml, and it seems like it's unable to find the C++ SFML libraries

Here'e the rustc output:

rustc --version
rustc 0.10-pre (2bba723 2014-02-17 08:06:49 -0800)
host: x86_64-unknown-linux-gnu

And here's the output when I try and build rust-sfml:

 make
mkdir -p lib
rustc --out-dir=lib src/rsfml/lib.rs


error: linking with `cc` failed: exit code: 1
note: cc arguments: '-m64' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' 'lib/librsfml-fe88034a-0.2.so' 'lib/rsfml.o' 'lib/rsfml.metadata.o' '-nodefaultlibs' '-Wl,--as-needed' '-L/home/bollu/prog/build/rust-sfml/.rust' '-L/home/bollu/prog/build/rust-sfml' '-lcsfml-system' '-lcsfml-window' '-lcsfml-audio' '-lcsfml-graphics' '-lcsfml-network' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lstd-966edb7e-0.10-pre' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lsync-7bf3a0fc-0.10-pre' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lserialize-d01a48ca-0.10-pre' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lcollections-6cc47867-0.10-pre' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lgetopts-f2d8d0e7-0.10-pre' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lterm-2516c234-0.10-pre' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lextra-64ade3d6-0.10-pre' '-lrt' '-lc' '-ldl' '-lm' '-lpthread' '-lgcc_s' '-shared' '-Wl,-rpath,$ORIGIN/../../../../../../usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-Wl,-rpath,/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lmorestack' '-lcompiler-rt'
note: /usr/bin/ld: cannot find -lcsfml-system
/usr/bin/ld: cannot find -lcsfml-window
/usr/bin/ld: cannot find -lcsfml-audio
/usr/bin/ld: cannot find -lcsfml-graphics
/usr/bin/ld: cannot find -lcsfml-network
collect2: error: ld returned 1 exit status

error: aborting due to previous error
Makefile:26: recipe for target 'lib' failed
make: *** [lib] Error 101

But the libraries do exist in /usr/lib

ls /usr/lib | grep sfml
├── libsfml-audio.a
├── libsfml-audio.so
├── libsfml-graphics.a
├── libsfml-graphics.so
├── libsfml-network.a
├── libsfml-network.so
├── libsfml-system.a
├── libsfml-system.so
├── libsfml-window.a
├── libsfml-window.so

And also:

ls /lib/ | grep sfml
├── libsfml-audio.a
├── libsfml-audio.so
├── libsfml-graphics.a
├── libsfml-graphics.so
├── libsfml-network.a
├── libsfml-network.so
├── libsfml-system.a
├── libsfml-system.so
├── libsfml-window.a
├── libsfml-window.so

So, any ideas as to why it's not able to build? Ive been trying for ~2 days but I've had no success.

FAQ:
Yes, I'm using SFML 2.1. I built it from source using the clang compiler

Here's the clang version:

clang --version
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix

Also, the rust compiler was also built from source - last built around a week back.

I'm on ArchLinux, with the 64 bit version. I've enabled multilib, so I do have some of the more common packages in both 32 bit and 64 bit.

Thanks a lot for writing the library :) I wish I could just build it though >_>;

Setting up on Windows

Hi, if I create a new project by running cargo new rsfml --bin and then add sfml = "0.9.3" to my dependencies, I can't compile. In your readme, you state that I have to install sfml and csfml.... I was wondering how you do that? It's not clear. Sorry :(
My output:

    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling libc v0.1.8
   Compiling winapi-build v0.1.1
   Compiling winapi v0.2.1
   Compiling advapi32-sys v0.1.2
   Compiling rand v0.3.9
   Compiling sfml v0.9.3
error: linking with `gcc` failed: exit code: 1
note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-static-libgcc" "-m64" "-L" "C:\Program Files\Rust stable 1.1\bin\rustlib\x86_64-pc-windows-gnu\lib" "-o" "C:\Users\user\Documents\Programming\Rust\rsfml\target\debug\deps\sfml-c376d0ff0e84302b.dll" "C:\Users\user\Documents\Programming\Rust\rsfml\target\debug\deps\sfml-c376d0ff0e84302b.o" "C:\Users\user\Documents\Programming\Rust\rsfml\target\debug\deps\sfml-c376d0ff0e84302b.metadata.o" "C:\Users\user\Documents\Programming\Rust\rsfml\target\debug\deps\liblibc-2eda841eb12a3090.rlib" "-L" "C:\Program Files\Rust stable 1.1\bin\rustlib\x86_64-pc-windows-gnu\lib" "-lstd-7d23ff90" "-L" "C:\Users\user\Documents\Programming\Rust\rsfml\target\debug\deps" "-L" "C:\Users\user\Documents\Programming\Rust\rsfml\target\debug\deps" "-L" "C:\Program Files\Rust stable 1.1\bin\rustlib\x86_64-pc-windows-gnu\lib" "-L" "C:\Users\user\Documents\Programming\Rust\rsfml\src\.rust\bin\x86_64-pc-windows-gnu" "-L" "C:\Users\user\Documents\Programming\Rust\rsfml\src\bin\x86_64-pc-windows-gnu" "-Wl,--whole-archive" "-Wl,-Bstatic" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-lcsfml-system" "-lcsfml-window" "-lcsfml-audio" "-lcsfml-graphics" "-lcsfml-network" "-lws2_32" "-luserenv" "-shared" "-lcompiler-rt"
note: ld: cannot find -lcsfml-system
ld: cannot find -lcsfml-window
ld: cannot find -lcsfml-audio
ld: cannot find -lcsfml-graphics
ld: cannot find -lcsfml-network

error: aborting due to previous error
Could not compile `sfml`.

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.

RFC: Rename crate from `rsfml` to `sfml`

The crate is already used in the context of Rust, so the r is redundant.
sfml is one letter shorter, and more consistent with other bindings like rust-sdl and rust-sdl2, which use sdl and sdl2 for their crate names respectively.

The only drawback is that existing code would need to be changed to use sfml instead of rsfml, but that sounds like just a simple search&replace operation.

Alternatively, we could use sf, which is even shorter, and in line with the original SFML library, which is contained in the sf namespace.

Reason for refcounted views?

In rsfml::graphics::RenderWindow all the methods dealing with views (set_view, get_view …) deal with Rc<RefCell> objects in their instances. I wonder why this is. It feels a bit bloated to deal with these objects instead of simple borrowed pointers. So in essence my question is the following: why should the RenderWindow care at all about how the view's memory is managed?

Simply want to understand your rationale behind this.

Random `KeyReleased events` when holding key

If the frame rate is kept unbounded, random KeyReleased events are triggered when holding a key.

e.g: The following code

extern crate sfml;

use sfml::window::{ContextSettings, VideoMode, event, window_style};
use sfml::graphics::{RenderWindow};

fn main() {
    let mut window = RenderWindow::new(VideoMode::new_init(400, 400, 32),
                                   "a",
                                   window_style::CLOSE,
                                   &ContextSettings::default()).unwrap();

    //window.set_framerate_limit(60);
    //window.set_vertical_sync_enabled(true);

    loop {
        for event in window.events() {
            match event {
                event::Closed => return,
                event::KeyPressed { code, .. } => {
                    println!("Key pressed: {:?}", code);
                },
                event::KeyReleased { code, .. } => {
                    println!("Key released: {:?}", code);
                }
                _ => {},
            }
        }
        window.display();
    }
}

will sometimes print

...
Key pressed: Right
Key released: Right
Key pressed: Right
...

when holding the Right arrow pressed.

The problem disappears if you limit the framerate with either

set_framerate_limit()

or

set_vertical_sync_enabled(true)

Segfault in Pong example

Hello!
When i execute pong in ./bin after compiling it i get a segfault. :x
Ubuntu-12.04.03
Rust version 0.9
SFML :2.0
Csfml: 2.0
Installed with instruction found in .travis.yml

Gdb stuff :
(gdb) run
Starting program: /home/darnuria/libs/rust-sfml/bin/pong
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7fbe700 (LWP 12696)]
[New Thread 0x7fffee37b700 (LWP 12697)]
[New Thread 0x7fffee27a700 (LWP 12698)]
[New Thread 0x7fffee179700 (LWP 12699)]
[New Thread 0x7fffee078700 (LWP 12700)]
[New Thread 0x7fffedf77700 (LWP 12701)]
[New Thread 0x7fffede76700 (LWP 12702)]
[New Thread 0x7fffedd75700 (LWP 12703)]
24
[New Thread 0x7fffcfbc9700 (LWP 12704)]
[Thread 0x7fffcfbc9700 (LWP 12704) exited]
[New Thread 0x7fffcfbc9700 (LWP 12705)]
[New Thread 0x7fffcf3c8700 (LWP 12706)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7fbe700 (LWP 12696)]
0x00007ffff3f60cac in sf::RenderTarget::clear(sf::Color const&) () from /usr/local/lib/libsfml-graphics.so.2
(gdb) s
Single stepping until exit from function _ZN2sf12RenderTarget5clearERKNS_5ColorE,
which has no line number information.
[Thread 0x7fffcfbc9700 (LWP 12705) exited]
[Thread 0x7fffcf3c8700 (LWP 12706) exited]
[Thread 0x7fffedd75700 (LWP 12703) exited]
[Thread 0x7fffede76700 (LWP 12702) exited]
[Thread 0x7fffedf77700 (LWP 12701) exited]
[Thread 0x7fffee078700 (LWP 12700) exited]
[Thread 0x7fffee179700 (LWP 12699) exited]
[Thread 0x7fffee27a700 (LWP 12698) exited]
[Thread 0x7fffee37b700 (LWP 12697) exited]
[Thread 0x7ffff7fbe700 (LWP 12696) exited]

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.

More human readeable llvb-3.3 stuff :
darnuria@firestone:master$ lldb-3.3 ./pong
Current executable set to './pong' (x86_64).
(lldb) run
Process 14367 launched: './pong' (x86_64)
24
Process 14367 stopped

  • thread #2: tid = 0x3823, 0x00007fca6888ccac libsfml-graphics.so.2sf::RenderTarget::clear(sf::Color const&) + 12, stop reason = invalid address frame #0: 0x00007fca6888ccac libsfml-graphics.so.2sf::RenderTarget::clear(sf::Color const&) + 12
    libsfml-graphics.so.2`sf::RenderTarget::clear(sf::Color const&) + 12:

-> 0x7fca6888ccac: callq *24(%rax)
0x7fca6888ccaf: testb %al, %al
0x7fca6888ccb1: jne 0x7fca6888ccb8 ; sf::RenderTarget::clear(sf::Color const&) + 24
0x7fca6888ccb3: popq %rbx
(lldb)

About an update to handle cargo build script

Hi,
following this reddit subject.

The ffi mod should be outside the rust sfml "wrapper" as an internal project to allow an overriding of the build script.

More conventional for cargo and easiest way to link for windows users.

There are a lot of things to move out and I am not sure of what to keep. But it could look like that

Cargo.toml

[package]

name = "sfml-sys"
version = "0.0.1"
authors = ["Jeremy Letang <[email protected]>"]
links = "sfml-sys"
build = "build.rs"

[lib]
name = "sfml-sys"
path = "src/lib.rs"

[build-dependencies]
pkg-config = "*"

[features]

default = []
use-pkgconfig = []

build.rs

extern crate "pkg-config" as pkg_config;

fn main() {
    let libs = [
        "csfml-system", 
        "csfml-window", 
        "csfml-graphics",
        "csfml-audio",
        "csfml-network"
    ];

    if std::os::getenv("CARGO_FEATURE_USE_PKGCONFIG").is_some() {
        for &l in libs.iter() {
            if pkg_config::find_library(l).is_err() {
                panic!("Could not find {:} via pkgconfig")
            }
        };
    } else {
        for &l in libs.iter() {
            println!("cargo:rustc-flags=-l {:}", l);
        };
    }
}

Regards.

Does not compile on latest nightly

Rust version

PS C:\Users\Andrew McKinlay\Documents\GitHub\rust-sfml> rustc -v
rustc 0.13.0-nightly (f9fc49c06 2014-10-10 00:07:08 +0000)

Cargo version

PS C:\Users\Andrew McKinlay\Documents\GitHub\rust-sfml> cargo --version
cargo 0.0.1-pre-nightly (861c07f 2014-10-07 23:29:57 +0000)

Rust SFML version

0.9.0

Error message

PS C:\Users\Andrew McKinlay\Documents\GitHub\rust-sfml> cargo build
   Compiling rust-sfml v0.9.0 (file:///C:/Users/Andrew%20McKinlay/Documents/GitHub/rust-sfml)
src\window\event.rs:275:17: 275:32 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:275                 sfEvtKeyPressed => {
                                        ^~~~~~~~~~~~~~~
src\window\event.rs:284:17: 284:33 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:284                 sfEvtKeyReleased => {
                                        ^~~~~~~~~~~~~~~~
src\window\event.rs:314:17: 314:41 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:314                 sfEvtMouseButtonReleased => super::MouseButtonReleased { button: button, x: x, y
: y },
                                        ^~~~~~~~~~~~~~~~~~~~~~~~
src\window\event.rs:315:17: 315:40 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:315                 sfEvtMouseButtonPressed => super::MouseButtonPressed { button: button, x: x, y:
y },
                                        ^~~~~~~~~~~~~~~~~~~~~~~
src\window\event.rs:340:17: 340:43 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:340                 sfEvtJoystickButtonPressed =>
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~
src\window\event.rs:342:17: 342:44 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:342                 sfEvtJoystickButtonReleased =>
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
src\window\event.rs:353:17: 353:39 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:353                 sfEvtJoystickConnected => super::JoystickConnected { joystickid: jid },
                                        ^~~~~~~~~~~~~~~~~~~~~~
src\window\event.rs:354:17: 354:42 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:354                 sfEvtJoystickDisconnected => super::JoystickDisconnected { joystickid: jid},
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~
src\window\event.rs:364:13: 364:24 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:364             sfEvtClosed => super::Closed,
                                    ^~~~~~~~~~~
src\window\event.rs:365:13: 365:25 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:365             sfEvtResized => event.size(),
                                    ^~~~~~~~~~~~
src\window\event.rs:366:13: 366:27 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:366             sfEvtLostFocus => super::LostFocus,
                                    ^~~~~~~~~~~~~~
src\window\event.rs:367:13: 367:29 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:367             sfEvtGainedFocus => super::GainedFocus,
                                    ^~~~~~~~~~~~~~~~
src\window\event.rs:368:13: 368:29 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:368             sfEvtTextEntered => event.text(),
                                    ^~~~~~~~~~~~~~~~
src\window\event.rs:369:13: 369:28 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:369             sfEvtKeyPressed => event.key(_type),
                                    ^~~~~~~~~~~~~~~
src\window\event.rs:370:13: 370:29 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:370             sfEvtKeyReleased => event.key(_type),
                                    ^~~~~~~~~~~~~~~~
src\window\event.rs:371:13: 371:33 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:371             sfEvtMouseWheelMoved => event.mouse_wheel(),
                                    ^~~~~~~~~~~~~~~~~~~~
src\window\event.rs:372:13: 372:36 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:372             sfEvtMouseButtonPressed => event.mouse_button(_type),
                                    ^~~~~~~~~~~~~~~~~~~~~~~
src\window\event.rs:373:13: 373:37 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:373             sfEvtMouseButtonReleased => event.mouse_button(_type),
                                    ^~~~~~~~~~~~~~~~~~~~~~~~
src\window\event.rs:374:13: 374:28 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:374             sfEvtMouseMoved => event.mouse_move(),
                                    ^~~~~~~~~~~~~~~
src\window\event.rs:375:13: 375:30 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:375             sfEvtMouseEntered => super::MouseLeft,
                                    ^~~~~~~~~~~~~~~~~
src\window\event.rs:376:13: 376:27 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:376             sfEvtMouseLeft => super::MouseEntered,
                                    ^~~~~~~~~~~~~~
src\window\event.rs:377:13: 377:39 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:377             sfEvtJoystickButtonPressed => event.joystick_button(_type),
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
src\window\event.rs:378:13: 378:40 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:378             sfEvtJoystickButtonReleased => event.joystick_button(_type),
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
src\window\event.rs:379:13: 379:31 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:379             sfEvtJoystickMoved => event.joystick_move(),
                                    ^~~~~~~~~~~~~~~~~~
src\window\event.rs:380:13: 380:35 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:380             sfEvtJoystickConnected => event.joystick_connect(_type),
                                    ^~~~~~~~~~~~~~~~~~~~~~
src\window\event.rs:381:13: 381:38 error: static variables cannot be referenced in a pattern, use a `const` instead
src\window\event.rs:381             sfEvtJoystickDisconnected => event.joystick_connect(_type),
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 26 previous errors
Could not compile `rust-sfml`.

To learn more, run the command again with --verbose.

Ensure safety of resources (images, fonts, audio buffers)

Right now it is possible to load an image, create a sprite that uses that image and then drop that image. The result is an useless sprite in the best case. While this is the behavior in C/C++, Rust can do better. I can think of these solutions:

  1. Use garbage collection for these resources. This would be pretty restraining and un-rusty though.
  2. Force a texture to be present at sprite creation and use lifetimes to make sure that texture stays valid. This would however make it impossible to change the texture at runtime. Alternatively, the ability to swap out textures and to create sprites with no lifetime constraints could be marked unsafe.
  3. Ignore the problem. But when these compile-time features are unused one might as well go back to writing C/C++.

Rc<RefCell<View>>

Since I'm using an rc RenderStates, trying to create a view with a regular View is impossible. I can create a Rc<RefCell> , but as it is not a standard View, I cannot access any of View's methods.

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
    • 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

Evaluate cases of unused struct fields and non-camel-case types outside of ffi module

In 696aaa3 and 4a03e33, I moved the global allow directive for dead_code and non_camel_case_types to the ffi module.

These are the current cases rustc warns about:

src/window/window.rs:52:5: 52:22 warning: struct field is never used: `title_length`, #[warn(dead_code)] on by default
src/window/window.rs:52     title_length: u32
                            ^~~~~~~~~~~~~~~~~
src/window/window.rs:58:5: 58:31 warning: struct field is never used: `event`, #[warn(dead_code)] on by default
src/window/window.rs:58     event: event::raw::sfEvent,
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~
src/window/event.rs:168:5: 168:40 warning: type `sfKeyCode` should have a camel case name such as `Sfkeycode`, #[warn(non_camel_case_types)] on by default
src/window/event.rs:168     pub type sfKeyCode = ::libc::c_int;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/window/event.rs:170:5: 170:45 warning: type `sfMouseButton` should have a camel case name such as `Sfmousebutton`, #[warn(non_camel_case_types)] on by default
src/window/event.rs:170     pub type sfMouseButton = ::libc::c_uint;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/window/event.rs:171:5: 171:46 warning: type `sfJoystickAxis` should have a camel case name such as `Sfjoystickaxis`, #[warn(non_camel_case_types)] on by default
src/window/event.rs:171     pub type sfJoystickAxis = ::libc::c_uint;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/window/event.rs:173:5: 173:43 warning: type `sfEventType` should have a camel case name such as `Sfeventtype`, #[warn(non_camel_case_types)] on by default
src/window/event.rs:173     pub type sfEventType = ::libc::c_uint;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/graphics/render_window.rs:63:5: 63:31 warning: struct field is never used: `event`, #[warn(dead_code)] on by default
src/graphics/render_window.rs:63     event: event::raw::sfEvent,
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~

We should evaluate each case individually, and either fix it, or if it's justified, explicitly mark the individual case as allow.

Lifetime in `Iterator` impl for `Vertices` is not constrained

impl<'s> Iterator for Vertices {
does not compile on latest nightly:

src/graphics/vertex_array.rs:256:6: 256:8 error: the lifetime parameter `'s` is not constrained by the impl trait, self type, or predicates [E0207]
src/graphics/vertex_array.rs:256 impl<'s> Iterator for Vertices {
                                      ^~

I talked to people on #rust, and they are telling me that it was a bug that this compiled before, and this code is memory-unsafe.

We must either constrain the lifetime in a way to be memory-safe, or return raw pointers instead of references.

/cc @jeremyletang

Pong example crashes

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5aeac8e in sf::Shader::bind(sf::Shader const*) ()
   from /usr/lib/libsfml-graphics.so.2.2.0
(gdb) bt
#0  0x00007ffff5aeac8e in sf::Shader::bind(sf::Shader const*) ()
   from /usr/lib/libsfml-graphics.so.2.2.0
#1  0x00007ffff5aea596 in sf::RenderTarget::draw(sf::Vertex const*, unsigned int, sf::PrimitiveType, sf::RenderStates const&) () from /usr/lib/libsfml-graphics.so.2.2.0
#2  0x00007ffff5af3a3c in sf::VertexArray::draw(sf::RenderTarget&, sf::RenderStates) const ()
   from /usr/lib/libsfml-graphics.so.2.2.0
#3  0x00007ffff5ae9e39 in sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&) ()
   from /usr/lib/libsfml-graphics.so.2.2.0
#4  0x00007ffff5af388c in sf::Text::draw(sf::RenderTarget&, sf::RenderStates) const ()
   from /usr/lib/libsfml-graphics.so.2.2.0
#5  0x00007ffff5ae9e39 in sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&) ()
   from /usr/lib/libsfml-graphics.so.2.2.0
#6  0x00007ffff75bb47c in sfRenderWindow_drawText () from /usr/lib/libcsfml-graphics.so.2.2
#7  0x00005555555769af in sfml::graphics::render_window::RenderWindow.RenderTarget::draw_text (
    self=0x7fffffffe320, text=0x7fffffffdf98, render_states=0x7fffffffd630)
    at src/graphics/render_window.rs:764
#8  0x00005555555601ba in pong::graphics::text::Text<'s>.Drawable::draw<sfml::graphics::render_window::RenderWindow> (self=0x7fffffffdf98, render_target=0x7fffffffe320, render_states=0x7fffffffd630)
    at src/graphics/text/mod.rs:329
#9  0x0000555555560161 in pong::graphics::render_window::RenderWindow.RenderTarget::draw<sfml::graphics::text::Text> (self=0x7fffffffe320, object=0x7fffffffdf98) at src/graphics/render_window.rs:734
#10 0x000055555555e684 in pong::main () at examples/pong.rs:243
#11 0x0000555555583489 in rust_try_inner ()
#12 0x0000555555583476 in rust_try ()
#13 0x0000555555580b44 in rt::lang_start::h35b1454095097ebdvFw ()
#14 0x0000555555560305 in main ()

Implement RenderStates

Hello! I'm looking at implementing RenderStates so I can texture my VertexArrays, but not too sure about the best way to go about it is.

Currently I am thinking to update RenderWindow's draw_vertex_array function to the following (plus the logic of course):

    /// Draw a VertexArray
    pub fn draw_vertex_array(&self, vertexArray : &VertexArray, render_states: Option<&RenderStates>) -> () {

I also think the RenderStates functionality could be better like this, considering the texture and shader fields are optional in SFML:

pub struct RenderStates {
    blendMode: BlendMode,
    transform: @Transform,
    texture: Option<@Texture>,
    shader: Option<@Shader>
}

But to make this useful I think I'll have to update the Drawable trait to also take an Option argument? Before I go and update the entire library I just wanted to see if you had any ideas or plans for this functionality?

Migrate to a bitflags version that uses associated consts, once available

See: bitflags/bitflags#21

Constants being associated with their type make for much nicer discoverability in the documentation than the current solution putting the various constants in a module. Right now when the user clicks on e.g. TextStyle in the documentation, it doesn't list the available text styles. We also have to expose the text_style module, when otherwise we could just expose only the TextStyle type.

Putting rust-ci token on travis fails

The rust-ci status for rust-sfml doesn't seem to be updating.
It's probably because of this in the travis build output:

$ curl http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    27  100    27    0     0     28      0 --:--:-- --:--:-- --:--:--    33
sh: 1: Syntax error: "(" unexpected

Window Border in Windows

Hi,
It's me again. I'm glad that sfml works properly on windows seven but the border window of the example is like a windows 98 (aero theme not loaded ?). We're in 2014, and i hope you know how i can forget this old border...

Regards.

"Not enough storage is available to process this command." on Windows 7

I'm running Windows 7 64-bit with 32gb of RAM and over 40gb of available disk space. I've copied the SFML and CSFML files over to MinGW and am running the latest Rust 0.10-pre-nightly installed less than an hour ago. When I run make rsfml I get the following error:

task 'rustc' failed at 'failed to print diagnostics: unknown error (OS Error 8: Not enough storage is available to process this command.)', c:\bot\slave\nightly-win\build\src\libsyntax\diagnostic.rs:267

I've looked around online and found some references to this error that involved messing around in the registry. I've tried all of them with no luck so far. I can build my own simple projects just fine so it's not a general purpose "rust is completely broken" issue.

Many of the references I've found to this error, including one on Microsoft's site, mention that this is common primarily when you have anti-virus but I'm not running any.

maybe replace IntRect / FloatRect to to Rect<T>

This will reflect the recent change on Vector2f/Vector2i/Vector2u/Vector2<T>.
The difference is that IntRect / FloatRect have two methods: contains and intersect. We may need to reeimplement them.

Event::MouseEntered and MouseLeft are swapped

In src/window/event.rs line 393:

            sfEvtMouseEntered => super::MouseLeft,
            sfEvtMouseLeft => super::MouseEntered,

So I get a MouseEntered event when the mouse leaves the window & vice versa.

Drawing vertices directly?

Does rust-sfml have the ability to draw vertices as in this example? The source is http://sfml-dev.org/documentation/2.1/classsf_1_1Vertex.php

// define a 100x100 square, red, with a 10x10 texture mapped on it
sf::Vertex vertices[] =
{
    sf::Vertex(sf::Vector2f( 0, 0), sf::Color::Red, sf::Vector2f( 0, 0)),
    sf::Vertex(sf::Vector2f( 0, 100), sf::Color::Red, sf::Vector2f( 0, 10)),
    sf::Vertex(sf::Vector2f(100, 100), sf::Color::Red, sf::Vector2f(10, 10)),
    sf::Vertex(sf::Vector2f(100, 0), sf::Color::Red, sf::Vector2f(10, 0))
};
// draw it
window.draw(vertices, 4, sf::Quads);

Segmentation fault on window change

This bug just popped up where if I run my program, then click off of the main window to the console window, the program segfaults almost immediately. I posted an issue in the rust repo, but they wanted to make sure it's not an SFML issue. I'm not certain if this is an SFML problem or a problem with my code as it doesn't seem to repro on test programs. Also, I'm running OS X Mavericks. Here's a paste of the log I get back: http://pastebin.com/4AtNFacV

Repro steps:

Error: unresolved name `window_style::CLOSE` in examples

The examples tell you to do this to open a window:

use sfml::graphics::{RenderWindow};
use sfml::window::{ContextSettings, VideoMode, window_style};

...

let mut window = match RenderWindow::new(
  VideoMode::new_init(800, 600, 32),
  "SFML Example",
  window_style::CLOSE,
  &ContextSettings::default()) {
    Some(window) => window,
    None => panic!("Cannot create a new Render Window.")
};

But this throws an error: unresolved name window_style::CLOSE.

Using rustc 1.6.0-beta.3.

Clarify license in Cargo.toml

When I tried to publish an update to crates.io, it complained about missing license/license-file, and didn't let me publish. So I put a license-file attribute that points to LICENSE.txt, but now the license field on the crates.io page says "non-standard".
Previously, it said "zlib-acknowledgment". Is that the correct license? If so, it should be put in the license field of Cargo.toml.

/cc @jeremyletang

refactor transform

Transform is implemented in an ugly way for now. We may need to use a slice to replace internal of the structure.

unable to build on archLinux 64-bit

Hello!

I've tried to build this by running rustpkg build rsfml. Unfortunately, It's failing, Here's the error log:

WARNING: The Rust package manager is experimental and may be unstable
/home/bollu/tmp/rust-sfml/src/rsfml/lib.rs:1:0: 1:0 error: transmute called on types with different sizes: i8 (8 bits) to window::mouse::MouseButton (64 bits)
/home/bollu/tmp/rust-sfml/src/rsfml/lib.rs:1 /*
                                             ^
task <unnamed> failed at 'explicit failure', /build/rust/src/rust-0.8/src/libsyntax/diagnostic.rs:72
task <unnamed> failed at 'receiving on closed channel', /build/rust/src/rust-0.8/src/libstd/rt/comm.rs:188

I'm using the rust-0.8.1 compiler. Here's theoutput of rust --version and rustpkg --version:

❯ rust --version
rust-sfml/git/master
rust 0.8
host: x86_64-unknown-linux-gnu
 rustpkg --version
WARNING: The Rust package manager is experimental and may be unstable
rustpkg 0.8
host: x86_64-unknown-linux-gnu

I'm really new to rust, so I'd like some help building this.

Thanks!

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.

Can't compile the library

Hi,
I begin with rust-lang and I can't compile the SFML rust library...
I'm using Windows 7 (x64) with 32 bits rust and MinGw.

C:\Users\Blblbl\rust-sfml-master>rustc src/rsfml/lib.rs
src\rsfml\graphics\render_window.rs:117:32: 117:39 error: instantiating a type p
arameter with an incompatible type `std::cell::RefCell<graphics::view::View>`, w
hich does not fulfill `Freeze`
src\rsfml\graphics\render_window.rs:117                 let def_view = Rc::new(R
efCell::new(Wrappable::wrap(raw_def_view)));
                                                                       ^~~~~~~
src\rsfml\graphics\render_window.rs:176:32: 176:39 error: instantiating a type p
arameter with an incompatible type `std::cell::RefCell<graphics::view::View>`, w
hich does not fulfill `Freeze`
src\rsfml\graphics\render_window.rs:176                 let def_view = Rc::new(R
efCell::new(Wrappable::wrap(raw_def_view)));
                                                                       ^~~~~~~
error: aborting due to 2 previous errors
task 'rustc' failed at 'explicit failure', C:\bot\slave\dist2-win\build\src\libs
yntax\diagnostic.rs:75
task '<main>' failed at 'explicit failure', C:\bot\slave\dist2-win\build\src\lib
rustc\lib.rs:453

Regards.

rust-sfml won't compile with rust nightly

The problem is in graphics::vertex_array:

impl Index<uint, Vertex> for VertexArray {
    fn index<'s>(&'s self, _rhs: &uint) -> &'s Vertex {
        unsafe {
            mem::transmute::<*const Vertex, &'s Vertex>
                (ffi::sfVertexArray_getVertex(self.vertex_array,
                                              *_rhs as c_uint) as *const Vertex)
        }
    }
}

The method 'index' has an incompatible return type: expected Vertex but found &Vertex.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.