VertexBuffer

Struct VertexBuffer 

Source
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

Source

pub fn clear(&mut self)

Clear all data from VertexArray

Source

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}
Source

pub fn append(&mut self, vertices: &[Vertex])

Append data to the actual VertexArray while be updated internaly.

Source

pub fn get_primitive(&self) -> Primitive

Source

pub fn set_geometry(&mut self, vertice: &[Vertex])

Source

pub fn bind(&self)

Source

pub fn unbind(&self)

Trait Implementations§

Source§

impl Clone for VertexBuffer

Source§

fn clone(&self) -> VertexBuffer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VertexBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VertexBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drawable for VertexBuffer

Source§

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<'_>)

Draw with a particular context
Source§

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<'_>)

Setup the draw for the final system you don’t have to implement it in a normal drawable
Source§

impl DrawableMut for VertexBuffer

Source§

fn draw_mut<T: Drawer>(&mut self, target: &mut T)

Mutable version of draw function.
Source§

fn draw_with_context_mut(&mut self, context: &mut Context<'_>)

Mutable draw context function.
Source§

impl Drop for VertexBuffer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Index<usize> for VertexBuffer

Source§

type Output = Vertex

The returned type after indexing.
Source§

fn index(&self, vertex_index: usize) -> &Vertex

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for VertexBuffer

Source§

fn index_mut(&mut self, index: usize) -> &mut Vertex

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl PartialEq for VertexBuffer

Source§

fn eq(&self, other: &VertexBuffer) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for VertexBuffer

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.