Texture

Struct Texture 

Source
pub struct Texture { /* private fields */ }

Implementations§

Source§

impl Texture

Source

pub fn new() -> Texture

Examples found in repository?
examples/demo/main.rs (line 71)
13fn main() {
14  let mut events_loop = EventsLoop::new();
15  let wb = WindowBuilder::new()
16    .with_title("Demo")
17    .with_resizable(false)
18    .with_dimensions(LogicalSize::from((400, 400)));
19  let context = ContextBuilder::new()
20    .with_vsync(true)
21    .build_windowed(wb, &events_loop)
22    .unwrap();
23
24  unsafe {
25    context.make_current().unwrap();
26    gl::load_with(|symbol| context.get_proc_address(symbol) as *const _);
27  }
28
29  gllite::gli::clear_color(0.0, 0.0, 0.0, 1.0);
30
31  let shader_frag = "#version 330
32precision mediump float;
33out vec4 outColor;
34
35in vec2 v_position;
36
37uniform vec4 color;
38uniform sampler2D tex;
39
40void main() {
41  outColor = color * texture(tex, v_position);
42}";
43  let shader_vert = "#version 330
44in vec2 a_position;
45out vec2 v_position;
46
47void main() {
48  v_position = a_position;
49  gl_Position = vec4(a_position.xy, 0, 1);
50}";
51  let mut prog = gllite::program::Program::new();
52  prog
53    .add_shader(shader_vert, gl::VERTEX_SHADER)
54    .add_shader(shader_frag, gl::FRAGMENT_SHADER)
55    .compile();
56
57  let p = Rc::new(prog);
58
59  let mut node = gllite::node::Node::for_program(Rc::clone(&p));
60
61  let vertices: [f32; 6] = [
62    0.0, 1.0,
63    -1.0, -1.0,
64    1.0, -1.0,
65  ];
66
67  node.add_attribute(String::from("a_position"));
68  node.buffer_data(&vertices);
69  node.set_uniform(String::from("color"), UniformValue::FloatVec4(1.0, 1.0, 0.0, 1.0));
70
71  let tex = Texture::new();
72  let check: [u8;16] = [
73    30, 30, 30, 255,
74    200, 200, 200, 255,
75    200, 200, 200, 255,
76    30, 30, 30, 255,
77  ];
78  tex.set_from_bytes(gli::RGBA, 2, 2, gli::RGBA, &check[0] as *const u8);
79  tex.set_wrap_mode(gli::REPEAT, gli::REPEAT);
80  tex.set_filter_mode(gli::NEAREST, gli::NEAREST);
81  node.set_uniform(String::from("tex"), tex.as_uniform_value());
82
83  let mut last_frame_time = SystemTime::now();
84  loop {
85    let now = SystemTime::now();
86    let delta = match now.duration_since(last_frame_time) {
87      Ok(n) => n.as_millis(),
88      Err(_) => 1,
89    };
90    last_frame_time = now;
91
92    if delta < 16 {
93      let diff = 16 - delta;
94      let sleeptime = time::Duration::from_millis(diff as u64);
95      thread::sleep(sleeptime);
96    }
97
98    let mut should_exit = false;
99    events_loop.poll_events(|event| {
100      match event {
101        Event::WindowEvent {event, ..} => match event {
102          WindowEvent::CloseRequested => should_exit = true,
103          _ => (),
104        },
105        _ => (),
106      }
107    });
108    if should_exit {
109      break;
110    }
111
112    p.make_current();
113    unsafe {
114      gl::Clear(gl::COLOR_BUFFER_BIT);
115      node.draw();
116    }
117    context.swap_buffers().unwrap();
118  }
119}
Source

pub fn set_wrap_mode(&self, s: u32, t: u32)

Examples found in repository?
examples/demo/main.rs (line 79)
13fn main() {
14  let mut events_loop = EventsLoop::new();
15  let wb = WindowBuilder::new()
16    .with_title("Demo")
17    .with_resizable(false)
18    .with_dimensions(LogicalSize::from((400, 400)));
19  let context = ContextBuilder::new()
20    .with_vsync(true)
21    .build_windowed(wb, &events_loop)
22    .unwrap();
23
24  unsafe {
25    context.make_current().unwrap();
26    gl::load_with(|symbol| context.get_proc_address(symbol) as *const _);
27  }
28
29  gllite::gli::clear_color(0.0, 0.0, 0.0, 1.0);
30
31  let shader_frag = "#version 330
32precision mediump float;
33out vec4 outColor;
34
35in vec2 v_position;
36
37uniform vec4 color;
38uniform sampler2D tex;
39
40void main() {
41  outColor = color * texture(tex, v_position);
42}";
43  let shader_vert = "#version 330
44in vec2 a_position;
45out vec2 v_position;
46
47void main() {
48  v_position = a_position;
49  gl_Position = vec4(a_position.xy, 0, 1);
50}";
51  let mut prog = gllite::program::Program::new();
52  prog
53    .add_shader(shader_vert, gl::VERTEX_SHADER)
54    .add_shader(shader_frag, gl::FRAGMENT_SHADER)
55    .compile();
56
57  let p = Rc::new(prog);
58
59  let mut node = gllite::node::Node::for_program(Rc::clone(&p));
60
61  let vertices: [f32; 6] = [
62    0.0, 1.0,
63    -1.0, -1.0,
64    1.0, -1.0,
65  ];
66
67  node.add_attribute(String::from("a_position"));
68  node.buffer_data(&vertices);
69  node.set_uniform(String::from("color"), UniformValue::FloatVec4(1.0, 1.0, 0.0, 1.0));
70
71  let tex = Texture::new();
72  let check: [u8;16] = [
73    30, 30, 30, 255,
74    200, 200, 200, 255,
75    200, 200, 200, 255,
76    30, 30, 30, 255,
77  ];
78  tex.set_from_bytes(gli::RGBA, 2, 2, gli::RGBA, &check[0] as *const u8);
79  tex.set_wrap_mode(gli::REPEAT, gli::REPEAT);
80  tex.set_filter_mode(gli::NEAREST, gli::NEAREST);
81  node.set_uniform(String::from("tex"), tex.as_uniform_value());
82
83  let mut last_frame_time = SystemTime::now();
84  loop {
85    let now = SystemTime::now();
86    let delta = match now.duration_since(last_frame_time) {
87      Ok(n) => n.as_millis(),
88      Err(_) => 1,
89    };
90    last_frame_time = now;
91
92    if delta < 16 {
93      let diff = 16 - delta;
94      let sleeptime = time::Duration::from_millis(diff as u64);
95      thread::sleep(sleeptime);
96    }
97
98    let mut should_exit = false;
99    events_loop.poll_events(|event| {
100      match event {
101        Event::WindowEvent {event, ..} => match event {
102          WindowEvent::CloseRequested => should_exit = true,
103          _ => (),
104        },
105        _ => (),
106      }
107    });
108    if should_exit {
109      break;
110    }
111
112    p.make_current();
113    unsafe {
114      gl::Clear(gl::COLOR_BUFFER_BIT);
115      node.draw();
116    }
117    context.swap_buffers().unwrap();
118  }
119}
Source

pub fn set_filter_mode(&self, min: u32, mag: u32)

Examples found in repository?
examples/demo/main.rs (line 80)
13fn main() {
14  let mut events_loop = EventsLoop::new();
15  let wb = WindowBuilder::new()
16    .with_title("Demo")
17    .with_resizable(false)
18    .with_dimensions(LogicalSize::from((400, 400)));
19  let context = ContextBuilder::new()
20    .with_vsync(true)
21    .build_windowed(wb, &events_loop)
22    .unwrap();
23
24  unsafe {
25    context.make_current().unwrap();
26    gl::load_with(|symbol| context.get_proc_address(symbol) as *const _);
27  }
28
29  gllite::gli::clear_color(0.0, 0.0, 0.0, 1.0);
30
31  let shader_frag = "#version 330
32precision mediump float;
33out vec4 outColor;
34
35in vec2 v_position;
36
37uniform vec4 color;
38uniform sampler2D tex;
39
40void main() {
41  outColor = color * texture(tex, v_position);
42}";
43  let shader_vert = "#version 330
44in vec2 a_position;
45out vec2 v_position;
46
47void main() {
48  v_position = a_position;
49  gl_Position = vec4(a_position.xy, 0, 1);
50}";
51  let mut prog = gllite::program::Program::new();
52  prog
53    .add_shader(shader_vert, gl::VERTEX_SHADER)
54    .add_shader(shader_frag, gl::FRAGMENT_SHADER)
55    .compile();
56
57  let p = Rc::new(prog);
58
59  let mut node = gllite::node::Node::for_program(Rc::clone(&p));
60
61  let vertices: [f32; 6] = [
62    0.0, 1.0,
63    -1.0, -1.0,
64    1.0, -1.0,
65  ];
66
67  node.add_attribute(String::from("a_position"));
68  node.buffer_data(&vertices);
69  node.set_uniform(String::from("color"), UniformValue::FloatVec4(1.0, 1.0, 0.0, 1.0));
70
71  let tex = Texture::new();
72  let check: [u8;16] = [
73    30, 30, 30, 255,
74    200, 200, 200, 255,
75    200, 200, 200, 255,
76    30, 30, 30, 255,
77  ];
78  tex.set_from_bytes(gli::RGBA, 2, 2, gli::RGBA, &check[0] as *const u8);
79  tex.set_wrap_mode(gli::REPEAT, gli::REPEAT);
80  tex.set_filter_mode(gli::NEAREST, gli::NEAREST);
81  node.set_uniform(String::from("tex"), tex.as_uniform_value());
82
83  let mut last_frame_time = SystemTime::now();
84  loop {
85    let now = SystemTime::now();
86    let delta = match now.duration_since(last_frame_time) {
87      Ok(n) => n.as_millis(),
88      Err(_) => 1,
89    };
90    last_frame_time = now;
91
92    if delta < 16 {
93      let diff = 16 - delta;
94      let sleeptime = time::Duration::from_millis(diff as u64);
95      thread::sleep(sleeptime);
96    }
97
98    let mut should_exit = false;
99    events_loop.poll_events(|event| {
100      match event {
101        Event::WindowEvent {event, ..} => match event {
102          WindowEvent::CloseRequested => should_exit = true,
103          _ => (),
104        },
105        _ => (),
106      }
107    });
108    if should_exit {
109      break;
110    }
111
112    p.make_current();
113    unsafe {
114      gl::Clear(gl::COLOR_BUFFER_BIT);
115      node.draw();
116    }
117    context.swap_buffers().unwrap();
118  }
119}
Source

pub fn as_uniform_value(&self) -> UniformValue

Examples found in repository?
examples/demo/main.rs (line 81)
13fn main() {
14  let mut events_loop = EventsLoop::new();
15  let wb = WindowBuilder::new()
16    .with_title("Demo")
17    .with_resizable(false)
18    .with_dimensions(LogicalSize::from((400, 400)));
19  let context = ContextBuilder::new()
20    .with_vsync(true)
21    .build_windowed(wb, &events_loop)
22    .unwrap();
23
24  unsafe {
25    context.make_current().unwrap();
26    gl::load_with(|symbol| context.get_proc_address(symbol) as *const _);
27  }
28
29  gllite::gli::clear_color(0.0, 0.0, 0.0, 1.0);
30
31  let shader_frag = "#version 330
32precision mediump float;
33out vec4 outColor;
34
35in vec2 v_position;
36
37uniform vec4 color;
38uniform sampler2D tex;
39
40void main() {
41  outColor = color * texture(tex, v_position);
42}";
43  let shader_vert = "#version 330
44in vec2 a_position;
45out vec2 v_position;
46
47void main() {
48  v_position = a_position;
49  gl_Position = vec4(a_position.xy, 0, 1);
50}";
51  let mut prog = gllite::program::Program::new();
52  prog
53    .add_shader(shader_vert, gl::VERTEX_SHADER)
54    .add_shader(shader_frag, gl::FRAGMENT_SHADER)
55    .compile();
56
57  let p = Rc::new(prog);
58
59  let mut node = gllite::node::Node::for_program(Rc::clone(&p));
60
61  let vertices: [f32; 6] = [
62    0.0, 1.0,
63    -1.0, -1.0,
64    1.0, -1.0,
65  ];
66
67  node.add_attribute(String::from("a_position"));
68  node.buffer_data(&vertices);
69  node.set_uniform(String::from("color"), UniformValue::FloatVec4(1.0, 1.0, 0.0, 1.0));
70
71  let tex = Texture::new();
72  let check: [u8;16] = [
73    30, 30, 30, 255,
74    200, 200, 200, 255,
75    200, 200, 200, 255,
76    30, 30, 30, 255,
77  ];
78  tex.set_from_bytes(gli::RGBA, 2, 2, gli::RGBA, &check[0] as *const u8);
79  tex.set_wrap_mode(gli::REPEAT, gli::REPEAT);
80  tex.set_filter_mode(gli::NEAREST, gli::NEAREST);
81  node.set_uniform(String::from("tex"), tex.as_uniform_value());
82
83  let mut last_frame_time = SystemTime::now();
84  loop {
85    let now = SystemTime::now();
86    let delta = match now.duration_since(last_frame_time) {
87      Ok(n) => n.as_millis(),
88      Err(_) => 1,
89    };
90    last_frame_time = now;
91
92    if delta < 16 {
93      let diff = 16 - delta;
94      let sleeptime = time::Duration::from_millis(diff as u64);
95      thread::sleep(sleeptime);
96    }
97
98    let mut should_exit = false;
99    events_loop.poll_events(|event| {
100      match event {
101        Event::WindowEvent {event, ..} => match event {
102          WindowEvent::CloseRequested => should_exit = true,
103          _ => (),
104        },
105        _ => (),
106      }
107    });
108    if should_exit {
109      break;
110    }
111
112    p.make_current();
113    unsafe {
114      gl::Clear(gl::COLOR_BUFFER_BIT);
115      node.draw();
116    }
117    context.swap_buffers().unwrap();
118  }
119}
Source

