Шейдер с учетом mvp

This commit is contained in:
2022-12-15 13:45:11 +03:00
parent 795aac516d
commit e64d62b56f
6 changed files with 25 additions and 9 deletions

View File

@@ -238,8 +238,11 @@ Model::~Model()
}
// Вызов отрисовки
void Model::render()
void Model::render(const GLuint &model_uniform)
{
// Загрузим матрицу трансформации
glUniformMatrix4fv(model_uniform, 1, GL_FALSE, &getTransformMatrix()[0][0]);
// Подключаем VAO
vao.use();
// Если есть индексы - рисуем с их использованием

View File

@@ -27,10 +27,10 @@ Scene& Scene::operator=(const Scene& other)
}
// Рендер сцены
void Scene::render()
void Scene::render(const GLuint &model_uniform)
{
for (auto & model : models)
model.render();
model.render(model_uniform);
}
// Перестройка узлов выбранного списка

View File

@@ -5,6 +5,7 @@
#include <iostream>
#include "Camera.h"
#include "Model.h"
#define WINDOW_WIDTH 800
@@ -112,6 +113,7 @@ GLuint LoadShaders(const char *vertex_file, const char *fragment_file)
return programID;
}
int main(void)
{
GLFWwindow* window; // Указатель на окно GLFW3
@@ -174,19 +176,28 @@ int main(void)
// Загрузка индексов модели
rectangle.load_indices(indices, sizeof(indices));
rectangle.e_position().z = 2;
rectangle.e_rotation() = {0.733f, 0.462f, 0.191f, 0.462f};
// Установка цвета очистки буфера цвета
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
// Расположение Uniform-переменной
GLuint vp_uniform = glGetUniformLocation(shaderProgram, "vp");
GLuint model_uniform = glGetUniformLocation(shaderProgram, "model");
// Пока не произойдет событие запроса закрытия окна
while(!glfwWindowShouldClose(window))
{
// Загрузим матрицу проекции*вида
glUniformMatrix4fv(vp_uniform, 1, GL_FALSE, &Camera::current().getVP()[0][0]);
// Очистка буфера цвета
glClear(GL_COLOR_BUFFER_BIT);
// Тут производится рендер
rectangle.render();
rectangle.render(model_uniform);
// Представление содержимого буфера цепочки показа на окно
glfwSwapBuffers(window);