Compare commits

...

1 Commits
v0.2 ... master

4 changed files with 26 additions and 4 deletions

View File

@ -9,6 +9,7 @@
"functional": "cpp", "functional": "cpp",
"tuple": "cpp", "tuple": "cpp",
"type_traits": "cpp", "type_traits": "cpp",
"utility": "cpp" "utility": "cpp",
"new": "cpp"
} }
} }

View File

@ -2,6 +2,7 @@
#define MODEL_H #define MODEL_H
#include "Buffers.h" #include "Buffers.h"
#include "Texture.h"
#include <GLM/glm.hpp> #include <GLM/glm.hpp>
#include <GLM/gtc/quaternion.hpp> #include <GLM/gtc/quaternion.hpp>
@ -65,6 +66,7 @@ class Model : public Node
void load_indices(GLuint* indices, GLuint count); // Загрузка индексов в буфер void load_indices(GLuint* indices, GLuint count); // Загрузка индексов в буфер
void load_texCoords(glm::vec2* texCoords, GLuint count); // Загрузка текстурных координат в буфер void load_texCoords(glm::vec2* texCoords, GLuint count); // Загрузка текстурных координат в буфер
void set_index_range(size_t first_byteOffset, size_t count); // Ограничение диапазона из буфера индексов void set_index_range(size_t first_byteOffset, size_t count); // Ограничение диапазона из буфера индексов
void set_texture(Texture& texture); // Привязка текстуры к модели
private: private:
VAO vao; VAO vao;
@ -72,6 +74,7 @@ class Model : public Node
BO texCoords_vbo; // буфер с текстурными координатами BO texCoords_vbo; // буфер с текстурными координатами
GLuint verteces_count; // Количество вершин GLuint verteces_count; // Количество вершин
size_t first_index_byteOffset, indices_count; // Сдвиг в байтах для первого и количество индексов size_t first_index_byteOffset, indices_count; // Сдвиг в байтах для первого и количество индексов
Texture texture_diffuse; // Диффузная текстура
}; };
#endif // MODEL_H #endif // MODEL_H

View File

@ -211,7 +211,8 @@ vertex_vbo(VERTEX), index_vbo(ELEMENT), texCoords_vbo(VERTEX)
Model::Model(const Model& copy) : Node(copy), Model::Model(const Model& copy) : Node(copy),
vao(copy.vao), vao(copy.vao),
verteces_count(copy.verteces_count), first_index_byteOffset(copy.first_index_byteOffset), indices_count(copy.indices_count), 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)
{ {
} }
@ -230,6 +231,8 @@ Model& Model::operator=(const Model& other)
index_vbo = other.index_vbo; index_vbo = other.index_vbo;
texCoords_vbo = other.texCoords_vbo; texCoords_vbo = other.texCoords_vbo;
texture_diffuse = other.texture_diffuse;
return *this; return *this;
} }
@ -244,6 +247,9 @@ void Model::render(const GLuint &model_uniform)
// Загрузим матрицу трансформации // Загрузим матрицу трансформации
glUniformMatrix4fv(model_uniform, 1, GL_FALSE, &getTransformMatrix()[0][0]); glUniformMatrix4fv(model_uniform, 1, GL_FALSE, &getTransformMatrix()[0][0]);
// Подключаем текстуры
texture_diffuse.use();
// Подключаем VAO // Подключаем VAO
vao.use(); vao.use();
// Если есть индексы - рисуем с их использованием // Если есть индексы - рисуем с их использованием
@ -333,3 +339,15 @@ void Model::set_index_range(size_t first_byteOffset, size_t count)
first_index_byteOffset = first_byteOffset; first_index_byteOffset = first_byteOffset;
indices_count = count; indices_count = count;
} }
// Привязка текстуры к модели
void Model::set_texture(Texture& texture)
{
GLuint type = texture.getType();
switch(type)
{
case TEX_DIFFUSE:
texture_diffuse = texture;
break;
};
}

View File

@ -220,6 +220,7 @@ int main(void)
// Текстура травы // Текстура травы
Texture grass(TEX_DIFFUSE, "../resources/textures/grass.png"); Texture grass(TEX_DIFFUSE, "../resources/textures/grass.png");
rectangle.set_texture(grass);
// Установка цвета очистки буфера цвета // Установка цвета очистки буфера цвета
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
@ -240,7 +241,6 @@ int main(void)
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
// Тут производится рендер // Тут производится рендер
grass.use(); // Привязка текстуры как активной
rectangle.render(model_uniform); rectangle.render(model_uniform);
// Представление содержимого буфера цепочки показа на окно // Представление содержимого буфера цепочки показа на окно