fix #6 (although still nothing renders)
This commit is contained in:
@@ -8,5 +8,5 @@ out vec4 FragColor;
|
||||
void main()
|
||||
{
|
||||
// FragColor = vec4(fragPos, 1.0);
|
||||
FragColor = vec4(1.0, 1.0, 1.0 , 1.0);
|
||||
FragColor = vec4(1.0);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ impl PerspectiveCamera {
|
||||
front,
|
||||
position,
|
||||
intrinsic_coordinates: coordinates,
|
||||
fov: fov.unwrap_or(45.0),
|
||||
fov: fov.unwrap_or(75.0),
|
||||
movement_speed: movement_speed.unwrap_or(2.5),
|
||||
aspect_ratio: None,
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ impl OctaSphere {
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_sphere(&mut self) {
|
||||
pub fn generate_sphere(&mut self) {
|
||||
let (vertices, indices) = self.generator.generate_sphere();
|
||||
self.mesh = Some(Mesh::new(vertices, indices))
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ impl Mesh {
|
||||
mesh_data.push(self.normals[i].z);
|
||||
}
|
||||
|
||||
Self::fill_buffer(mesh_data.as_ptr() as *const u8, mesh_data.len(), self.vbo, gl);
|
||||
Self::fill_buffer(self.indices.as_ptr() as *const u8, self.indices.len(), self.ebo, gl);
|
||||
Self::fill_buffer(mesh_data.as_ptr() as *const u8, mesh_data.len(), self.vbo, glow::ARRAY_BUFFER, gl);
|
||||
Self::fill_buffer(self.indices.as_ptr() as *const u8, self.indices.len(), self.ebo, glow::ELEMENT_ARRAY_BUFFER, gl);
|
||||
|
||||
// vertices
|
||||
gl.enable_vertex_attrib_array(0);
|
||||
@@ -83,16 +83,16 @@ impl Mesh {
|
||||
|
||||
// normals
|
||||
gl.enable_vertex_attrib_array(1);
|
||||
gl.vertex_attrib_pointer_f32(0, 3, glow::FLOAT, false, 6 * size_of::<f32>() as i32, 0); // stride is (6 * size_of::<f32>) because 3 for vertices and 3 for normals
|
||||
gl.vertex_attrib_pointer_f32(0, 3, glow::FLOAT, false, 6 * size_of::<f32>() as i32, 3 * size_of::<f32>() as i32); // stride is (6 * size_of::<f32>) because 3 for vertices and 3 for normals
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn fill_buffer(data: *const u8, num_elements: usize, dst_buffer: Option<NativeBuffer>, gl: &Context) {
|
||||
unsafe fn fill_buffer(data: *const u8, num_elements: usize, dst_buffer: Option<NativeBuffer>, buffer_target: u32, gl: &Context) {
|
||||
unsafe {
|
||||
let mesh_data_u8: &[u8] = std::slice::from_raw_parts(data, num_elements * size_of::<f32>());
|
||||
|
||||
gl.bind_buffer(glow::ARRAY_BUFFER, dst_buffer);
|
||||
gl.buffer_data_u8_slice(glow::ARRAY_BUFFER, mesh_data_u8, glow::STATIC_DRAW);
|
||||
gl.bind_buffer(buffer_target, dst_buffer);
|
||||
gl.buffer_data_u8_slice(buffer_target, mesh_data_u8, glow::STATIC_DRAW);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ impl ApplicationHandler for Nebulix {
|
||||
let(gl, gl_context, gl_surface, window) = create_window_with_gl_context(event_loop);
|
||||
|
||||
unsafe {
|
||||
gl.clear_color(0.0, 0.0, 0.0, 1.0);
|
||||
gl.clear_color(0.2, 0.5, 0.8, 1.0);
|
||||
}
|
||||
|
||||
self.camera.update_aspect(&window.inner_size().to_logical(window.scale_factor()));
|
||||
@@ -116,6 +116,7 @@ impl ApplicationHandler for Nebulix {
|
||||
self.camera.process_mouse(self.input.get_mouse_offset());
|
||||
let mut move_direction: Vector3<f32> = Vector3::zeros();
|
||||
|
||||
if self.input.is_special_key_pressed(NamedKey::Escape) {event_loop.exit()}
|
||||
if self.input.is_key_pressed("a") { move_direction.x -= 1.0f32; }
|
||||
if self.input.is_key_pressed("d") { move_direction.x += 1.0f32; }
|
||||
if self.input.is_key_pressed("w") { move_direction.z -= 1.0f32; }
|
||||
@@ -129,7 +130,7 @@ impl ApplicationHandler for Nebulix {
|
||||
let gl_surface = self.gl_surface.as_ref().unwrap();
|
||||
let gl_context = self.gl_context.as_ref().unwrap();
|
||||
|
||||
let model_matrix = Matrix4::new_translation(&Vector3::new(0.0f32, 0.0f32, -3.0f32));
|
||||
let model_matrix = Matrix4::new_translation(&Vector3::new(0f32, 0f32, -3f32));
|
||||
let view_matrix = self.camera.view_matrix();
|
||||
let projection_matrix = self.camera.projection_matrix();
|
||||
|
||||
@@ -138,14 +139,14 @@ impl ApplicationHandler for Nebulix {
|
||||
}
|
||||
|
||||
// Custom code HERE
|
||||
let mut sphere = OctaSphere::new(2).unwrap();
|
||||
let mut sphere = OctaSphere::new(10).unwrap();
|
||||
let sphere_shader = Shader::new(gl, "./resources/shaders/sphere.vert".into(), "./resources/shaders/sphere.frag".into()).unwrap();
|
||||
|
||||
sphere_shader.use_shader();
|
||||
sphere_shader.set_matrix4_f32("modelMatrix", model_matrix);
|
||||
sphere_shader.set_matrix4_f32("viewMatrix", view_matrix);
|
||||
sphere_shader.set_matrix4_f32("projectionMatrix", projection_matrix);
|
||||
|
||||
sphere_shader.use_shader();
|
||||
sphere.render(gl);
|
||||
|
||||
gl_surface.swap_buffers(&gl_context).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user