pub fn set_from_bytes( &self, internal: u32, width: i32, height: i32, format: u32, data: *const u8, )

Examples found in repository?
examples/demo/main.rs (line 78)
13fn main() {
14  let mut events_loop = EventsLoop::new();
15  let wb = WindowBuilder::new()
16    .with_title("Demo")
17    .with_resizable(false)
18    .with_dimensions(LogicalSize::from((400, 400)));
19  let context = ContextBuilder::new()
20    .with_vsync(true)
21    .build_windowed(wb, &events_loop)
22    .unwrap();
23
24  unsafe {
25    context.make_current().unwrap();
26    gl::load_with(|symbol| context.get_proc_address(symbol) as *const _);
27  }
28
29  gllite::gli::clear_color(0.0, 0.0, 0.0, 1.0);
30
31  let shader_frag = "#version 330
32precision mediump float;
33out vec4 outColor;
34
35in vec2 v_position;
36
37uniform vec4 color;
38uniform sampler2D tex;
39
40void main() {
41  outColor = color * texture(tex, v_position);
42}";
43  let shader_vert = "#version 330
44in vec2 a_position;
45out vec2 v_position;
46
47void main() {
48  v_position = a_position;
49  gl_Position = vec4(a_position.xy, 0, 1);
50}";
51  let mut prog = gllite::program::Program::new();
52  prog
53    .add_shader(shader_vert, gl::VERTEX_SHADER)
54    .add_shader(shader_frag, gl::FRAGMENT_SHADER)
55    .compile();
56
57  let p = Rc::new(prog);
58
59  let mut node = gllite::node::Node::for_program(Rc::clone(&p));
60
61  let vertices: [f32; 6] = [
62    0.0, 1.0,
63    -1.0, -1.0,
64    1.0, -1.0,
65  ];
66
67  node.add_attribute(String::from("a_position"));
68  node.buffer_data(&vertices);
69  node.set_uniform(String::from("color"), UniformValue::FloatVec4(1.0, 1.0, 0.0, 1.0));
70
71  let tex = Texture::new();
72  let check: [u8;16] = [
73    30, 30, 30, 255,
74    200, 200, 200, 255,
75    200, 200, 200, 255,
76    30, 30, 30, 255,
77  ];
78  tex.set_from_bytes(gli::RGBA, 2, 2, gli::RGBA, &check[0] as *const u8);
79  tex.set_wrap_mode(gli::REPEAT, gli::REPEAT);
80  tex.set_filter_mode(gli::NEAREST, gli::NEAREST);
81  node.set_uniform(String::from("tex"), tex.as_uniform_value());
82
83  let mut last_frame_time = SystemTime::now();
84  loop {
85    let now = SystemTime::now();
86    let delta = match now.duration_since(last_frame_time) {
87      Ok(n) => n.as_millis(),
88      Err(_) => 1,
89    };
90    last_frame_time = now;
91
92    if delta < 16 {
93      let diff = 16 - delta;
94      let sleeptime = time::Duration::from_millis(diff as u64);
95      thread::sleep(sleeptime);
96    }
97
98    let mut should_exit = false;
99    events_loop.poll_events(|event| {
100      match event {
101        Event::WindowEvent {event, ..} => match event {
102          WindowEvent::CloseRequested => should_exit = true,
103          _ => (),
104        },
105        _ => (),
106      }
107    });
108    if should_exit {
109      break;
110    }
111
112    p.make_current();
113    unsafe {
114      gl::Clear(gl::COLOR_BUFFER_BIT);
115      node.draw();
116    }
117    context.swap_buffers().unwrap();
118  }
119}
Source

pub fn bind_to_slot(&self, slot: u32)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.