WebGL-rs
Demos:
To run the example in "example" folder, run:
cd ./example
cargo web start --target-webasm
Example from https://www.tutorialspoint.com/webgl/webgl_drawing_a_triangle.htm in Rust
let size = ;
let config = new;
let mut app = new;
let vertices: = vec!;
let indices: = vec!;
let count = indices.len;
load_with;
let gl = new;
// Create an empty buffer object to store vertex buffer
let vertex_buffer = gl.create_buffer;
// Bind appropriate array buffer to it
gl.bind_buffer;
// Pass the vertex data to the buffer
gl.buffer_data;
// Unbind the buffer
gl.unbind_buffer;
// Create an empty buffer object to store Index buffer
let index_buffer = gl.create_buffer;
// Bind appropriate array buffer to it
gl.bind_buffer;
// Pass the vertex data to the buffer
gl.buffer_data;
// Unbind the buffer
gl.unbind_buffer;
/*================ Shaders ====================*/
// Vertex shader source code
let vert_code = "attribute vec3 coordinates;
void main(void) {
gl_Position = vec4(coordinates, 1.0);
}";
// Create a vertex shader object
let vert_shader = gl.create_shader;
// Attach vertex shader source code
gl.shader_source;
// Compile the vertex shader
gl.compile_shader;
//fragment shader source code
let frag_code = "void main(void) {
gl_FragColor = vec4(1, 0.5, 0.0, 1);
}";
// Create fragment shader object
let frag_shader = gl.create_shader;
// Attach fragment shader source code
gl.shader_source;
// Compile the fragmentt shader
gl.compile_shader;
// Create a shader program object to store
// the combined shader program
let shader_program = gl.create_program;
// Attach a vertex shader
gl.attach_shader;
// Attach a fragment shader
gl.attach_shader;
// Link both the programs
gl.link_program;
// Use the combined shader program object
gl.use_program;
/*======= Associating shaders to buffer objects =======*/
// Bind vertex buffer object
gl.bind_buffer;
// Bind index buffer object
gl.bind_buffer;
// Get the attribute location
let coord = gl.get_attrib_location
.unwrap;
// Point an attribute to the currently bound VBO
gl.vertex_attrib_pointer;
// Enable the attribute
gl.enable_vertex_attrib_array;
/*=========Drawing the triangle===========*/
// Clear the canvas
gl.clear_color;
// Enable the depth test
gl.enable;
// Clear the color buffer bit
gl.clear;
gl.clear;
// Set the view port
gl.viewport;
app.run;