Draw SDL2 window
parent
a9024dde9c
commit
6b6dd344bf
|
@ -2,6 +2,62 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.131"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "04c3b4822ccebfa39c02fc03d1534441b22ead323fa0f48bb7ddd8e6ba076a40"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "medit"
|
name = "medit"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"sdl2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sdl2"
|
||||||
|
version = "0.35.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f7959277b623f1fb9e04aea73686c3ca52f01b2145f8ea16f4ff30d8b7623b1a"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"lazy_static",
|
||||||
|
"libc",
|
||||||
|
"sdl2-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sdl2-sys"
|
||||||
|
version = "0.35.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3586be2cf6c0a8099a79a12b4084357aa9b3e0b0d7980e3b67aaf7a9d55f9f0"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"version-compare",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version-compare"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73"
|
||||||
|
|
|
@ -6,3 +6,4 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
sdl2 = "0.35.2"
|
||||||
|
|
105
flake.lock
105
flake.lock
|
@ -1,87 +1,5 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"crane": {
|
|
||||||
"flake": false,
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1654444508,
|
|
||||||
"narHash": "sha256-4OBvQ4V7jyt7afs6iKUvRzJ1u/9eYnKzVQbeQdiamuY=",
|
|
||||||
"owner": "ipetkov",
|
|
||||||
"repo": "crane",
|
|
||||||
"rev": "db5482bf225acc3160899124a1df5a617cfa27b5",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "ipetkov",
|
|
||||||
"repo": "crane",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"devshell": {
|
|
||||||
"flake": false,
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1658746384,
|
|
||||||
"narHash": "sha256-CCJcoMOcXyZFrV1ag4XMTpAPjLWb4Anbv+ktXFI1ry0=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "devshell",
|
|
||||||
"rev": "0ffc7937bb5e8141af03d462b468bd071eb18e1b",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "devshell",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dream2nix": {
|
|
||||||
"inputs": {
|
|
||||||
"alejandra": [
|
|
||||||
"nci",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"crane": "crane",
|
|
||||||
"devshell": [
|
|
||||||
"nci",
|
|
||||||
"devshell"
|
|
||||||
],
|
|
||||||
"flake-utils-pre-commit": [
|
|
||||||
"nci",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"gomod2nix": [
|
|
||||||
"nci",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"mach-nix": [
|
|
||||||
"nci",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"nixpkgs": [
|
|
||||||
"nci",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"poetry2nix": [
|
|
||||||
"nci",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"pre-commit-hooks": [
|
|
||||||
"nci",
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1660322711,
|
|
||||||
"narHash": "sha256-Q7im8L9UEVs448V4dv4XdCZy5yFfO1J+KpBi8O9Fe4o=",
|
|
||||||
"owner": "nix-community",
|
|
||||||
"repo": "dream2nix",
|
|
||||||
"rev": "9331fb1376068e24f0ab5080aec85f43a369ebdb",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-community",
|
|
||||||
"repo": "dream2nix",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-parts": {
|
"flake-parts": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
|
@ -117,28 +35,23 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nci": {
|
"naersk": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"devshell": "devshell",
|
|
||||||
"dream2nix": "dream2nix",
|
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
],
|
|
||||||
"rust-overlay": [
|
|
||||||
"rust"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1660543949,
|
"lastModified": 1659610603,
|
||||||
"narHash": "sha256-dnKsU4qMXzbOaWRFQ9W2f5gOCXMtqo2ZRSugdNs/80s=",
|
"narHash": "sha256-LYgASYSPYo7O71WfeUOaEUzYfzuXm8c8eavJcel+pfI=",
|
||||||
"owner": "yusdacra",
|
"owner": "nix-community",
|
||||||
"repo": "nix-cargo-integration",
|
"repo": "naersk",
|
||||||
"rev": "670586d5d3a2a786fa2adfc4273b4419206c1e78",
|
"rev": "c6a45e4277fa58abd524681466d3450f896dc094",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "yusdacra",
|
"owner": "nix-community",
|
||||||
"repo": "nix-cargo-integration",
|
"repo": "naersk",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -161,7 +74,7 @@
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-parts": "flake-parts",
|
"flake-parts": "flake-parts",
|
||||||
"nci": "nci",
|
"naersk": "naersk",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"rust": "rust"
|
"rust": "rust"
|
||||||
}
|
}
|
||||||
|
|
37
flake.nix
37
flake.nix
|
@ -9,25 +9,38 @@
|
||||||
rust.url = "github:oxalica/rust-overlay";
|
rust.url = "github:oxalica/rust-overlay";
|
||||||
rust.inputs.nixpkgs.follows = "nixpkgs";
|
rust.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
||||||
nci.url = "github:yusdacra/nix-cargo-integration";
|
naersk.url = "github:nix-community/naersk";
|
||||||
nci.inputs.nixpkgs.follows = "nixpkgs";
|
naersk.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
nci.inputs.rust-overlay.follows = "rust";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, flake-parts, ... }@inputs:
|
outputs = { self, flake-parts, nixpkgs, naersk, rust }:
|
||||||
|
let
|
||||||
|
overlays = [ rust.overlays.default ];
|
||||||
|
in
|
||||||
flake-parts.lib.mkFlake { inherit self; } {
|
flake-parts.lib.mkFlake { inherit self; } {
|
||||||
imports = [{
|
imports = [{
|
||||||
config.perSystem = { system, ... }: {
|
config.perSystem = { system, ... }: {
|
||||||
config._module.args.pkgs = (import inputs.nixpkgs {
|
config._module.args.pkgs = import nixpkgs { inherit system overlays; };
|
||||||
inherit system;
|
|
||||||
overlays = [ inputs.rust.overlays.default ];
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}];
|
}];
|
||||||
systems = inputs.nixpkgs.lib.systems.flakeExposed;
|
systems = nixpkgs.lib.systems.flakeExposed;
|
||||||
perSystem = { config, self', inputs', pkgs, system, ... }: { };
|
perSystem = { config, self', inputs', pkgs, system, ... }:
|
||||||
flake = inputs.nci.lib.makeOutputs {
|
let
|
||||||
root = ./.;
|
toolchain = pkgs.rust-bin.stable.latest.default;
|
||||||
|
naersk-lib = pkgs.callPackage naersk {
|
||||||
|
cargo = toolchain;
|
||||||
|
rustc = toolchain;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages.default = naersk-lib.buildPackage {
|
||||||
|
src = ./.;
|
||||||
|
buildInputs = with pkgs; [ SDL2 ];
|
||||||
|
};
|
||||||
|
apps.default.program = "${config.packages.default}/bin/medit";
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
nativeBuildInputs = [ toolchain ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -1,3 +1,36 @@
|
||||||
|
use sdl2::{event::Event, init, keyboard::Keycode, pixels::Color};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
let ctx = init().unwrap();
|
||||||
|
let vid = ctx.video().unwrap();
|
||||||
|
let win = vid
|
||||||
|
.window("medit", 800, 600)
|
||||||
|
.position_centered()
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
let mut can = win.into_canvas().build().unwrap();
|
||||||
|
can.set_draw_color(Color::RGB(0, 255, 255));
|
||||||
|
can.clear();
|
||||||
|
can.present();
|
||||||
|
let mut event_pump = ctx.event_pump().unwrap();
|
||||||
|
let mut i = 0;
|
||||||
|
'running: loop {
|
||||||
|
i = (i + 1) % 255;
|
||||||
|
can.set_draw_color(Color::RGB(i, 64, 255 - i));
|
||||||
|
can.clear();
|
||||||
|
for event in event_pump.poll_iter() {
|
||||||
|
match event {
|
||||||
|
Event::Quit { .. }
|
||||||
|
| Event::KeyDown {
|
||||||
|
keycode: Some(Keycode::Escape),
|
||||||
|
..
|
||||||
|
} => break 'running,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The rest of the game loop goes here...
|
||||||
|
|
||||||
|
can.present();
|
||||||
|
std::thread::sleep(std::time::Duration::new(0, 1_000_000_000u32 / 60));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue