From c0ce496ce0b2cd3f535333fd507d7756dfa04d83 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sat, 27 Jul 2019 14:43:29 -0500 Subject: [PATCH] actually draw the level --- Cargo.lock | 246 +++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 7 +- levels/tutorial.json | 52 ++++++++- shaders/cell.frag | 18 +++- shaders/cell.vert | 4 +- shaders/segment.frag | 11 ++ shaders/segment.vert | 13 +++ src/data.rs | 2 +- src/enums.rs | 18 +++- src/game.rs | 10 ++ src/level.rs | 40 ++++++- src/main.rs | 14 ++- src/renderer.rs | 181 +++++++++++++++++++++++++++---- src/resources.rs | 38 +++++++ textures/segment.png | Bin 0 -> 23287 bytes 15 files changed, 612 insertions(+), 42 deletions(-) create mode 100644 shaders/segment.frag create mode 100644 shaders/segment.vert create mode 100644 textures/segment.png diff --git a/Cargo.lock b/Cargo.lock index c9b1297..02b5c2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,10 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "adler32" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "alga" version = "0.9.1" @@ -150,6 +155,11 @@ dependencies = [ "objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "color_quant" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "core-foundation" version = "0.6.4" @@ -175,6 +185,54 @@ dependencies = [ "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-deque" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-queue" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "deflate" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "derivative" version = "1.0.2" @@ -206,6 +264,11 @@ name = "downcast-rs" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "either" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fake-simd" version = "0.1.2" @@ -242,6 +305,15 @@ dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "gif" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "color_quant 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "gl_generator" version = "0.11.0" @@ -340,6 +412,40 @@ dependencies = [ "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "image" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "gif 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "jpeg-decoder 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "png 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tiff 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "inflate" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "jpeg-decoder" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "json5" version = "0.2.5" @@ -404,6 +510,11 @@ dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lzw" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "malloc_buf" version = "0.0.6" @@ -434,6 +545,14 @@ dependencies = [ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "memoffset" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "nalgebra" version = "0.18.0" @@ -486,6 +605,45 @@ dependencies = [ "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "num-derive" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-integer" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-iter" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-rational" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num-traits" version = "0.2.8" @@ -494,6 +652,14 @@ dependencies = [ "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "num_cpus" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "objc" version = "0.2.6" @@ -601,6 +767,17 @@ name = "pkg-config" version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "png" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "deflate 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", + "inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "proc-macro2" version = "0.4.30" @@ -718,6 +895,28 @@ name = "rawpointer" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rayon" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rayon-core" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rdrand" version = "0.4.0" @@ -758,11 +957,21 @@ dependencies = [ "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "scopeguard" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "scopeguard" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "semver" version = "0.9.0" @@ -860,6 +1069,17 @@ name = "takeable-option" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "tiff" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "typenum" version = "1.10.0" @@ -949,6 +1169,7 @@ name = "wedge" version = "0.1.0" dependencies = [ "glium 0.25.1 (registry+https://github.com/rust-lang/crates.io-index)", + "image 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)", "json5 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "nalgebra 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", "nalgebra-glm 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1027,6 +1248,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] +"checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" "checksum alga 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d708cb68c7106ed1844de68f50f0157a7788c2909a6926fad5a87546ef6a4ff8" "checksum andrew 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9b7f09f89872c2b6b29e319377b1fbe91c6f5947df19a25596e121cf19a7b35e" "checksum android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407" @@ -1046,19 +1268,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "55e7ec0b74fe5897894cbc207092c577e87c52f8a59e8ca8d97ef37551f60a49" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cocoa 0.18.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cf79daa4e11e5def06e55306aa3601b87de6b5149671529318da048f67cdd77b" +"checksum color_quant 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd" "checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" "checksum core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" "checksum core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)" = "56790968ab1c8a1202a102e6de05fc6e1ec87da99e4e93e9a7d13efbfc1e95a9" +"checksum crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "05e44b8cf3e1a625844d1750e1f7820da46044ff6d28f4d43e455ba3e5bb2c13" +"checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9" +"checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" +"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" +"checksum deflate 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "707b6a7b384888a70c8d2e8650b3e60170dfc6a67bb4aa67b6dfca57af4bedb4" "checksum derivative 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6073e9676dbebdddeabaeb63e3b7cefd23c86f5c41d381ee1237cc77b1079898" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "77e51249a9d823a4cb79e3eca6dcd756153e8ed0157b6c04775d04bf1b13b76a" "checksum downcast-rs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b92dfd5c2f75260cbf750572f95d387e7ca0ba5e3fbe9e1a33f23025be020f" +"checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +"checksum gif 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "86c2f2b597d6e05c86ee5947b2223bda468fe8dad3e88e2a6520869322aaf568" "checksum gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39a23d5e872a275135d66895d954269cf5e8661d234eb1c2480f4ce0d586acbd" "checksum gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)" = "c8a455b5a3ccd35daeb89fdb8a89ebb0a1fe23c05c7a7f9017840bc3ae176f71" "checksum glium 0.25.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d7d887755ee729c5204e151db1c81b0b5beb809ef5e01d0eb14847e80a71256" @@ -1068,6 +1298,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum glutin_gles2_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "89996c30857ae1b4de4b5189abf1ea822a20a9fe9e1c93e5e7b862ff0bdd5cdf" "checksum glutin_glx_sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1290a5ca5e46fcfa7f66f949cc9d9194b2cb6f2ed61892c8c2b82343631dba57" "checksum glutin_wgl_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f801bbc91efc22dd1c4818a47814fc72bf74d024510451b119381579bfa39021" +"checksum image 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)" = "99198e595d012efccf12abf4abc08da2d97be0b0355a2b08d101347527476ba4" +"checksum inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff" +"checksum jpeg-decoder 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c8b7d43206b34b3f94ea9445174bda196e772049b9bddbc620c9d29b2d20110d" "checksum json5 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "85fb48cdfbe18a1ef5ce0a0edc30b8b8f61422f7073f709dd09311c2b3d2bba6" "checksum khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" @@ -1077,16 +1310,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5cc7ad3d82c845bdb5dde34ffdcc7a5fb4d2996e1e1ee0f19c33bc80e15196b9" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c275b6ad54070ac2d665eef9197db647b32239c9d244bfb6f041a766d00da5b3" +"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" "checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43" "checksum matrixmultiply 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfed72d871629daa12b25af198f110e8095d7650f5f4c61c5bac28364604f9b" "checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +"checksum memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6075db033bbbb7ee5a0bbd3a3186bbae616f57fb001c485c7ff77955f8177f" "checksum nalgebra 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e12856109b5cb8e2934b5e45e4624839416e1c6c1f7d286711a7a66b79db29d" "checksum nalgebra-glm 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f2c7f8b7093ddb95018d5f48ce453304c49b624d078cbeed157b8f0d45d9872f" "checksum nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum num-complex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fcb0cf31fb3ff77e6d2a6ebd6800df7fdcd106f2ad89113c9130bcd07f93dffc" +"checksum num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "eafd0b45c5537c3ba526f79d3e75120036502bebacbb3f3220914067ce39dbf2" +"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" +"checksum num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "76bd5272412d173d6bf9afdf98db8612bbabc9a7a830b7bfc9c188911716132e" +"checksum num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2885278d5fe2adc2f75ced642d52d879bffaceb5a2e0b1d4309ffdfb239b454" "checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" +"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" "checksum objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "31d20fd2b37e07cf5125be68357b588672e8cefe9a96f8c17a9d46053b3e590d" "checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" "checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" @@ -1100,6 +1340,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum pest_generator 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "63120576c4efd69615b5537d3d052257328a4ca82876771d6944424ccfd9f646" "checksum pest_meta 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f249ea6de7c7b7aba92b4ff4376a994c6dbd98fd2166c89d5c4947397ecb574d" "checksum pkg-config 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c1d2cfa5a714db3b5f24f0915e74fcdf91d09d496ba61329705dda7774d2af" +"checksum png 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "63daf481fdd0defa2d1d2be15c674fbfa1b0fd71882c303a91f9a79b3252c359" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" @@ -1113,12 +1354,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" "checksum rawpointer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ebac11a9d2e11f2af219b8b8d833b76b1ea0e054aa0e8d8e9e4cbde353bdf019" +"checksum rayon 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a4b0186e22767d5b9738a05eab7c6ac90b15db17e5b5f9bd87976dd7d89a10a4" +"checksum rayon-core 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ebbe0df8435ac0c397d467b6cad6d25543d06e8a019ef3f6af3c384597515bd2" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rusttype 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)" = "654103d61a05074b268a107cf6581ce120f0fc0115f2610ed9dfea363bb81139" "checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" +"checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" +"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)" = "d46b3dfedb19360a74316866cef04687cd4d6a70df8e6a506c63512790769b72" @@ -1131,6 +1376,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum stb_truetype 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "69b7df505db8e81d54ff8be4693421e5b543e08214bd8d99eb761fcb4d5668ba" "checksum syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)" = "eadc09306ca51a40555dd6fc2b415538e9e18bc9f870e47b1a524a79fe2dcf5e" "checksum takeable-option 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d77adff586b9bd922afef7791341ed94b09845e11225929217efe949e6366d43" +"checksum tiff 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1e4834f28a0330cb9f3f2c87d2649dca723cb33802e2bdcf18da32759fbec7ce" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-trie 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8f00ed7be0c1ff1e24f46c3d2af4859f7e863672ba3a6e92e7cff702bf9f06c2" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" diff --git a/Cargo.toml b/Cargo.toml index 200cb8b..e366645 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,9 @@ edition = "2018" [dependencies] glium = "0.25" -serde = "1.0" -serde_derive = "1.0" +image = "0.21" json5 = "0.2" nalgebra = "0.18" -nalgebra-glm = "0.4" \ No newline at end of file +nalgebra-glm = "0.4" +serde = "1.0" +serde_derive = "1.0" \ No newline at end of file diff --git a/levels/tutorial.json b/levels/tutorial.json index dd8c7e1..45035d0 100644 --- a/levels/tutorial.json +++ b/levels/tutorial.json @@ -13,13 +13,61 @@ "blocks": [ { "movable": true, - "push_dir": 0, + "orientation": 1, "position": [1, 3], "color": [255, 10, 100], "segments": [ [0, 0, 0, 0], [1, 0, 4, 0], ], - } + }, + { + "movable": true, + "orientation": 2, + "position": [2, 4], + "color": [105, 210, 50], + "segments": [ + [0, 0, 2, 0], + [0, 1, 0, 0], + ], + }, + { + "movable": true, + "orientation": 2, + "position": [0, 4], + "color": [35, 150, 100], + "segments": [ + [0, 0, 1, 1], + [0, 1, 0, 1], + ], + }, + { + "movable": true, + "orientation": 1, + "position": [0, 3], + "color": [25, 120, 10], + "segments": [ + [0, 0, 3, 1], + [1, 0, 0, 1], + ], + }, + { + "movable": false, + "orientation": 0, + "position": [0, 2], + "color": [15, 15, 15], + "segments": [ + [0, 0, 0, 0], + ], + }, + { + "movable": false, + "orientation": 0, + "position": [2, 2], + "color": [15, 15, 15], + "segments": [ + [0, 0, 0, 1], + ], + }, ] } \ No newline at end of file diff --git a/shaders/cell.frag b/shaders/cell.frag index 35b732c..7700db0 100644 --- a/shaders/cell.frag +++ b/shaders/cell.frag @@ -1,7 +1,21 @@ #version 330 -out vec4 color; +in vec4 pos; +out vec4 outcolor; + +uniform vec4 color; + +const float threshold = 0.05; + +const vec4 top = vec4(0.5, 0.5, 0.5, 1.0); +const vec4 bot = vec4(0.4, 0.4, 0.4, 1.0); void main() { - color = vec4(1.0, 1.0, 1.0, 1.0); + outcolor = 0.2 * (bot * (1 - pos.y) + top * (1 - pos.x)) + 0.2; + // if ((pos.x > -threshold && pos.x < threshold) + // || (pos.y > -threshold && pos.y < threshold) + // || (pos.x > 1.0-threshold && pos.x < 1.0+threshold) + // || (pos.y > 1.0-threshold && pos.y < 1.0+threshold)) { + // outcolor = vec4(0.0, 0.0, 0.0, 1.0); + // } } \ No newline at end of file diff --git a/shaders/cell.vert b/shaders/cell.vert index 104701f..096ac61 100644 --- a/shaders/cell.vert +++ b/shaders/cell.vert @@ -1,10 +1,12 @@ #version 330 in vec2 point; +out vec4 pos; uniform mat4 target; uniform mat4 projection; void main() { - gl_Position = projection * target * vec4(point, 0.0, 1.0); + pos = vec4(point, 0.0, 1.0); + gl_Position = projection * target * pos; } \ No newline at end of file diff --git a/shaders/segment.frag b/shaders/segment.frag new file mode 100644 index 0000000..4aa7c15 --- /dev/null +++ b/shaders/segment.frag @@ -0,0 +1,11 @@ +#version 330 + +in vec2 v_tex_coords; +out vec4 outcolor; + +uniform sampler2D tex; +uniform vec4 tint; + +void main() { + outcolor = tint * texture(tex, v_tex_coords); +} diff --git a/shaders/segment.vert b/shaders/segment.vert new file mode 100644 index 0000000..29ee2d5 --- /dev/null +++ b/shaders/segment.vert @@ -0,0 +1,13 @@ +#version 330 + +in vec2 pos; +in vec2 tex; +out vec2 v_tex_coords; + +uniform mat4 target; +uniform mat4 projection; + +void main() { + v_tex_coords = tex; + gl_Position = projection * target * vec4(pos, 0.0, 1.0); +} diff --git a/src/data.rs b/src/data.rs index 8e78029..e470d90 100644 --- a/src/data.rs +++ b/src/data.rs @@ -7,7 +7,7 @@ pub struct PlayerData { #[derive(Debug, Deserialize)] pub struct BlockData { pub movable: bool, - pub push_dir: u32, + pub orientation: u32, pub position: [u32; 2], pub color: [u32; 3], pub segments: Vec<[u32; 4]>, diff --git a/src/enums.rs b/src/enums.rs index f5abed4..1717b17 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -15,9 +15,21 @@ impl From for Board { } #[derive(Copy, Clone)] -pub enum MotionDir { - Horizontal, - Vertical, +pub enum Orientation { + Both = 0, + Horizontal = 1, + Vertical = 2, +} + +impl From for Orientation { + fn from(n: u32) -> Self { + match n { + 0 => Orientation::Both, + 1 => Orientation::Horizontal, + 2 => Orientation::Vertical, + _ => panic!("expecting 0..2, got {}", n), + } + } } #[derive(Copy, Clone)] diff --git a/src/game.rs b/src/game.rs index 90c31a1..2247358 100644 --- a/src/game.rs +++ b/src/game.rs @@ -6,9 +6,13 @@ use crate::level::Level; use crate::renderer::Renderer; use crate::resources::Resources; +const SEGMENT_VERT: &str = include_str!("../shaders/segment.vert"); +const SEGMENT_FRAG: &str = include_str!("../shaders/segment.frag"); const CELL_VERT: &str = include_str!("../shaders/cell.vert"); const CELL_FRAG: &str = include_str!("../shaders/cell.frag"); +const SEGMENT_IMAGE: &[u8] = include_bytes!("../textures/segment.png"); + const LEVEL_TUTORIAL: &str = include_str!("../levels/tutorial.json"); pub struct Game<'a> { @@ -21,6 +25,12 @@ pub struct Game<'a> { impl<'a> Game<'a> { pub fn new(display: &'a Display) -> Game { let mut resources = Resources::default(); + resources + .load_image_from_memory(display, "segment", &SEGMENT_IMAGE, false) + .unwrap(); + resources + .load_shader(display, "segment", &SEGMENT_VERT, &SEGMENT_FRAG) + .unwrap(); resources .load_shader(display, "cell", &CELL_VERT, &CELL_FRAG) .unwrap(); diff --git a/src/level.rs b/src/level.rs index 4d402ec..07d22eb 100644 --- a/src/level.rs +++ b/src/level.rs @@ -1,7 +1,7 @@ use std::collections::VecDeque; use crate::data::LevelData; -use crate::enums::{Board, Shape}; +use crate::enums::{Board, Orientation, Shape}; use crate::renderer::Renderer; use crate::{GAME_HEIGHT, GAME_WIDTH}; @@ -13,6 +13,9 @@ pub struct Level { #[derive(Clone)] pub struct Block { + position: (u32, u32), + color: (f32, f32, f32), + orientation: Orientation, segments: Vec, } @@ -28,6 +31,7 @@ impl Level { .blocks .iter() .map(|block| { + let position = (block.position[0], block.position[1]); let segments = block .segments .iter() @@ -35,7 +39,18 @@ impl Level { Segment(segment[0], segment[1], segment[2].into(), segment[3].into()) }) .collect(); - Block { segments } + let orientation = block.orientation.into(); + let color = ( + block.color[0] as f32 / 256.0, + block.color[1] as f32 / 256.0, + block.color[2] as f32 / 256.0, + ); + Block { + position, + color, + segments, + orientation, + } }) .collect(); @@ -70,6 +85,25 @@ impl Level { offset.1 + 2 * scale, ); - renderer.render_cell(left_off, 50, Shape::Full); + // render the grid + for x in 0..self.dimensions.0 { + for y in 0..self.dimensions.1 { + renderer.render_cell((left_off.0 + x * scale, left_off.1 + y * scale), scale); + renderer.render_cell((right_off.0 + x * scale, right_off.1 + y * scale), scale); + } + } + + // render blocks + for block in self.blocks.iter() { + for segment in block.segments.iter() { + let offset = match &segment.3 { + Board::Left => left_off, + Board::Right => right_off, + }; + let coord = (segment.0 + block.position.0, segment.1 + block.position.1); + let location = (offset.0 + coord.0 * scale, offset.1 + coord.1 * scale); + renderer.render_segment(location, scale, block.color, block.orientation, segment.2); + } + } } } diff --git a/src/main.rs b/src/main.rs index 23b9456..98137b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,10 +13,9 @@ mod resources; use std::time::Instant; -use glium::glutin::{ - dpi::PhysicalSize, ContextBuilder, Event, EventsLoop, WindowBuilder, WindowEvent, -}; -use glium::{Display, Rect}; +use glium::glutin::dpi::PhysicalSize; +use glium::glutin::{ContextBuilder, Event, EventsLoop, WindowBuilder, WindowEvent}; +use glium::{Display, Rect, Surface}; use crate::game::Game; @@ -36,6 +35,12 @@ fn main() { let cb = ContextBuilder::new(); let display = Display::new(wb, cb, &events_loop).unwrap(); + { + let gl_window = display.gl_window(); + let window = gl_window.window(); + println!("size: {:?}", window.get_inner_size()); + } + let game = Game::new(&display); let mut closed = false; @@ -53,6 +58,7 @@ fn main() { }); let mut target = display.draw(); + target.clear(None, Some((0.0, 0.0, 0.0, 1.0)), true, None, None); let mut renderer = game.create_renderer(&mut target); game.render(&mut renderer); target.finish().unwrap(); diff --git a/src/renderer.rs b/src/renderer.rs index 53c12ae..4beaa40 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -1,29 +1,32 @@ use glium::draw_parameters::{Blend, DrawParameters}; use glium::index::{NoIndices, PrimitiveType}; -use glium::{Display, Frame, Program, Surface, VertexBuffer}; -use nalgebra::Matrix4; +use glium::{Display, Frame, Program, Surface, Texture2d, VertexBuffer}; +use nalgebra::{Matrix4, Vector4}; -use crate::enums::Shape; +use crate::enums::{Orientation, Shape}; use crate::game::Game; use crate::{GAME_HEIGHT, GAME_WIDTH}; pub struct Renderer<'a, 'b> { target: &'a mut Frame, display: &'b Display, - program: &'b Program, + cell_program: &'b Program, + segment_program: &'b Program, + segment_texture: &'b Texture2d, } impl<'a, 'b> Renderer<'a, 'b> { pub fn new(game: &'b Game, target: &'a mut Frame) -> Self { - let program = game.resources.get_shader("cell").unwrap(); Renderer { target, display: &game.display, - program, + cell_program: game.resources.get_shader("cell").unwrap(), + segment_program: game.resources.get_shader("segment").unwrap(), + segment_texture: game.resources.get_texture("segment").unwrap(), } } - pub fn render_cell(&mut self, location: (u32, u32), scale: u32, shape: Shape) { + pub fn render_cell(&mut self, location: (u32, u32), scale: u32) { #[derive(Copy, Clone)] struct Vertex { point: [f32; 2], @@ -32,21 +35,12 @@ impl<'a, 'b> Renderer<'a, 'b> { let indices = NoIndices(PrimitiveType::TrianglesList); let mut vertices = Vec::::new(); - match shape { - Shape::Full => { - vertices.push(Vertex { point: [0.0, 0.0] }); - vertices.push(Vertex { point: [1.0, 0.0] }); - vertices.push(Vertex { point: [0.0, 1.0] }); - vertices.push(Vertex { point: [1.0, 1.0] }); - vertices.push(Vertex { point: [0.0, 1.0] }); - vertices.push(Vertex { point: [1.0, 0.0] }); - } - _ => { - vertices.push(Vertex { point: [0.0, 0.0] }); - vertices.push(Vertex { point: [1.0, 0.0] }); - vertices.push(Vertex { point: [0.0, 1.0] }); - } - } + vertices.push(Vertex { point: [0.0, 0.0] }); + vertices.push(Vertex { point: [1.0, 0.0] }); + vertices.push(Vertex { point: [0.0, 1.0] }); + vertices.push(Vertex { point: [1.0, 1.0] }); + vertices.push(Vertex { point: [0.0, 1.0] }); + vertices.push(Vertex { point: [1.0, 0.0] }); let vertex_buffer = VertexBuffer::new(self.display, &vertices).unwrap(); let projection = @@ -55,16 +49,157 @@ impl<'a, 'b> Renderer<'a, 'b> { matrix = matrix.append_nonuniform_scaling(&[scale as f32, scale as f32, 1.0].into()); matrix = matrix.append_translation(&[location.0 as f32, location.1 as f32, 0.0].into()); + let color = Vector4::from([0.6, 0.6, 0.8, 1.0f32]); + let uniforms = uniform! { target: *matrix.as_ref(), projection: *projection.as_ref(), + color: *color.as_ref(), }; self.target .draw( &vertex_buffer, &indices, - &self.program, + &self.cell_program, + &uniforms, + &DrawParameters { + blend: Blend::alpha_blending(), + ..Default::default() + }, + ) + .unwrap(); + } + + pub fn render_segment( + &mut self, + location: (u32, u32), + scale: u32, + color: (f32, f32, f32), + orientation: Orientation, + shape: Shape, + ) { + #[derive(Copy, Clone)] + struct Vertex { + pos: [f32; 2], + tex: [f32; 2], + } + implement_vertex!(Vertex, pos, tex); + + let indices = NoIndices(PrimitiveType::TrianglesList); + let mut vertices = Vec::new(); + match shape { + Shape::BottomLeft => { + vertices.push(Vertex { + pos: [1.0, 1.0], + tex: [1.0, 1.0], + }); + vertices.push(Vertex { + pos: [1.0, 0.0], + tex: [1.0, 0.0], + }); + vertices.push(Vertex { + pos: [0.0, 0.0], + tex: [0.0, 0.0], + }); + } + Shape::TopLeft => { + vertices.push(Vertex { + pos: [0.0, 1.0], + tex: [0.0, 1.0], + }); + vertices.push(Vertex { + pos: [1.0, 1.0], + tex: [1.0, 1.0], + }); + vertices.push(Vertex { + pos: [1.0, 0.0], + tex: [1.0, 0.0], + }); + } + Shape::TopRight => { + vertices.push(Vertex { + pos: [1.0, 1.0], + tex: [1.0, 1.0], + }); + vertices.push(Vertex { + pos: [0.0, 1.0], + tex: [0.0, 1.0], + }); + vertices.push(Vertex { + pos: [0.0, 0.0], + tex: [0.0, 0.0], + }); + } + Shape::BottomRight => { + vertices.push(Vertex { + pos: [0.0, 1.0], + tex: [0.0, 1.0], + }); + vertices.push(Vertex { + pos: [1.0, 0.0], + tex: [1.0, 0.0], + }); + vertices.push(Vertex { + pos: [0.0, 0.0], + tex: [0.0, 0.0], + }); + } + _ => { + vertices.push(Vertex { + pos: [0.0, 1.0], + tex: [0.0, 1.0], + }); + vertices.push(Vertex { + pos: [1.0, 0.0], + tex: [1.0, 0.0], + }); + vertices.push(Vertex { + pos: [0.0, 0.0], + tex: [0.0, 0.0], + }); + vertices.push(Vertex { + pos: [0.0, 1.0], + tex: [0.0, 1.0], + }); + vertices.push(Vertex { + pos: [1.0, 1.0], + tex: [1.0, 1.0], + }); + vertices.push(Vertex { + pos: [1.0, 0.0], + tex: [1.0, 0.0], + }); + } + } + let vertex_buffer = VertexBuffer::new(self.display, &vertices).unwrap(); + let tint = Vector4::from([color.0, color.1, color.2, 1.0f32]); + + let projection = + glm::ortho::(0.0, GAME_WIDTH as f32, GAME_HEIGHT as f32, 0.0, -1.0, 1.0); + let mut matrix = Matrix4::::identity(); + matrix = matrix.append_nonuniform_scaling(&[scale as f32, scale as f32, 1.0].into()); + matrix = matrix.append_translation(&[location.0 as f32, location.1 as f32, 0.0].into()); + + let rotate_texture = match orientation { + Orientation::Both => false, + Orientation::Vertical => true, + Orientation::Horizontal => false, + }; + + let uniforms = uniform! { + target: *matrix.as_ref(), + rotate_texture: rotate_texture, + projection: *projection.as_ref(), + tint: *tint.as_ref(), + tex: self.segment_texture, + }; + + self.target + .draw( + &vertex_buffer, + &indices, + &self.segment_program, &uniforms, &DrawParameters { blend: Blend::alpha_blending(), diff --git a/src/resources.rs b/src/resources.rs index 2973b15..1c66772 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -1,14 +1,52 @@ use std::collections::HashMap; +use glium::texture::RawImage2d; use glium::{Display, Program, ProgramCreationError, Texture2d}; +use image::{DynamicImage, GenericImageView, ImageBuffer, ImageError, Rgba}; #[derive(Default)] pub struct Resources { + pub window_dimensions: (u32, u32), textures: HashMap, shaders: HashMap, } impl Resources { + pub fn load_image_from_memory( + &mut self, + display: &Display, + name: impl AsRef, + buffer: &[u8], + alpha: bool, + ) -> Result<(), ImageError> { + let image = image::load_from_memory(buffer)?; + self.load_image(display, name, image, alpha); + Ok(()) + } + + pub fn load_image( + &mut self, + display: &Display, + name: impl AsRef, + image: DynamicImage, + alpha: bool, + ) { + let name = name.as_ref().to_owned(); + let dimensions = image.dimensions(); + let image = if alpha { + RawImage2d::from_raw_rgba_reversed(&image.raw_pixels(), dimensions) + } else { + RawImage2d::from_raw_rgb_reversed(&image.raw_pixels(), dimensions) + }; + // TODO: don't unwrap + let texture = Texture2d::new(display, image).unwrap(); + self.textures.insert(name, texture); + } + + pub fn get_texture(&self, name: impl AsRef) -> Option<&Texture2d> { + self.textures.get(name.as_ref()) + } + pub fn load_shader( &mut self, display: &Display, diff --git a/textures/segment.png b/textures/segment.png new file mode 100644 index 0000000000000000000000000000000000000000..ca44e1c247ec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