1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//! # easy-opengl
//!
//! `easy-opengl` is a collection of utilities to make opengl app
//! more quickly and easy without losing custumization and freedom
//! # Example
//! ``` rust
//!extern crate gl;
//!extern crate sdl2;
//!
//!use easy_opengl::buffers::*;
//!use easy_opengl::shader::*;
//!use easy_opengl::textures::*;
//!
//!use sdl2::event::Event;
//!use sdl2::event::WindowEvent;
//!
//!const SCR_WIDTH: u32 = 800;
//!const SCR_HEIGHT: u32 = 600;
//!
//!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;
//!
//!    void main() {
//!        FragColor = texture(texture1, TexCoord) * color;
//!    }
//!"#;
//!
//!pub struct Window {
//!    pub sdl_context: sdl2::Sdl,
//!    pub sdl_window: sdl2::video::Window,
//!    pub gl_context: sdl2::video::GLContext,
//!    pub event_pump: sdl2::EventPump,
//!    pub name: String,
//!    pub width: u32,
//!    pub height: u32,
//!}
//!
//!impl Window {
//!    pub fn new(width: u32, height: u32, name: String) -> Self {
//!        let sdl_context = sdl2::init().unwrap();
//!        let video_subsystem = sdl_context.video().unwrap();
//!
//!        let window = video_subsystem
//!            .window("Titulo", width.clone(), height.clone())
//!            .opengl()
//!            .resizable()
//!            .build()
//!            .unwrap();
//!
//!        let gl_context = window.gl_create_context().unwrap();
//!        gl::load_with(|name| video_subsystem.gl_get_proc_address(name) as *const std::ffi::c_void);
//!        let mut event_pump = sdl_context.event_pump().unwrap();
//!
//!        Self {
//!            sdl_context,
//!            sdl_window: window,
//!            gl_context,
//!            event_pump,
//!            width,
//!            height,
//!            name,
//!        }
//!    }
//!}
//!
//!pub fn main() {
//!    let mut window = Window::new(SCR_WIDTH, SCR_HEIGHT, "Test".to_string());
//!    let mut shader = Shader::new();
//!    shader.load_from_memory(VERTEX_SHADER_SOURCE, FRAGMENT_SHADER_SOURCE, None);
//!
//!    let vertices = vec![
//!        0.5, 0.5, 0.0, 1.0, 1.0, // top right
//!        0.5, -0.5, 0.0, 1.0, 0.0, // bottom right
//!        -0.5, -0.5, 0.0, 0.0, 0.0, // bottom left
//!        -0.5, 0.5, 0.0, 0.0, 1.0, // top left
//!    ];
//!    let indices = vec![
//!        0, 1, 3, // first Triangle
//!        1, 2, 3, // second Triangle
//!    ];
//!
//!    let vao = VertexArray::new();
//!    // Is important keep alive the variable, because when is out of scope it will destroy the buffer
//!    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()),
//!    ]);
//!
//!    // Is important keep alive the variable, because when is out of scope it will destroy the buffer
//!    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());
//!
//!    'main: loop {
//!        window.sdl_window.gl_swap_window();
//!        for event in window.event_pump.poll_iter() {
//!            unsafe {
//!                gl::ClearColor(0.1, 0.1, 0.1, 1.0);
//!                gl::Clear(gl::COLOR_BUFFER_BIT);
//!                texture.bind();
//!                shader.bind();
//!                shader.set_uniform("color", UniformType::Fv4(1.0, 0.4, 0.1, 1.0));
//!                vao.bind();
//!                gl::DrawElements(
//!                    gl::TRIANGLES,
//!                    indices.len() as i32,
//!                    gl::UNSIGNED_INT,
//!                    std::ptr::null(),
//!                );
//!            }
//!            match event {
//!                Event::Quit { .. } => {
//!                    break 'main;
//!                }
//!                Event::Window {
//!                    timestamp,
//!                    window_id,
//!                    win_event,
//!                } => match win_event {
//!                    WindowEvent::Resized(w, h) => unsafe {
//!                        gl::Viewport(0, 0, w, h);
//!                    },
//!                    _ => {}
//!                },
//!                _ => {}
//!            }
//!        }
//!        // ::std::thread::sleep(::std::time::Duration::new(0, 1_000_000_000u32 / 60));
//!    }
//!}
//! ```

#[allow(dead_code)]
pub mod buffers;
pub mod shader;
pub mod textures;