hello world
This commit is contained in:
31
src/main.rs
31
src/main.rs
@@ -27,9 +27,8 @@ use glutin::event_loop::ControlFlow;
|
||||
// initial window size
|
||||
const INITIAL_SCREEN_W: u32 = 800;
|
||||
const INITIAL_SCREEN_H: u32 = 600;
|
||||
// TODO: I used the funny number.
|
||||
const VERTEX_ATTRIBUTE_INDEX: u32 = 3;
|
||||
const DIMENSIONS: i32 = 2;
|
||||
const VERTEX_ATTRIBUTE_INDEX: u32 = 0;
|
||||
const DIMENSIONS: i32 = 3;
|
||||
|
||||
// == // Helper functions to make interacting with OpenGL a little bit prettier. You *WILL* need these! // == //
|
||||
|
||||
@@ -99,7 +98,6 @@ unsafe fn create_vao(vertices: &Vec<f32>, indices: &Vec<u32>) -> u32 {
|
||||
);
|
||||
gl::EnableVertexAttribArray(VERTEX_ATTRIBUTE_INDEX);
|
||||
|
||||
|
||||
let mut index_buf_id = 0;
|
||||
gl::GenBuffers(1, &mut index_buf_id);
|
||||
gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, index_buf_id);
|
||||
@@ -110,8 +108,6 @@ unsafe fn create_vao(vertices: &Vec<f32>, indices: &Vec<u32>) -> u32 {
|
||||
gl::STATIC_DRAW,
|
||||
);
|
||||
|
||||
gl::DrawElements(gl::TRIANGLES, indices.len() as i32, gl::UNSIGNED_INT, std::ptr::null());
|
||||
|
||||
vao_id
|
||||
}
|
||||
|
||||
@@ -185,11 +181,16 @@ fn main() {
|
||||
|
||||
// == // Set up your VAO around here
|
||||
|
||||
let vertices = vec![-1., 0., 1., 0.5];
|
||||
let indices = vec![0, 1, 2, 1, 1, 3];
|
||||
let vertices = vec![
|
||||
-0.6, -0.6, 0.,
|
||||
0.6, -0.6, 0.,
|
||||
0., 0.6, 0.
|
||||
];
|
||||
let indices = vec![0, 1, 2];
|
||||
let my_vao = unsafe {
|
||||
create_vao(&vertices, &indices);
|
||||
create_vao(&vertices, &indices)
|
||||
};
|
||||
|
||||
println!("created vao!");
|
||||
// let my_vao = unsafe { 1337 };
|
||||
|
||||
@@ -206,10 +207,6 @@ fn main() {
|
||||
let simple_shader = unsafe {
|
||||
shader::ShaderBuilder::new()
|
||||
.attach_file("./shaders/simple.vert")
|
||||
.link()
|
||||
};
|
||||
let simple_shader = unsafe {
|
||||
shader::ShaderBuilder::new()
|
||||
.attach_file("./shaders/simple.frag")
|
||||
.link()
|
||||
};
|
||||
@@ -274,6 +271,14 @@ fn main() {
|
||||
gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
|
||||
|
||||
// == // Issue the necessary gl:: commands to draw your scene here
|
||||
simple_shader.activate();
|
||||
gl::BindVertexArray(my_vao);
|
||||
gl::DrawElements(
|
||||
gl::TRIANGLES,
|
||||
indices.len() as i32,
|
||||
gl::UNSIGNED_INT,
|
||||
std::ptr::null(),
|
||||
);
|
||||
}
|
||||
|
||||
// Display the new color buffer on the display
|
||||
|
||||
Reference in New Issue
Block a user