#include #include #include #include #include #include #include #include #include "engine/Backend/Backend.h" namespace game { const int SCREEN_WIDTH = 1366; const int SCREEN_HEIGHT = 768; std::optional shader; std::optional model; std::optional camera; float lastX = SCREEN_WIDTH / 2.0f; float lastY = SCREEN_HEIGHT / 2.0f; bool firstMouse = true; bool Init() { shader.emplace("assets/shaders/basicVertex.vert", "assets/shaders/basicFragment.frag"); shader->Use(); shader->setInt("ourTexture", 0); shader->setInt("material.diffuse", 0); shader->setInt("material.specular", 1); shader->setInt("numberOfPointLights", 1); shader->setInt("numberOfSpotLights", 1); camera.emplace(glm::vec3(0.0f, 0.0f, 0.0f)); model.emplace("assets/models/sponza/Sponza.gltf"); glfwSetInputMode(engine::Backend::getWindow(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetInputMode(engine::Backend::getWindow(), GLFW_RAW_MOUSE_MOTION, GLFW_TRUE); return true; } void PreFrame() { glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); shader->Use(); camera->Update(shader.value(), SCREEN_WIDTH, SCREEN_HEIGHT); shader->setFloat("material.shininess", 32.0f); shader->setVec3("dirLight.direction", -0.2f, -1.0f, -0.3f); shader->setVec3("dirLight.ambient", 0.05f, 0.05f, 0.05f); shader->setVec3("dirLight.diffuse", 0.8f, 0.8f, 0.8f); shader->setVec3("dirLight.specular", 0.8f, 0.8f, 0.8f); shader->setVec3("pointLights[0].position", -1.88f, 8.45f, -0.98f); shader->setVec3("pointLights[0].ambient", 0.05f, 0.05f, 0.05f); shader->setVec3("pointLights[0].diffuse", 1.0f, 0.7f, 0.4f); shader->setVec3("pointLights[0].specular", 1.0f, 1.0f, 1.0f); shader->setFloat("pointLights[0].constant", 1.0f); shader->setFloat("pointLights[0].linear", 0.09f); shader->setFloat("pointLights[0].quadratic", 0.032f); shader->setVec3("spotLights[0].position", camera->position); shader->setVec3("spotLights[0].direction", camera->front); shader->setVec3("spotLights[0].ambient", 0.0f, 0.0f, 0.0f); shader->setVec3("spotLights[0].diffuse", 1.0f, 1.0f, 1.0f); shader->setVec3("spotLights[0].specular", 1.0f, 1.0f, 1.0f); shader->setFloat("spotLights[0].constant", 1.0f); shader->setFloat("spotLights[0].linear", 0.09f); shader->setFloat("spotLights[0].quadratic", 0.032f); shader->setFloat("spotLights[0].cutOff", glm::cos(glm::radians(12.5f))); shader->setFloat("spotLights[0].outerCutOff", glm::cos(glm::radians(15.0f))); } void Render() { glm::mat4 modelTransform = glm::mat4(1.0f); modelTransform = glm::translate(modelTransform, glm::vec3(0.0f, 0.0f, 0.0f)); modelTransform = glm::scale(modelTransform, glm::vec3(0.02f, 0.02f, 0.02f)); shader->setMat4("model", modelTransform); model->Draw(shader.value()); } void Update() { } void PostFrame() { } void Cleanup() { } }