-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.rs
71 lines (63 loc) · 2.34 KB
/
example.rs
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
use meliusgfx::material::{Material, AttributeType};
use meliusgfx::texture::{Texture, WrappingType, FilteringType};
use meliusgfx::render::{Renderer, FaceCulling, DebugFilter, Vertex};
use glfw::Context;
fn main() {
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
glfw.window_hint(glfw::WindowHint::OpenGlProfile(glfw::OpenGlProfileHint::Core));
glfw.window_hint(glfw::WindowHint::OpenGlForwardCompat(true));
glfw.window_hint(glfw::WindowHint::ContextVersion(4, 3));
glfw.window_hint(glfw::WindowHint::Samples(Some(4)));
let (mut window, _) = glfw.create_window(800, 600, "Test Window", glfw::WindowMode::Windowed)
.expect("Failed to create GLFW window.");
window.set_key_polling(true);
window.make_current();
let mut renderer = Renderer::new(|x| { window.get_proc_address(x) }, true, true, FaceCulling::Front, vec![DebugFilter::Info]);
let my_triangle = renderer.create_object(
Some(vec![
Vertex {
position: (-0.5, -0.5, 0.0),
color: (1.0, 1.0, 1.0, 1.0),
tex_coords: ( 0.0, 0.0),
normals: (0.0, 0.0, 0.0),
texture_id: 0.0
},
Vertex {
position: ( 0.0, 0.5, 0.0),
color: (1.0, 1.0, 1.0, 1.0),
tex_coords: ( 0.5, 1.0),
normals: (0.0, 0.0, 0.0),
texture_id: 0.0
},
Vertex {
position: ( 0.5, -0.5, 0.0),
color: (1.0, 1.0, 1.0, 1.0),
tex_coords: ( 1.0, 0.0),
normals: (0.0, 0.0, 0.0),
texture_id: 0.0
},
]),
Some(vec![0, 1, 2]),
Material::from_shader_files(
"tests/vertex_shader.glsl",
"tests/fragment_shader.glsl",
vec![
Texture::new(
WrappingType::Repeat,
FilteringType::Linear,
FilteringType::Linear,
0,
Texture::get_from_location("wall.jpg")
)
],
vec![
("time", AttributeType::Float1(0.1))
],
),
);
while !window.should_close() {
renderer.render((0.0, 0.0, 0.0, 0.0));
window.swap_buffers();
glfw.poll_events();
}
}