Шейдер с учетом mvp
This commit is contained in:
		
							parent
							
								
									ba2e9ca695
								
							
						
					
					
						commit
						86f8035b32
					
				| @ -59,7 +59,7 @@ class Model : public Node | |||||||
|         Model& operator=(const Model& other); // Оператор присваивания
 |         Model& operator=(const Model& other); // Оператор присваивания
 | ||||||
|         virtual ~Model(); |         virtual ~Model(); | ||||||
| 
 | 
 | ||||||
|         void render(); // Вызов отрисовки
 |         void render(const GLuint &model_uniform); // Вызов отрисовки
 | ||||||
| 
 | 
 | ||||||
|         void load_verteces(glm::vec3* verteces, GLuint count); // Загрузка вершин в буфер
 |         void load_verteces(glm::vec3* verteces, GLuint count); // Загрузка вершин в буфер
 | ||||||
|         void load_indices(GLuint* indices, GLuint count); // Загрузка индексов в буфер
 |         void load_indices(GLuint* indices, GLuint count); // Загрузка индексов в буфер
 | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ class Scene | |||||||
|         Scene(const Scene ©); // Конструктор копирования
 |         Scene(const Scene ©); // Конструктор копирования
 | ||||||
|         Scene& operator=(const Scene& other); // Оператор присваивания
 |         Scene& operator=(const Scene& other); // Оператор присваивания
 | ||||||
| 
 | 
 | ||||||
|         void render(); // Рендер сцены
 |         void render(const GLuint &model_uniform); // Рендер сцены
 | ||||||
| 
 | 
 | ||||||
|         Node root; // Корневой узел
 |         Node root; // Корневой узел
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -2,8 +2,10 @@ | |||||||
| 
 | 
 | ||||||
| layout(location = 0) in vec3 pos;  | layout(location = 0) in vec3 pos;  | ||||||
| 
 | 
 | ||||||
|  | uniform mat4 vp; | ||||||
|  | uniform mat4 model; | ||||||
|  | 
 | ||||||
| void main()  | void main()  | ||||||
| {  | {  | ||||||
|     gl_Position.xyz = pos;  |     gl_Position = vp * model * vec4(pos, 1.0); | ||||||
|     gl_Position.w = 1.0;  |  | ||||||
| }  | }  | ||||||
|  | |||||||
| @ -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
 | ||||||
|     vao.use(); |     vao.use(); | ||||||
|     // Если есть индексы - рисуем с их использованием
 |     // Если есть индексы - рисуем с их использованием
 | ||||||
|  | |||||||
| @ -27,10 +27,10 @@ Scene& Scene::operator=(const Scene& other) | |||||||
| }  | }  | ||||||
| 
 | 
 | ||||||
| // Рендер сцены
 | // Рендер сцены
 | ||||||
| void Scene::render()  | void Scene::render(const GLuint &model_uniform)  | ||||||
| { | { | ||||||
|     for (auto & model : models) |     for (auto & model : models) | ||||||
|         model.render(); |         model.render(model_uniform); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Перестройка узлов выбранного списка
 | // Перестройка узлов выбранного списка
 | ||||||
|  | |||||||
							
								
								
									
										13
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/main.cpp
									
									
									
									
									
								
							| @ -5,6 +5,7 @@ | |||||||
| 
 | 
 | ||||||
| #include <iostream> | #include <iostream> | ||||||
| 
 | 
 | ||||||
|  | #include "Camera.h" | ||||||
| #include "Model.h" | #include "Model.h" | ||||||
| 
 | 
 | ||||||
| #define WINDOW_WIDTH 800 | #define WINDOW_WIDTH 800 | ||||||
| @ -112,6 +113,7 @@ GLuint LoadShaders(const char *vertex_file, const char *fragment_file) | |||||||
|     return programID; |     return programID; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |   | ||||||
| int main(void) | int main(void) | ||||||
| { | { | ||||||
|     GLFWwindow* window; // Указатель на окно GLFW3
 |     GLFWwindow* window; // Указатель на окно GLFW3
 | ||||||
| @ -175,18 +177,27 @@ int main(void) | |||||||
|     // Загрузка индексов модели
 |     // Загрузка индексов модели
 | ||||||
|     rectangle.load_indices(indices, sizeof(indices)); |     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); |     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)) |     while(!glfwWindowShouldClose(window)) | ||||||
|     { |     { | ||||||
|  |         // Загрузим матрицу проекции*вида
 | ||||||
|  |         glUniformMatrix4fv(vp_uniform, 1, GL_FALSE, &Camera::current().getVP()[0][0]); | ||||||
|  | 
 | ||||||
|         // Очистка буфера цвета
 |         // Очистка буфера цвета
 | ||||||
|         glClear(GL_COLOR_BUFFER_BIT); |         glClear(GL_COLOR_BUFFER_BIT); | ||||||
| 
 | 
 | ||||||
|         // Тут производится рендер
 |         // Тут производится рендер
 | ||||||
|         rectangle.render(); |         rectangle.render(model_uniform); | ||||||
| 
 | 
 | ||||||
|         // Представление содержимого буфера цепочки показа на окно
 |         // Представление содержимого буфера цепочки показа на окно
 | ||||||
|         glfwSwapBuffers(window); |         glfwSwapBuffers(window); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user