My OpenGL helloworld in rust. Probably the worst rust code ever :D
authorEleni Maria Stea <estea@igalia.com>
Mon, 26 Aug 2019 16:23:46 +0000 (19:23 +0300)
committerEleni Maria Stea <estea@igalia.com>
Mon, 26 Aug 2019 16:23:46 +0000 (19:23 +0300)
Cargo.toml [new file with mode: 0644]
src/main.rs [new file with mode: 0644]

diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644 (file)
index 0000000..ced8622
--- /dev/null
@@ -0,0 +1,14 @@
+[package]
+name = "rust_hw"
+version = "0.1.0"
+authors = ["Eleni Maria Stea <estea@igalia.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+gl = "0.10.0"
+
+[dependencies.sdl2]
+version = "0.32.2"
+features = ["bundled", "static-link"]
diff --git a/src/main.rs b/src/main.rs
new file mode 100644 (file)
index 0000000..a2c00e9
--- /dev/null
@@ -0,0 +1,52 @@
+extern crate sdl2;
+extern crate gl;
+
+//use std::ffi::CString;
+//pub mod draw;
+
+static _WIN_W : u32 = 800;
+static _WIN_H : u32 = 600;
+
+fn main() {
+    let _sdl = sdl2::init().unwrap();
+    let _video = _sdl.video().unwrap();
+    let _win = _video
+        .window("foobar", _WIN_W, _WIN_H)
+        .opengl() // add opengl flag
+        .resizable()
+        .build()
+        .unwrap();
+
+    let _gl_ctx = _win.gl_create_context().unwrap();
+    let _gl = gl::load_with(|s| _video.gl_get_proc_address(s) as
+                            *const std::os::raw::c_void);
+
+//    let _vsdr = draw::Shader::load_vs_code(&CString::new(include_str!("data/quad.v.glsl").unwrap.unrap();
+//    let _fsdr = draw::Shader::load_fs_code(&CString::new(include_str!("data/quad.f.glsl").unwrap.unrap();
+//    let sdr_prog = draw::Program::from_shaders(&[vsdr, fsdr]).unwrap();
+
+    unsafe {
+        gl::ClearColor(0.3, 0.1, 0.1, 1.0);
+    }
+
+    let mut event_pump = _sdl.event_pump().unwrap();
+    'main: loop {
+        for _event in event_pump.poll_iter() {
+            // handle user input here
+            match _event {
+                sdl2::event::Event::Quit {..} |
+                sdl2::event::Event::KeyDown {keycode:
+                    Some(sdl2::keyboard::Keycode::Escape), ..} =>
+                        break 'main,
+                _ => {},
+            }
+        }
+
+        unsafe {
+            gl::Clear(gl::COLOR_BUFFER_BIT);
+            gl::Viewport(0, 0, _WIN_W as i32, _WIN_H as i32);
+        }
+
+        _win.gl_swap_window();
+    }
+}