This commit is contained in:
2025-08-27 21:23:52 +02:00
parent 4cf8cfcfc4
commit 3a2ae50444
3 changed files with 49 additions and 28 deletions

View File

@@ -1,8 +1,8 @@
#version 430 core
#version 450 core
out vec4 color;
void main()
{
color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
}
}

View File

@@ -1,8 +1,8 @@
#version 430 core
#version 450 core
in vec3 position;
in layout(location=0) vec3 position;
void main()
{
gl_Position = vec4(position, 1.0f);
}
}

View File

@@ -52,22 +52,43 @@ fn offset<T>(n: u32) -> *const c_void {
// ptr::null()
// == // Generate your VAO here
unsafe fn create_vao(vertices: &Vec<f32>, indices: &Vec<u32>) -> u32 {
// Implement me!
// generate a VAO and bind it
let mut vao_id: u32 = 0;
gl::GenVertexArrays(1, &mut vao_id);
gl::BindVertexArray(vao_id);
// Also, feel free to delete comments :)
// generate a VBO and bind it
let mut vbo_id: u32 = 0;
gl::GenBuffers(1, &mut vbo_id);
gl::BindBuffer(gl::ARRAY_BUFFER, vbo_id);
// This should:
// * Generate a VAO and bind it
// * Generate a VBO and bind it
// * Fill it with data
// * Configure a VAP for the data and enable it
// * Generate a IBO and bind it
// * Fill it with data
// * Return the ID of the VAO
// fill it with data
gl::BufferData(
gl::ARRAY_BUFFER,
byte_size_of_array(&vertices),
pointer_to_array(&vertices),
gl::STATIC_DRAW
);
0
// configure a VAP for the data and enable it
gl::VertexAttribPointer(0, 3, gl::FLOAT, gl::FALSE, size_of::<f32>()*3, ptr::null());
gl::EnableVertexAttribArray(0);
// generate a IBO and bind it
let mut ibo_id: u32 = 0;
gl::GenBuffers(1, &mut ibo_id);
gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, ibo_id);
// fill it with data
gl::BufferData(
gl::ELEMENT_ARRAY_BUFFER,
byte_size_of_array(&indices),
pointer_to_array(&indices),
gl::STATIC_DRAW
);
return vao_id;
}
@@ -130,9 +151,13 @@ fn main() {
println!("GLSL\t: {}", util::get_gl_string(gl::SHADING_LANGUAGE_VERSION));
}
// == // Set up your VAO around here
let my_vao = unsafe { 1337 };
let vertices = vec![
-0.6, -0.6, 0.0,
0.6, -0.6, 0.0,
0.0, 0.6, 0.0
];
let indices = vec![ 0, 1, 2 ];
let vao_id = unsafe { create_vao(&vertices, &indices) };
// == // Set up your shaders here
@@ -144,13 +169,13 @@ fn main() {
// This snippet is not enough to do the exercise, and will need to be modified (outside
// of just using the correct path), but it only needs to be called once
/*
let simple_shader = unsafe {
shader::ShaderBuilder::new()
.attach_file("./path/to/simple/shader.file")
.attach_file("./shaders/simple.vert")
.attach_file("./shaders/simple.frag")
.link()
};
*/
unsafe { simple_shader.activate(); };
// Used to demonstrate keyboard handling for exercise 2.
@@ -215,11 +240,7 @@ fn main() {
gl::ClearColor(0.035, 0.046, 0.078, 1.0); // night sky
gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
// == // Issue the necessary gl:: commands to draw your scene here
gl::DrawElements(gl::TRIANGLE_STRIP, 3, gl::UNSIGNED_INT, ptr::null());
}
// Display the new color buffer on the display