use glfw::{Action, Context, Key};
use image::GenericImageView;
use moai::MoaiWindow;
use moai::gl::{VBO, VertexAttrib};
use moai::shader::Shader;
fn main() {
env_logger::init();
let mut window = MoaiWindow::new(String::from("Moai Square"), (3,3), [900,600]);
unsafe { gl::Viewport(0, 0, 900, 600) };
unsafe { gl::ClearColor(0.03, 0.01, 0.08, 1.0) };
let vertices: [f32; 32] = [
0.5, 0.5, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.5, -0.5, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, -0.5, -0.5, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, -0.5, 0.5, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0 ];
let indices = [
0, 1, 3, 1, 2, 3 ];
let shader = Shader::new().unwrap();
let vb = VBO::new(&vertices, &indices);
vb.set_layout(8,&[
VertexAttrib {size: 3, vtype: gl::FLOAT, normal: gl::FALSE}, VertexAttrib {size: 3, vtype: gl::FLOAT, normal: gl::FALSE}, VertexAttrib {size: 2, vtype: gl::FLOAT, normal: gl::FALSE}, ]);
let img = image::open("examples/moai.png").expect("Couldn't open image (bruh)").flipv();
let tid = unsafe {
let tid = moai::gl::texture::gen_texture();
moai::gl::texture::set_texture_data(
tid,
img.as_bytes(),
img.dimensions(),
true
);
tid
};
shader.bind();
let bruh: glam::Vec4 = glam::Vec4::new(1.0,0.6,0.3, 1.0);
shader.set_vec4("col", bruh);
while !window.window.should_close() {
unsafe { gl::Clear(gl::COLOR_BUFFER_BIT) };
unsafe {
shader.bind();
vb.bind();
gl::BindTexture(gl::TEXTURE_2D, tid);
gl::DrawElements(gl::TRIANGLES, vb.indices_size, gl::UNSIGNED_INT, std::ptr::null());
}
window.window.swap_buffers();
window.glfw.poll_events();
for (_, event) in glfw::flush_messages(&window.events) {
println!("{:?}", event);
match event {
glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => {
window.window.set_should_close(true)
},
_ => {},
}
}
}
}