try to line this up with open.gl tutorial

This commit is contained in:
Brandon Thomas committed 2020-04-12 22:04:18 -04:00
1 parent 3ec973d123
commit d7cc98b1ab
2 files changed
+43 -13

No files matched your search

+41 -10
View File
@@ -18,24 +18,53 @@ use glutin::ContextBuilder;
//use shader::Shader;
// Vertex data
static VERTEX_DATA: [GLfloat; 6] = [0.0, 0.5, 0.5, -0.5, -0.5, -0.5];
// Shader sources
static VS_SRC: &'static str = "
#version 150
#version 150 core
in vec2 position;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
//gl_Position = vec4(position.x, position.y, 0.0, 1.0);
}";
static FS_SRC: &'static str = "
#version 150
#version 150 core
out vec4 out_color;
void main() {
out_color = vec4(1.0, 1.0, 1.0, 1.0);
}";
// Vertex data
// static VERTEX_DATA: [GLfloat; 6] = [0.0, 0.5, 0.5, -0.5, -0.5, -0.5];
static VERTEX_DATA: [GLfloat; 6] = [
/*// Triangle 1
-0.5, 0.5,
0.5, 0.5,
0.5, -0.5,
// Triangle 2 -- doesn't work
0.5, -0.5,
-0.5, 0.5,
-0.5, -0.5,*/
// from open.gl tutorial
0.0, 0.5, // Vertex 1 (X, Y)
0.5, -0.5, // Vertex 2 (X, Y)
-0.5, -0.5 // Vertex 3 (X, Y)
/*// From open.gl tutorial - square
-0.5, 0.5, 1.0, 0.0, 0.0, // Top-left
0.5, 0.5, 0.0, 1.0, 0.0, // Top-right
0.5, -0.5, 0.0, 0.0, 1.0, // Bottom-right
-0.5, -0.5, 1.0, 1.0, 1.0 // Bottom-left*/
];
static ELEMENTS: [GLint; 6] = [
// From open.gl tutorial
0, 1, 2,
2, 3, 0,
];
pub fn run() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new();
@@ -54,14 +83,10 @@ pub fn run() {
let fs = compile_shader(FS_SRC, gl::FRAGMENT_SHADER);
let program = link_program(vs, fs);
let mut vao = 0;
let mut vbo = 0;
let mut vao = 0;
unsafe {
// Create Vertex Array Object
gl::GenVertexArrays(1, &mut vao);
gl::BindVertexArray(vao);
// Create a Vertex Buffer Object and copy the vertex data to it
gl::GenBuffers(1, &mut vbo);
gl::BindBuffer(gl::ARRAY_BUFFER, vbo);
@@ -72,6 +97,10 @@ pub fn run() {
gl::STATIC_DRAW,
);
// Create Vertex Array Object
gl::GenVertexArrays(1, &mut vao);
gl::BindVertexArray(vao);
// Use shader program
gl::UseProgram(program);
gl::BindFragDataLocation(program, 0, CString::new("out_color").unwrap().as_ptr());
@@ -114,6 +143,8 @@ pub fn run() {
gl::Clear(gl::COLOR_BUFFER_BIT);
// Draw a triangle from the 3 vertices
gl::DrawArrays(gl::TRIANGLES, 0, 3);
//gl::DrawElements(gl::TRIANGLES, 6, gl::UNSIGNED_INT, std::ptr::null())
}
gl_window.swap_buffers().unwrap();
},
+2 -3
View File
@@ -62,10 +62,9 @@ pub mod old_k4a_wrapper;
pub mod sensor_control;
pub fn main() {
let capture_provider = Arc::new(CaptureProvider::new());
/*let capture_provider = Arc::new(CaptureProvider::new());
let capture_provider2= capture_provider.clone();
thread::spawn(move || capture_thread(capture_provider));
thread::spawn(move || capture_thread(capture_provider));*/
//graphics_grr::run(capture_provider2).unwrap();
//graphics_glium::run_glium();