[−][src]Struct rustbatch::render::canvas::Canvas
Canvas is for offscreen drawing. Widow uses canvas and not direct draw calls from batches. the main advantage is that you can apply shader to canvas as a whole so you can make some post processing effects with fragment screen shader. Canvas can draw to another canvas or window.
example
use rustbatch::{Window, Batch, Vect, FPS}; use rustbatch::render::particle::system::{ParticleSystem, Initial, RandomizedProperty, Dynamic, Property}; use rustbatch::render::particle::system; use rustbatch::math::rgba::{Graph, GraphPoint}; use std::f32::consts::PI; use rustbatch::math::curve::Curve; use rustbatch::render::particle::shapes::{SymmetricShape, Triangle}; use rustbatch::vect; use rustbatch::render::program::Program; use rustbatch::render::shader::Shader; use std::ffi::CString; let (mut window, mut pump, _f, _g, _r) = Window::new(|sys| sys.window("segmentation", 400, 400).opengl().resizable().build().unwrap()); window.canvas.set_program(Program::from_shaders(&[Shader::default_vertex(), Shader::from_source( &CString::new(" #version 330 core\n in vec4 color;\n in vec2 region;\n\n in vec2 texture_size_f; out vec4 result_color;\n\n uniform sampler2D sp;\n\n vec4 ncolor; void main(){\n\ ncolor = texture(sp, region) * color; if (ncolor.a == 0.0) { if (texture(sp, region + vec2(4.0, 0)/texture_size_f).a != 0.0) { ncolor = vec4(1.0, 1.0, 1.0, 1.0); } } result_color = ncolor;\n\ }").unwrap() , gl::FRAGMENT_SHADER).expect("compilation failed")]).unwrap()); let mut sys = system::no_texture(system::ParticleConfig { rotation_relative_to_spawn_direction: true, inverted: false, gravity: Vect::DOWN * 2.0, color: Graph::new(vec![GraphPoint::new(0.0, [0.0, 0.0, 1.0, 1.0]), GraphPoint::new(0.5, [1.0, 1.0, 0.0, 1.0]), GraphPoint::new(1.0, [0.0, 1.0, 0.0, 1.0])]), spread: PI, friction: 2.0, origin_attraction: 10.0, initial: Initial { velocity: RandomizedProperty::new(300.0, 150.0), rotation: RandomizedProperty::no_random(0.0), twerk: RandomizedProperty::no_random(10.0), live_time: RandomizedProperty::new(1.0, 0.5), }, dynamic: Dynamic { acceleration: Property { curve: Curve::NONE, value: 0.0 }, twerk_acceleration: Property { curve: Curve::NONE, value: 0.0 }, scale: Property { curve: Curve::LINEAR_DECREASING, value: 20.0 } } }, SymmetricShape::new(10, 0.0)); let mut fps = FPS::new(1f32); 'main: loop { for event in pump.poll_iter() { match event { sdl2::event::Event::Quit { .. } => break 'main, _ => {} } } let delta = fps.increase(0f32); window.clear(); sys.update(delta); sys.spawn(1, vect!(0, 0), vect!(1, 0)); sys.draw(&mut window.canvas); window.update(); }
Implementations
impl Canvas
[src]
pub fn new(size: TextureSize) -> Self
[src]
pub fn customized(
size: TextureSize,
buffer: Buffer,
program: Program,
config: TextureConfig
) -> Self
[src]
size: TextureSize,
buffer: Buffer,
program: Program,
config: TextureConfig
) -> Self
customizes allows greater customization of canvas
pub fn set_program(&mut self, program: Program)
[src]
pub fn set_buffer(&mut self, buffer: Buffer)
[src]
pub fn resize(&mut self, size: TextureSize)
[src]
resize resizes canvas and erases its content
pub fn bind(&self)
[src]
bind binds the canvas so you can draw on it as you would on window
pub fn unbind()
[src]
unbind unbinds the current canvas. If you don't call this your draw calls will still affect this canvas and not the widow.
pub fn set_camera_matrix(&mut self, mat: Mat)
[src]
set camera sets the matrix by witch are all shapes transformed so you can squeeze thinks however you like
pub fn set_camera(&mut self, position: Vect, zoom: f32)
[src]
set_camera is more human readable way of setting viewport
pub fn size(&self) -> (u32, u32)
[src]
size returns current size of canvas
pub fn clear(&self, color: &RGBA)
[src]
clear clears the window
pub fn reset(&self)
[src]
reset clears canvas with transparent color
pub fn draw<T: Target>(&mut self, other: &mut T, mat: &Mat, color: &RGBA)
[src]
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Canvas
impl Send for Canvas
impl Sync for Canvas
impl Unpin for Canvas
impl UnwindSafe for Canvas
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,