12 #include <glm/glm.hpp> 13 #include <glm/gtc/matrix_transform.hpp> 14 #include <glm/gtc/type_ptr.hpp> 19 std::vector<Vertex> vertices,
20 std::vector<GLuint> indices,
21 std::vector<Texture> textures
27 glGenVertexArrays(1, &VAO_);
28 glGenBuffers(1, &VBO_);
29 glGenBuffers(1, &EBO_);
31 glBindVertexArray(VAO_);
33 glBindBuffer(GL_ARRAY_BUFFER, VBO_);
34 glBufferData(GL_ARRAY_BUFFER, vertices_.size() *
sizeof(
Vertex), &vertices_[0], GL_STATIC_DRAW);
36 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO_);
37 glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_.size() *
sizeof(GLuint), &indices_[0], GL_STATIC_DRAW);
40 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
sizeof(
Vertex), (GLvoid*) 0);
41 glEnableVertexAttribArray(0);
44 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
sizeof(
Vertex), (GLvoid*)
sizeof(glm::vec3));
45 glEnableVertexAttribArray(1);
48 glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE,
sizeof(
Vertex), (GLvoid*) (2 *
sizeof(glm::vec3)));
49 glEnableVertexAttribArray(2);
63 GLuint specularNr = 1;
64 for (GLuint i = 0; i <
textures_.size(); ++i)
67 glActiveTexture(GL_TEXTURE0 + i);
74 if (name ==
"texture_diffuse")
76 number = std::to_string(diffuseNr++);
78 else if (name ==
"texture_specular")
80 number = std::to_string(specularNr++);
83 glUniform1i(glGetUniformLocation(shader.
get_program(), (name + number).c_str()), i);
84 glBindTexture(GL_TEXTURE_2D,
textures_[i].
id);
86 glActiveTexture(GL_TEXTURE0);
89 glBindVertexArray(
VAO_);
90 glDrawElements(GL_TRIANGLES,
indices_.size(), GL_UNSIGNED_INT, 0);
Mesh(std::vector< Vertex > vertices, std::vector< GLuint > indices, std::vector< Texture > textures)
std::vector< GLuint > indices_
const GLuint get_program()
std::vector< Texture > textures_