1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
//! LeafRender is a simply, easy to use library to just get pixels onto the screen, //! regardless of your platform. //! //! Supported on Windows, Linux and the Raspberry Pi. //! //! Other libraries often require huge amounts of bootstrap which simply doesn't make //! sense for WIP or hobby projects. //! //! Some support is also included for image formats and input. //! //! ## Basic usage //! //! Import the crate in your Cargo.toml with (assuming Windows/Linux OpenGL): //! ``` //! leafrender = "0.1.0" //! ``` //! //! In your code, have something like: //! //! ``` //! use leafrender::input::Input; //! use leafrender::render::Drawer; //! use leafrender::pos::Rect; //! use leafrender::render::Color; //! //! use leafrender::PlatformDrawer; //! use leafrender::PlatformInput; //! //! let mut drawer = PlatformDrawer::new("LeafRender Test", 640, 480) //! .expect("Failed to create drawer"); //! let mut input = PlatformInput::new(); //! //! while { //! input.update(&mut drawer); //! input.do_continue() //! } { //! drawer.start(); //! drawer.clear(false); //! drawer.enable_blending(); // Enable partial transparency. //! // Left disabled by default for e.g. Pi //! //! drawer.draw_colored_rect( //! &Rect { //! x: 100, //! y: 100, //! width: 50, //! height: 50, //! }, //! &Color { //! r: 255, //! g: 0, //! b: 0, //! a: 255, //! } //! ); //! //! drawer.end(); //! } //! ``` //! //! ## More examples //! //! Want some text? //! //! ``` //! use crate::render::font::FontCache; //! use crate::pos::Position; //! //! let mut font = FontCache::from_bytes(include_bytes!("Lato-Regular.ttf")) //! .expect("Unable to load font"); //! //! // [...] //! //! // Inside your main loop, ensuring that blending is enabled (simple example above): //! //! font.draw( //! "Hello, World!", //! &Color { //! r: 0, //! g: 0, //! b: 0, //! a: 255, //! }, //! 12, //! &Position { //! x: 50, //! y: 50, //! }, //! &mut drawer //! ; //! ``` //! //! Or an image? //! //! ``` //! use image; // image crate //! //! let image = image::load_from_memory(include_bytes!("img.jpg")) //! .expect("Failed to load image") //! .to_rgba(); //! let image = drawer.convert_image(&image); //! //! // [...] //! //! // Inside your main loop, ensuring that blending is enabled (simple example above): //! //! drawer.draw_texture(&image, &Position { //! x: 150, //! y: 150, //! }); //! ``` //! //! # Features //! //! - Drawing of rectangles, vertices w/ colors //! - Drawing of fonts using `rusttype` //! - Drawing of images using `image` //! - Basic input handling (mouse) //! //! # Wishlist //! //! - More complete input handling (keyboard) //! - Clean up a few error handling edge cases //! - Few bits of safety could be cleaned up //! //! # Non-features //! //! - 3D (too much to control here) //! - Custom shaders //! extern crate image; extern crate rusttype; extern crate libc; #[cfg(feature = "raspberry_pi")] extern crate egl; #[cfg(feature = "raspberry_pi")] extern crate evdev; #[cfg(feature = "raspberry_pi")] extern crate opengles; #[cfg(feature = "raspberry_pi")] extern crate videocore; #[cfg(feature = "desktop_gl")] extern crate gl; #[cfg(feature = "desktop_gl")] extern crate glutin; pub mod pos; pub mod render; pub use crate::render::drawer_impl as PlatformDrawer; pub mod input; pub use crate::input::input_impl as PlatformInput;