diff --git a/.vscode/settings.json b/.vscode/settings.json index 560de08..1ab0c10 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "fstream": "cpp", "iosfwd": "cpp", "map": "cpp", - "atomic": "cpp" + "atomic": "cpp", + "new": "cpp" } } \ No newline at end of file diff --git a/include/Model.h b/include/Model.h index 480b8b0..fd9861c 100644 --- a/include/Model.h +++ b/include/Model.h @@ -2,6 +2,7 @@ #define MODEL_H #include "Buffers.h" +#include "Texture.h" #include @@ -15,6 +16,7 @@ class Model void load_verteces(glm::vec3* verteces, GLuint count); // Загрузка вершин в буфер void load_indices(GLuint* indices, GLuint count); // Загрузка индексов в буфер void load_texCoords(glm::vec2* texCoords, GLuint count); // Загрузка текстурных координат в буфер + void set_texture(Texture& texture); // Привязка текстуры к модели glm::vec3 position; // позиция модели glm::vec3 rotation; // поворот модели @@ -27,7 +29,7 @@ class Model BO texCoords_vbo; // буфер с текстурными координатами GLuint verteces_count; // Количество вершин GLuint indices_count; // Количество индексов - + Texture texture_diffuse; // Диффузная текстура }; #endif // MODEL_H diff --git a/src/Model.cpp b/src/Model.cpp index cb797ea..e1035b1 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -9,7 +9,7 @@ Model::Model() : verteces_count(0), indices_count(0), vertex_vbo(VERTEX), index_ } // Конструктор копирования -Model::Model(const Model& copy) : vao(copy.vao), verteces_count(copy.verteces_count), indices_count(copy.indices_count), vertex_vbo(copy.vertex_vbo), index_vbo(copy.index_vbo), texCoords_vbo(copy.texCoords_vbo), position(copy.position), rotation(copy.rotation), scale(copy.scale) +Model::Model(const Model& copy) : vao(copy.vao), verteces_count(copy.verteces_count), indices_count(copy.indices_count), vertex_vbo(copy.vertex_vbo), index_vbo(copy.index_vbo), texCoords_vbo(copy.texCoords_vbo), texture_diffuse(copy.texture_diffuse), position(copy.position), rotation(copy.rotation), scale(copy.scale) { } @@ -26,6 +26,9 @@ void Model::render(const GLuint &mvp_uniform) glm::mat4 mvp = camera.getVP() * this->getTransformMatrix(); glUniformMatrix4fv(mvp_uniform, 1, GL_FALSE, &mvp[0][0]); + // Подключаем текстуры + texture_diffuse.use(); + // Подключаем VAO vao.use(); // Если есть индексы - рисуем с их использованием @@ -123,3 +126,15 @@ glm::mat4 Model::getTransformMatrix() return transformMatrix; } + +// Привязка текстуры к модели +void Model::set_texture(Texture& texture) +{ + GLuint type = texture.getType(); + switch(type) + { + case TEX_DIFFUSE: + texture_diffuse = texture; + break; + }; +} diff --git a/src/main.cpp b/src/main.cpp index 552d336..fc86f78 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -221,6 +221,7 @@ int main(void) // Текстура травы Texture grass(TEX_DIFFUSE, "../resources/textures/grass.png"); + rectangle.set_texture(grass); // Установка цвета очистки буфера цвета glClearColor(0.0f, 0.0f, 0.0f, 1.0f); @@ -237,7 +238,6 @@ int main(void) glClear(GL_COLOR_BUFFER_BIT); // Тут производится рендер - grass.use(); rectangle.render(mvp_uniform); // Представление содержимого буфера цепочки показа на окно