create window, fill black

This commit is contained in:
Dan Ballard 2020-12-28 01:32:17 -08:00
parent c8ca06b710
commit 3e17b1b5e2
5 changed files with 1412 additions and 3 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target
.idea/

1338
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
[package]
name = "microworlds-rs"
name = "microworlds"
version = "0.1.0"
authors = ["Dan Ballard <dan@mindstab.net>"]
edition = "2018"
@ -7,3 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
piston = "0.52.0"
piston2d-graphics = "0.39.0"
pistoncore-glutin_window = "0.67.0"
piston2d-opengl_graphics = "0.76.0"

0
src/lib.rs Normal file
View File

View File

@ -1,3 +1,69 @@
fn main() {
println!("Hello, world!");
extern crate glutin_window;
extern crate graphics;
extern crate opengl_graphics;
extern crate piston;
use glutin_window::GlutinWindow as Window;
use opengl_graphics::{GlGraphics, OpenGL};
use piston::event_loop::{EventSettings, Events};
use piston::input::{RenderArgs, RenderEvent, UpdateArgs, UpdateEvent};
use piston::window::WindowSettings;
pub struct App {
gl: GlGraphics,
steps_per_sec: u32,
}
impl App {
fn render (&mut self, args: &RenderArgs) {
use graphics::*;
const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 1.0];
self.gl.draw(args.viewport(), |c, gl| {
// Clear the screen.
clear(BLACK, gl);
});
}
fn update(&mut self, args: &UpdateArgs) {
}
}
fn main() {
// Make window
// Change this to OpenGL::V2_1 if not working.
let opengl = OpenGL::V3_2;
// Create an Glutin window.
let mut window: Window = WindowSettings::new("spinning-square", [800, 800])
.graphics_api(opengl)
.exit_on_esc(true)
.build()
.unwrap();
let mut app = App {
gl: GlGraphics::new(opengl),
steps_per_sec: 2,
};
let mut events = Events::new(EventSettings::new());
// Make grid
// Quick life engine -> redraw
let mut events = Events::new(EventSettings::new());
while let Some(e) = events.next(&mut window) {
if let Some(args) = e.render_args() {
app.render(&args);
}
if let Some(args) = e.update_args() {
app.update(&args);
}
}
}