easy-opengl

Crates.ioeasy-opengl
lib.rseasy-opengl
version0.1.3
sourcesrc
created_at2022-11-05 23:15:44.443985
updated_at2022-11-13 20:02:01.572425
descriptionA set of tools to make easy opengl without lossing custumization and freedom
homepage
repositoryhttps://github.com/Stolkerve/easy-opengl
max_upload_size
id706190
size37,481
(Stolkerve)

documentation

README

Crates.io

easy-opengl is a collection of utilities to make opengl app more quickly and easy without losing custumization and freedom.

Example

use easy_opengl::buffers::*;
use easy_opengl::shader::*;
use easy_opengl::textures::*;

const VERTEX_SHADER_SOURCE: &str = r#"
    #version 330 core
    layout (location = 0) in vec3 aPos;
    layout (location = 1) in vec2 aTexCoord;

    out vec2 TexCoord;

    void main() {
       gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
       TexCoord = aTexCoord;
    }
"#;

const FRAGMENT_SHADER_SOURCE: &str = r#"
    #version 330 core
    out vec4 FragColor;
    in vec2 TexCoord;

    uniform sampler2D texture1;
    uniform vec4 color = vec4(1.0);

    void main() {
        FragColor = texture(texture1, TexCoord) * color;
    }
"#;

pub struct Vertex {
    pub pos: [f32; 3],
    pub uv: [f32; 2],
}


pub fn main() {
    let mut shader = Shader::new();
    shader.load_from_memory(VERTEX_SHADER_SOURCE, FRAGMENT_SHADER_SOURCE, None);

    let vertices = vec![
        Vertex {
            pos: [0.5, 0.5, 0.0],
            uv: [1.0, 1.0],
        }, // top right
        Vertex {
            pos: [0.5, -0.5, 0.0],
            uv: [1.0, 0.0],
        }, // bottom right
        Vertex {
            pos: [-0.5, -0.5, 0.0],
            uv: [0.0, 0.0],
        }, // bottom left
        Vertex {
            pos: [-0.5, 0.5, 0.0],
            uv: [0.0, 1.0],
        }, // top left
    ];
    let indices = vec![
        0, 1, 3, // first Triangle
        1, 2, 3, // second Triangle
    ];

    let vao = VertexArray::new();
    let _vbo = VertexBuffer::new(calc_bytes_size(&vertices) as isize, Some(&vertices));

    vao.bind();

    submit_vertex_attribs(&mut vec![
        VertexAttrib::new(VertexAttribType::Float3, false, "aPos".to_string()),
        VertexAttrib::new(VertexAttribType::Float2, false, "aTexCoord".to_string()),
    ]);

    let _ibo = IndexBuffer::new(calc_bytes_size(&indices) as isize, Some(&indices));

    let mut texture = Texture2D::new();
    texture.load_from_file("./a.png", TextureConfig::new());
}
Commit count: 10

cargo fmt