Comments (6)
Use window.draw_size()
.
from gfx_graphics.
@bvssvni the problem is not the draw size (both window.draw_size()
and c.get_view_size()
change as I resize the window). The problem persists anyways.
from gfx_graphics.
Here is the fixed code:
extern crate piston_window;
extern crate sdl2_window;
use piston_window::*;
use sdl2_window::Sdl2Window;
fn main() {
let mut window: PistonWindow<Sdl2Window> =
WindowSettings::new("Resize bug", [640, 480])
.exit_on_esc(true)
.build()
.unwrap();
while let Some(e) = window.next() {
let size = window.size();
window.draw_2d(&e, |c, g| {
clear([0.0, 0.0, 0.0, 1.0], g);
let (w, h) = (size.width as f64, size.height as f64);
rectangle(
[0.1, 0.6, 0.3, 1.0],
[0.0, 0.0, w/2.0, h/2.0],
c.transform, g
);
rectangle(
[0.1, 0.6, 0.3, 1.0],
[w/2.0, h/2.0, w/2.0, h/2.0],
c.transform, g
);
});
}
}
- piston is reexported in piston_window, so you do not need both
- call
window.next()
since it does proper cleanup and resizes the frame targets
from gfx_graphics.
The window.next() instead of .events() fixed it, thanks!
from gfx_graphics.
Thanks @bvssvni !
from gfx_graphics.
@bvssvni Thanks! That's great that this works. Although it seems the tutorials and examples could use some updating as some of them use events.next() currently.
from gfx_graphics.
Related Issues (20)
- Correct gamma HOT 4
- Improve performance for colored graphics HOT 3
- Use alpha bit method from Gfx in `has_texture_alpha`
- Convert color to sRGB when drawing glyph HOT 3
- Old graphics cards does not support sRGB conversion HOT 1
- Make `Gfx2d::draw` take closure with generic return type
- Use the new shader output names convention
- Make `GfxGraphics::encoder` public HOT 1
- Use of undeclared type or module `gfx`
- warning: `$crate` may not be imported HOT 3
- Compile error: error[E0432]: unresolved import `` HOT 2
- Breakage in Rust 1.15 Beta HOT 4
- GlyphCache constructor should take in-memory font
- glyph::Error is not std:error::Error HOT 5
- Clipped image not showing up in "draw_state" example
- Can't treat gfx_graphics as Graphics HOT 5
- Cannot compile due to stb_truetype 0.2.5 HOT 5
- `Stencil::Increment` does not seem to work.
- Scissor width and height are not proportional to scale_factor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gfx_graphics.