Skip to content

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

Notifications You must be signed in to change notification settings

Stolkerve/easy-opengl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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());
}

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages