pub struct VertexBuffer { /* private fields */ }
Expand description
Vertex Buffer structure A vertexbuffer is an buffer object in OpenGl. Here it’s linked with VertexArray for data. The VertexBuffer is the ‘low levelest’ object that is drawable. You can create it from Vertice slice or VertexArray
use gust::window::Window;
use gust::vertex::{VertexArray, Vertex};
use gust::Drawable;
fn main() {
let win = Window::default();
let vertice = &[
Vertex::new(Vector::new(0.0, 0.0), Vector::new(0.0, 0.0), Color::new(1.0, 0.0, 0.0)),
Vertex::new(Vector::new(1.0, 0.0), Vector::new(0.0, 0.0), Color::new(1.0, 0.0, 0.0)),
Vertex::new(Vector::new(0.0, 1.0), Vector::new(0.0, 0.0), Color::new(1.0, 0.0, 0.0)),
];
let triangle = VertexBuffer::from(vertice);
while window.is_open() {
window.clear();
window.draw(&triangle);
window.display();
}
}
Implementations§
Source§impl VertexBuffer
impl VertexBuffer
Sourcepub fn new(t: Primitive, vertice: VertexArray) -> VertexBuffer
pub fn new(t: Primitive, vertice: VertexArray) -> VertexBuffer
Create new Vertex Buffer from vertices
Examples found in repository?
examples/shape.rs (line 74)
8fn main() {
9 let mut window = Window::new(gust::WIDTH, gust::HEIGHT, "Hello");
10 let vert_arr = VertexArray::from(
11 vec![
12 Vertex::new(
13 Vector::new(800.0, 400.0),
14 Vector::new(200.0, 0.0),
15 Color::new(0.0, 1.0, 0.0),
16 ),
17 Vertex::new(
18 Vector::new(1200.0, 700.0),
19 Vector::new(20.0, 10.0),
20 Color::new(0.0, 1.0, 1.0),
21 ),
22 Vertex::new(
23 Vector::new(1000.0, 300.0),
24 Vector::new(0.0, 0.0),
25 Color::new(0.0, 0.2, 1.0),
26 ),
27 Vertex::new(
28 Vector::new(800.0, 100.0),
29 Vector::new(0.0, 0.0),
30 Color::new(1.0, 1.0, 0.5),
31 ),
32 Vertex::new(
33 Vector::new(600.0, 300.0),
34 Vector::new(0.0, 0.0),
35 Color::new(0.5, 0.2, 0.1),
36 ),
37 Vertex::new(
38 Vector::new(400.0, 700.0),
39 Vector::new(0.0, 0.0),
40 Color::new(1.0, 0.0, 0.0),
41 ),
42 ]
43 .as_slice(),
44 );
45
46 let vert_arr_2 = VertexArray::from(
47 vec![
48 Vertex::new(Vector::new(0.0, 0.0), Vector::new(0.0, 0.0), Color::blue()),
49 Vertex::new(
50 Vector::new(0.0, 100.0),
51 Vector::new(0.0, 0.0),
52 Color::blue(),
53 ),
54 Vertex::new(
55 Vector::new(100.0, 100.0),
56 Vector::new(0.0, 0.0),
57 Color::blue(),
58 ),
59 Vertex::new(Vector::new(0.0, 0.0), Vector::new(0.0, 0.0), Color::green()),
60 Vertex::new(
61 Vector::new(100.0, 100.0),
62 Vector::new(0.0, 0.0),
63 Color::green(),
64 ),
65 Vertex::new(
66 Vector::new(100.0, 0.0),
67 Vector::new(0.0, 0.0),
68 Color::green(),
69 ),
70 ]
71 .as_slice(),
72 );
73
74 let vert_buf = VertexBuffer::new(Primitive::TriangleFan, vert_arr);
75 let vert_buf2 = VertexBuffer::new(Primitive::Triangles, vert_arr_2);
76
77 let event_handler = EventHandler::new(&window);
78
79 window.set_clear_color(Color::red());
80 window.poll(EventType::Key);
81 while window.is_open() {
82 window.poll_events();
83
84 for event in event_handler.fetch() {
85 match event.1 {
86 Events::Key(Key::Escape, _, Action::Press, _) => {
87 window.close();
88 }
89 _ => {}
90 }
91 }
92
93 window.clear();
94 window.draw(&vert_buf);
95 window.draw(&vert_buf2);
96 window.display();
97 }
98}
Sourcepub fn append(&mut self, vertices: &[Vertex])
pub fn append(&mut self, vertices: &[Vertex])
Append data to the actual VertexArray while be updated internaly.
pub fn get_primitive(&self) -> Primitive
pub fn set_geometry(&mut self, vertice: &[Vertex])
pub fn bind(&self)
pub fn unbind(&self)
Trait Implementations§
Source§impl Clone for VertexBuffer
impl Clone for VertexBuffer
Source§fn clone(&self) -> VertexBuffer
fn clone(&self) -> VertexBuffer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for VertexBuffer
impl Debug for VertexBuffer
Source§impl Default for VertexBuffer
impl Default for VertexBuffer
Source§impl Drawable for VertexBuffer
impl Drawable for VertexBuffer
Source§fn draw<T: Drawer>(&self, target: &mut T)
fn draw<T: Drawer>(&self, target: &mut T)
Draw the drawable structure, you need a Drawer(Where the struct will be draw)
Source§fn draw_with_context(&self, context: &mut Context<'_>)
fn draw_with_context(&self, context: &mut Context<'_>)
Draw with a particular context
Source§fn update(&mut self)
fn update(&mut self)
Update the openGL state of the drawable entity
Should be call often so be carefull when implementing.
Source§fn setup_draw(&self, context: &mut Context<'_>)
fn setup_draw(&self, context: &mut Context<'_>)
Setup the draw for the final system you don’t have to implement it in a normal drawable
Source§impl DrawableMut for VertexBuffer
impl DrawableMut for VertexBuffer
Source§impl Drop for VertexBuffer
impl Drop for VertexBuffer
Source§impl Index<usize> for VertexBuffer
impl Index<usize> for VertexBuffer
Source§impl IndexMut<usize> for VertexBuffer
impl IndexMut<usize> for VertexBuffer
Source§impl PartialEq for VertexBuffer
impl PartialEq for VertexBuffer
impl StructuralPartialEq for VertexBuffer
Auto Trait Implementations§
impl Freeze for VertexBuffer
impl RefUnwindSafe for VertexBuffer
impl !Send for VertexBuffer
impl !Sync for VertexBuffer
impl Unpin for VertexBuffer
impl UnwindSafe for VertexBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SetParameter for T
impl<T> SetParameter for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.