A modular game engine written in Rust.
Questions tagged [rust-piston]
34 questions
17
votes
1 answer
How do I stop Piston from making the screen flash when I don't call `graphics::clear` every time the screen is rendered?
Consider two programs, and the difference between them:
$ diff flashes/src/main.rs doesnt_flash/src/main.rs
22,23c22
<
< let mut i = 0;
---
> let mut cursor_poses: Vec<(f64, f64)> = Vec::new();
28c27
< mx = x; my = y;
---
> …

Fredrick Brennan
- 7,079
- 2
- 30
- 61
8
votes
1 answer
error[E0658]: `cfg(doctest)` is experimental and subject to change
I am relatively new to rust and I was trying to build a game using an online tutorial when I encountered this error. Can someone please tell me what this error is and how to solve it?
I switched from stable rust version to nightly using rustup…

Dennis Moncy
- 141
- 4
6
votes
3 answers
How do I encode a Rust Piston image and get the result in memory?
I am using the Piston image package to generate images.
fn get_image() -> image::DynamicImage {
image::DynamicImage::ImageRgba8(image::ImageBuffer::new(512, 512))
}
I have a hyper web server, from which I would like to serve…

Jeremy
- 1
- 85
- 340
- 366
5
votes
1 answer
Why does Piston text() require a mutable reference to the glyph cache?
I'm curious why text() takes a mutable borrow of the glyph cache:
cache: &mut C
My understanding is that the glyphe cache represented the static characters (glyphs) loaded from the font file. Why would those need to be able to be mutated by the…

phoenix
- 7,988
- 6
- 39
- 45
4
votes
1 answer
How to create a fullscreen window using piston?
I was trying to create an application that opens a full-screen window using the piston crate.
How can I retrieve the physical screen size in pixels programmatically? It seems an easy thing to do, but I was not able to figure that out.
extern crate…

Jimmy Hypi
- 43
- 4
4
votes
0 answers
Making piston_window transparent
I am currently trying to use piston_window and just need to know how to make my piston_window transparent. I know that glutin_window supports with_transparency on it's window builder, but I don't know how I could set that.
Relevant code:
extern…

Scrumplex
- 522
- 1
- 6
- 15
3
votes
1 answer
Rendering text in a separate function using piston2d in rust
I am trying to render text in a separate function using piston2d / piston_window. I am able to draw text just fine, but I can't figure out how to pass the appropriate parameters into a separate function.
I have studied What is GlyphCache type in a…

Johann Woelper
- 43
- 5
3
votes
1 answer
What is the idiomatic way in Rust to store a collection of objects to be used as Piston textures or sprites?
All the examples I've seen for getting access to a texture object is to do something like the following:
let img = Texture::from_path(...)
This gives the impression that in order to have an array of textures it should be something like let mut…

tamato
- 838
- 7
- 15
2
votes
1 answer
How to change the cursor icon in Piston2D / PistonWindow / GlutinWindow?
Like Normal, Busy or Text Select. I want to create a desktop Windows applcation and I need to change its icon.

USSURATONCAHI
- 75
- 7
2
votes
1 answer
Attempted to leave type `PointerState` uninitialized
I wanted to try to make a game in Rust using Piston. This is the first time I have used this library. I took this code from the official doc to test it. However, when my mouse touches the application window it closes immediately and I don’t…

Zenmoa
- 31
- 5
2
votes
2 answers
How to convert Vec> to Vec
Using the Piston image crate, I can write an image by feeding it a Vec, but my actual data is Vec> (because that is a lot easier to deal with, and I want to grow it dynamically).
How can I convert Vec> to Vec? Rgb is…

Timmmm
- 88,195
- 71
- 364
- 509
2
votes
0 answers
Why does it seem like Piston's position (0, 0) is halfway down the window on the left?
I'm hitting what I assume is a pretty basic misunderstanding of how to draw things using the Rust Piston library. Here is the main function I'm working with, mostly copied from beginner tutorials.
extern crate piston_window;
use…

Silvio Mayolo
- 62,821
- 6
- 74
- 116
2
votes
1 answer
What is GlyphCache type in a function to render text in Piston2d
I am trying to write a separate function to render text using piston2d. Taking the hello_world.rs example, I am trying to extend that to allow me to render text from within a function.
Here is the code that I wrote:
extern crate…

Samarth Hattangady
- 696
- 1
- 7
- 10
2
votes
0 answers
How to draw primitives in a texture?
When I want to draw some primitives in Piston, I do something like that:
let gl = &mut GlGraphics::new(OpenGL::V3_2);
gl.draw(viewport, |context, gl| {
Rectangle::new([1., 1., 1., 1.])
.draw([0., 0., 10., 20.], &context.draw_state,…

Boiethios
- 38,438
- 19
- 134
- 183
1
vote
0 answers
Wrong timing in physics simulation with piston
I have written a very basic simulation of a pendulum. I used the equation α = -g/l * sin(φ). I set g/l to 50, so I expect to get a period of 0.89 seconds (Using the formula 2π*√(l/g)). However, I get a period of around 6.5 seconds. The relevant code…

ismxy
- 21
- 3