화면크기변경 로직 추가
This commit is contained in:
43
src/main.cpp
43
src/main.cpp
@@ -1,15 +1,16 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include "assimp/Importer.hpp"
|
||||
#include "assimp/postprocess.h"
|
||||
#include "glfw/glfw_initialization.h"
|
||||
#include "glfw/glfw_monitor.h"
|
||||
#include "glfw/glfw_window.h"
|
||||
#include "precomp.h"
|
||||
#include "vulkan/graphics.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
|
||||
const veng::GlfwInitialization _glfw;
|
||||
|
||||
@@ -18,6 +19,17 @@ std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
|
||||
|
||||
veng::Graphics graphics(&window);
|
||||
|
||||
Assimp::Importer assetImporter;
|
||||
|
||||
const struct aiScene* scene = assetImporter.ReadFile(
|
||||
"assets/player.fbx", aiProcess_CalcTangentSpace | aiProcess_Triangulate |
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);
|
||||
|
||||
if (nullptr == scene) {
|
||||
spdlog::error(assetImporter.GetErrorString());
|
||||
return false;
|
||||
}
|
||||
|
||||
std::array<veng::Vertex, 4> vertices = {
|
||||
veng::Vertex{{-.5f, -.5f, 0.f}, {0.f, 1.f}},
|
||||
veng::Vertex{{.5f, -.5f, 0.f}, {1.f, 1.f}},
|
||||
@@ -30,28 +42,45 @@ std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
|
||||
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), glm::radians(45.f),
|
||||
glm::vec3(0.f, 1.f, 0.f));
|
||||
|
||||
glm::mat4 rotation2 =
|
||||
glm::rotate(glm::mat4(1.0f), glm::radians(0.f), glm::vec3(0.f, 0.f, 1.f));
|
||||
|
||||
glm::mat4 view = glm::translate(glm::mat4(1.f), glm::vec3(0.f, 0.f, -2.f));
|
||||
glm::mat4 projection =
|
||||
glm::perspective(glm::radians(60.f), 800.f / 600.f, 0.1f, 100.f);
|
||||
glm::perspective(glm::radians(150.f), 800.f / 600.f, 0.1f, 100.f);
|
||||
graphics.SetViewProjection(view, projection);
|
||||
|
||||
veng::TextureHandle texture = graphics.CreateTexture("assets/paving-stones.jpg");
|
||||
veng::TextureHandle texture =
|
||||
graphics.CreateTexture("assets/paving-stones.jpg");
|
||||
|
||||
double last_time = glfwGetTime();
|
||||
|
||||
glm::ivec2 window_size;
|
||||
while (!window.ShouldClose()) {
|
||||
glfwPollEvents();
|
||||
|
||||
glm::ivec2 current_window_size = window.GetFramebufferSize();
|
||||
if (current_window_size != window_size && current_window_size.x != 0 && current_window_size.y != 0) {
|
||||
window_size = current_window_size;
|
||||
projection = glm::perspective(
|
||||
glm::radians(90.f),
|
||||
(float)current_window_size.x / (float)current_window_size.y, 0.1f,
|
||||
100.f);
|
||||
graphics.SetViewProjection(view, projection);
|
||||
}
|
||||
|
||||
if (graphics.BeginFrame()) {
|
||||
double current_time = glfwGetTime();
|
||||
float delta_time = static_cast<float>(current_time - last_time);
|
||||
last_time = current_time;
|
||||
|
||||
std::cout << 1.f / delta_time << std::endl;
|
||||
|
||||
graphics.SetTexture(texture);
|
||||
rotation2 = glm::rotate(rotation2, delta_time * glm::radians(-360.f),
|
||||
glm::vec3(0.f, 0.f, 1.f));
|
||||
graphics.SetModelMatrix(rotation2);
|
||||
graphics.RenderIndexedBuffer(buffer, index_buffer, indices.size());
|
||||
rotation = glm::rotate(rotation, delta_time * glm::radians(3600.f),
|
||||
rotation = glm::rotate(rotation, delta_time * glm::radians(360.f),
|
||||
glm::vec3(0.f, 0.f, 1.f));
|
||||
graphics.SetModelMatrix(rotation);
|
||||
graphics.RenderIndexedBuffer(buffer, index_buffer, indices.size());
|
||||
|
||||
Reference in New Issue
Block a user