Compare commits

...

2 Commits
v0.2 ... master

6 changed files with 47 additions and 9 deletions

View File

@ -59,12 +59,12 @@ class Model : public Node
Model& operator=(const Model& other); // Оператор присваивания
virtual ~Model();
void render(); // Вызов отрисовки
void render(const GLuint &model_uniform); // Вызов отрисовки
void load_verteces(glm::vec3* verteces, GLuint count); // Загрузка вершин в буфер
void load_indices(GLuint* indices, GLuint count); // Загрузка индексов в буфер
void set_index_range(size_t first_byteOffset, size_t count); // Ограничение диапазона из буфера индексов
private:
VAO vao;
BO vertex_vbo, index_vbo; // вершинный и индексный буферы

View File

@ -14,7 +14,7 @@ class Scene
Scene(const Scene &copy); // Конструктор копирования
Scene& operator=(const Scene& other); // Оператор присваивания
void render(); // Рендер сцены
void render(const GLuint &model_uniform); // Рендер сцены
Node root; // Корневой узел

View File

@ -2,8 +2,10 @@
layout(location = 0) in vec3 pos;
uniform mat4 vp;
uniform mat4 model;
void main()
{
gl_Position.xyz = pos;
gl_Position.w = 1.0;
gl_Position = vp * model * vec4(pos, 1.0);
}

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,26 @@ GLuint LoadShaders(const char *vertex_file, const char *fragment_file)
return programID;
}
bool firstMouse = true;
float lastX, lastY;
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
{
if (firstMouse)
{
lastX = xpos;
lastY = ypos;
firstMouse = false;
}
glm::vec2 offset(xpos - lastX, lastY - ypos);
lastX = xpos;
lastY = ypos;
Camera::current().rotate(offset);
}
int main(void)
{
GLFWwindow* window; // Указатель на окно GLFW3
@ -145,6 +166,9 @@ int main(void)
glfwSwapInterval(1); // Вертикальная синхронизация
// Установка callback-функции для мыши и камеры
glfwSetCursorPosCallback(window, mouse_callback);
// Загрузка функций OpenGL с помощью GLAD
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
@ -174,19 +198,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);