From c4b60ac55213c4af07f81999cd851403677e9930 Mon Sep 17 00:00:00 2001 From: "re.kovalev" Date: Mon, 14 Nov 2022 19:47:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=B2=D1=8F=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D1=83=D1=80=D1=8B=20?= =?UTF-8?q?=D0=BA=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 ++- include/Model.h | 3 +++ src/Model.cpp | 20 +++++++++++++++++++- src/main.cpp | 4 ++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f3d0974..98bbebb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,7 @@ "functional": "cpp", "tuple": "cpp", "type_traits": "cpp", - "utility": "cpp" + "utility": "cpp", + "new": "cpp" } } \ No newline at end of file diff --git a/include/Model.h b/include/Model.h index d8bc976..d79e677 100644 --- a/include/Model.h +++ b/include/Model.h @@ -2,6 +2,7 @@ #define MODEL_H #include "Buffers.h" +#include "Texture.h" #include #include @@ -65,6 +66,7 @@ class Model : public Node void load_indices(GLuint* indices, GLuint count); // Загрузка индексов в буфер void load_texCoords(glm::vec2* texCoords, GLuint count); // Загрузка текстурных координат в буфер void set_index_range(size_t first_byteOffset, size_t count); // Ограничение диапазона из буфера индексов + void set_texture(Texture& texture); // Привязка текстуры к модели private: VAO vao; @@ -72,6 +74,7 @@ class Model : public Node BO texCoords_vbo; // буфер с текстурными координатами GLuint verteces_count; // Количество вершин size_t first_index_byteOffset, indices_count; // Сдвиг в байтах для первого и количество индексов + Texture texture_diffuse; // Диффузная текстура }; #endif // MODEL_H diff --git a/src/Model.cpp b/src/Model.cpp index ba70e80..eec4ac8 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -211,7 +211,8 @@ vertex_vbo(VERTEX), index_vbo(ELEMENT), texCoords_vbo(VERTEX) Model::Model(const Model& copy) : Node(copy), vao(copy.vao), verteces_count(copy.verteces_count), first_index_byteOffset(copy.first_index_byteOffset), indices_count(copy.indices_count), -vertex_vbo(copy.vertex_vbo), index_vbo(copy.index_vbo), texCoords_vbo(copy.texCoords_vbo) +vertex_vbo(copy.vertex_vbo), index_vbo(copy.index_vbo), texCoords_vbo(copy.texCoords_vbo), +texture_diffuse(copy.texture_diffuse) { } @@ -229,6 +230,8 @@ Model& Model::operator=(const Model& other) vertex_vbo = other.vertex_vbo; index_vbo = other.index_vbo; texCoords_vbo = other.texCoords_vbo; + + texture_diffuse = other.texture_diffuse; return *this; } @@ -244,6 +247,9 @@ void Model::render(const GLuint &model_uniform) // Загрузим матрицу трансформации glUniformMatrix4fv(model_uniform, 1, GL_FALSE, &getTransformMatrix()[0][0]); + // Подключаем текстуры + texture_diffuse.use(); + // Подключаем VAO vao.use(); // Если есть индексы - рисуем с их использованием @@ -333,3 +339,15 @@ void Model::set_index_range(size_t first_byteOffset, size_t count) first_index_byteOffset = first_byteOffset; indices_count = count; } + +// Привязка текстуры к модели +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 f054b2b..4675026 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -220,6 +220,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); @@ -240,9 +241,8 @@ int main(void) glClear(GL_COLOR_BUFFER_BIT); // Тут производится рендер - grass.use(); // Привязка текстуры как активной rectangle.render(model_uniform); - + // Представление содержимого буфера цепочки показа на окно glfwSwapBuffers(window); // Обработка системных событий