Format code with clang-format.

This commit is contained in:
2021-07-04 13:12:34 +02:00
parent 9937a36526
commit f816f5f565
37 changed files with 470 additions and 465 deletions

View File

@@ -1,8 +1,8 @@
#include "Camera.h" #include "Camera.h"
#include "eventActions.h" #include "eventActions.h"
#include <glm/gtc/matrix_transform.hpp>
#include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_transform.hpp>
#include <glm/gtc/matrix_transform.hpp>
Camera::Camera(float fov, float aspectRatio) Camera::Camera(float fov, float aspectRatio)
{ {
@@ -19,7 +19,7 @@ void Camera::updateVPM()
void Camera::updateAspectRatio(float aspectRatio) void Camera::updateAspectRatio(float aspectRatio)
{ {
//projectionMatrix = glm::ortho(-2.0f, 2.0f, -2.0f, 2.0f, -10.f, 100.0f); // projectionMatrix = glm::ortho(-2.0f, 2.0f, -2.0f, 2.0f, -10.f, 100.0f);
projectionMatrix = glm::perspective(fov / 2.0f, aspectRatio, 0.1f, 1000.0f); projectionMatrix = glm::perspective(fov / 2.0f, aspectRatio, 0.1f, 1000.0f);
updateVPM(); updateVPM();
} }
@@ -79,7 +79,7 @@ void Camera::updateDirectionFromMouseInput(double *cameraMouseActionRegister)
pitch += cameraMouseActionRegister[cameraMouseDeltaY]; pitch += cameraMouseActionRegister[cameraMouseDeltaY];
if (pitch > 89.0f) { if (pitch > 89.0f) {
pitch = 89.0f; pitch = 89.0f;
} }
if (pitch < -89.0f) { if (pitch < -89.0f) {
pitch = -89.0f; pitch = -89.0f;

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <glm/glm.hpp>
#include "ShaderProgram.h" #include "ShaderProgram.h"
#include <glm/glm.hpp>
class Camera class Camera
{ {
@@ -34,7 +34,7 @@ private:
glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 frontVec = glm::vec3(0.0f, 0.0f, -1.0f); glm::vec3 frontVec = glm::vec3(0.0f, 0.0f, -1.0f);
glm::vec3 upVec = glm::vec3(0.0f, 1.0f, 0.0f); glm::vec3 upVec = glm::vec3(0.0f, 1.0f, 0.0f);
float pitch = 0.0f; float pitch = 0.0f;
float yaw = -90.0f; float yaw = -90.0f;
@@ -43,5 +43,3 @@ private:
float fov; float fov;
}; };

View File

@@ -12,16 +12,16 @@
#include <imgui_impl_opengl3.h> #include <imgui_impl_opengl3.h>
#endif #endif
#include "Helper.h"
#include "Controller.h" #include "Controller.h"
#include "VertexArray.h"
#include "Texture.h"
#include "Model.h"
#include "Entity.h" #include "Entity.h"
#include "World.h" #include "Helper.h"
#include "Widget.h"
#include "Screen.h"
#include "JsonParser.h" #include "JsonParser.h"
#include "Model.h"
#include "Screen.h"
#include "Texture.h"
#include "VertexArray.h"
#include "Widget.h"
#include "World.h"
Controller::Controller() Controller::Controller()
{ {
@@ -33,7 +33,8 @@ Controller::Controller()
JsonParser shaderParser("data/shaderPrograms.json"); JsonParser shaderParser("data/shaderPrograms.json");
shaderPrograms = shaderParser.getShaderPrograms(); shaderPrograms = shaderParser.getShaderPrograms();
pp_framebuffer = new Framebuffer(gameWindow->getWindowWidth(), gameWindow->getWindowHeight(), getShaderProgramByName("postProcessingProgram")); pp_framebuffer = new Framebuffer(gameWindow->getWindowWidth(), gameWindow->getWindowHeight(),
getShaderProgramByName("postProcessingProgram"));
menu = new Menu(pp_framebuffer, getShaderProgramByName("menuProgram")); menu = new Menu(pp_framebuffer, getShaderProgramByName("menuProgram"));
@@ -119,7 +120,7 @@ void Controller::run()
getShaderProgramByName("lightProgram")->unbind(); getShaderProgramByName("lightProgram")->unbind();
// --- Render and buffer swap --- // --- Render and buffer swap ---
// Calc shadows // Calc shadows
static bool drawShadows = false; static bool drawShadows = false;
static bool firstRun = true; static bool firstRun = true;
@@ -128,13 +129,14 @@ void Controller::run()
getShaderProgramByName("defaultProgram")->unbind(); getShaderProgramByName("defaultProgram")->unbind();
if (drawShadows || firstRun) { if (drawShadows || firstRun) {
firstRun = false; firstRun = false;
world->calculateShadows(getShaderProgramByName("directionalShadowDepthProgram"), getShaderProgramByName("pointShadowDepthProgram")); world->calculateShadows(getShaderProgramByName("directionalShadowDepthProgram"),
getShaderProgramByName("pointShadowDepthProgram"));
} }
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
auto activeScreen = menu->getActiveScreen(); auto activeScreen = menu->getActiveScreen();
if(activeScreen) { if (activeScreen) {
activeScreen->draw(); activeScreen->draw();
} else { } else {
pp_framebuffer->bind(); pp_framebuffer->bind();
@@ -150,7 +152,8 @@ void Controller::run()
pp_framebuffer->render(); pp_framebuffer->render();
#ifdef _DEBUG #ifdef _DEBUG
renderImGui(world, &lightColor, &rotateEntity, &rotateLightSource, getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows); renderImGui(world, &lightColor, &rotateEntity, &rotateLightSource,
getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows);
#endif #endif
} }
glfwSwapBuffers(gameWindow->getGLFWwindow()); glfwSwapBuffers(gameWindow->getGLFWwindow());
@@ -168,7 +171,7 @@ void Controller::run()
if (gameWindow->getMouseIsCatched()) { if (gameWindow->getMouseIsCatched()) {
camera->updateDirectionFromMouseInput(gameEventHandler->getCursorDelta()); camera->updateDirectionFromMouseInput(gameEventHandler->getCursorDelta());
} }
menu->writeWindowActions(gameEventHandler->getWindowActionRegister()); menu->writeWindowActions(gameEventHandler->getWindowActionRegister());
gameWindow->handleWindowActionRegister(gameEventHandler->getWindowActionRegister()); gameWindow->handleWindowActionRegister(gameEventHandler->getWindowActionRegister());
@@ -210,10 +213,10 @@ void Controller::updateExposure(ShaderProgram *shaderProgram)
shaderProgram->unbind(); shaderProgram->unbind();
} }
ShaderProgram* Controller::getShaderProgramByName(const std::string& name) ShaderProgram *Controller::getShaderProgramByName(const std::string &name)
{ {
for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) { for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) {
if((*it)->getUniqueName() == name) { if ((*it)->getUniqueName() == name) {
return *it; return *it;
} }
} }
@@ -221,10 +224,10 @@ ShaderProgram* Controller::getShaderProgramByName(const std::string& name)
return nullptr; return nullptr;
} }
ShaderProgram* Controller::getShaderProgramByName(std::vector<ShaderProgram*> shaderPrograms, const std::string& name) ShaderProgram *Controller::getShaderProgramByName(std::vector<ShaderProgram *> shaderPrograms, const std::string &name)
{ {
for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) { for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) {
if((*it)->getUniqueName() == name) { if ((*it)->getUniqueName() == name) {
return *it; return *it;
} }
} }
@@ -238,13 +241,13 @@ void Controller::setMaxFps(uint16_t fps)
} }
#ifdef _DEBUG #ifdef _DEBUG
void Controller::renderImGui(World *world, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows) void Controller::renderImGui(World *world, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource,
ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows)
{ {
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
// render your GUI // render your GUI
ImGui::Begin("Debug Utils"); ImGui::Begin("Debug Utils");
ImGui::Text("Object"); ImGui::Text("Object");
@@ -283,8 +286,8 @@ void Controller::renderImGui(World *world, glm::vec3 *lightColor, bool *rotateEn
ImGui::Checkbox("Draw Shadows", drawShadows); ImGui::Checkbox("Draw Shadows", drawShadows);
ImGui::Checkbox("Rotate Lightsource", rotateLightSource); ImGui::Checkbox("Rotate Lightsource", rotateLightSource);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0 / ImGui::GetIO().Framerate,
1000.0 / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); ImGui::GetIO().Framerate);
ImGui::End(); ImGui::End();

View File

@@ -2,17 +2,16 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "Window.h"
#include "EventHandler.h"
#include "Camera.h" #include "Camera.h"
#include "ShaderProgram.h"
#include "Entity.h" #include "Entity.h"
#include "defines.h" #include "EventHandler.h"
#include "Light.h"
#include "Framebuffer.h" #include "Framebuffer.h"
#include "Light.h"
#include "Menu.h" #include "Menu.h"
#include "ShaderProgram.h"
#include "Window.h"
#include "World.h" #include "World.h"
#include "defines.h"
class Controller class Controller
{ {
@@ -24,7 +23,7 @@ public:
void setMaxFps(uint16_t fps); void setMaxFps(uint16_t fps);
static ShaderProgram* getShaderProgramByName(std::vector<ShaderProgram*> shaderPrograms, const std::string& name); static ShaderProgram *getShaderProgramByName(std::vector<ShaderProgram *> shaderPrograms, const std::string &name);
private: private:
void limit_framerate(); void limit_framerate();
@@ -32,9 +31,10 @@ private:
void updateWindowDimensions(); void updateWindowDimensions();
void updateExposure(ShaderProgram *shaderProgram); void updateExposure(ShaderProgram *shaderProgram);
ShaderProgram* getShaderProgramByName(const std::string& name); ShaderProgram *getShaderProgramByName(const std::string &name);
void renderImGui(World *world, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows); void renderImGui(World *world, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource,
ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows);
private: private:
Window *gameWindow; Window *gameWindow;
@@ -45,11 +45,10 @@ private:
Camera *camera; Camera *camera;
Menu *menu; Menu *menu;
std::vector<ShaderProgram*> shaderPrograms; std::vector<ShaderProgram *> shaderPrograms;
Framebuffer *pp_framebuffer; Framebuffer *pp_framebuffer;
uint16_t MAX_FPS = 60; uint16_t MAX_FPS = 60;
double deltaTime; double deltaTime;

View File

@@ -1,14 +1,12 @@
#include "Entity.h" #include "Entity.h"
#include <glm/gtc/matrix_transform.hpp>
#include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_transform.hpp>
#include <glm/gtc/matrix_transform.hpp>
uint32_t Entity::id_counter = 0; uint32_t Entity::id_counter = 0;
Entity::Entity(std::string name, Model *model, ShaderProgram *shaderProgram) : Entity::Entity(std::string name, Model *model, ShaderProgram *shaderProgram)
unique_name(name), : unique_name(name), model(model), shaderProgram(shaderProgram)
model(model),
shaderProgram(shaderProgram)
{ {
id = id_counter++; id = id_counter++;
} }
@@ -147,11 +145,9 @@ bool Entity::getIsLightSource()
return isLightSource; return isLightSource;
} }
Skybox::Skybox(Model *cubeModel, ShaderProgram *shaderProgram, const char *texturePseudoPath) : Skybox::Skybox(Model *cubeModel, ShaderProgram *shaderProgram, const char *texturePseudoPath)
cubeModel(cubeModel), : cubeModel(cubeModel), shaderProgram(shaderProgram), cubeMap(texturePseudoPath),
shaderProgram(shaderProgram), vertexArray(cubeModel->getMesh(0)->getVertexArray())
cubeMap(texturePseudoPath),
vertexArray(cubeModel->getMesh(0)->getVertexArray())
{ {
// Empty // Empty
} }

View File

@@ -1,8 +1,8 @@
#pragma once #pragma once
#include "Model.h" #include "Model.h"
#include "Texture.h"
#include "ShaderProgram.h" #include "ShaderProgram.h"
#include "Texture.h"
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp> #include <glm/gtx/quaternion.hpp>

View File

@@ -10,9 +10,7 @@ bool EventHandler::windowActionRegister[WINDOW_ACTION_NUM_ITEMS] = {0};
bool EventHandler::firstMouseInput = 1; bool EventHandler::firstMouseInput = 1;
float EventHandler::mouseSensitivity = 0.15f; float EventHandler::mouseSensitivity = 0.15f;
EventHandler::EventHandler(GLFWwindow *p_window) : window(p_window)
EventHandler::EventHandler(GLFWwindow *p_window) :
window(p_window)
{ {
glfwSetKeyCallback(window, key_callback); glfwSetKeyCallback(window, key_callback);
glfwSetCursorPosCallback(window, mouse_callback); glfwSetCursorPosCallback(window, mouse_callback);
@@ -27,7 +25,7 @@ void EventHandler::handleEvents()
void EventHandler::clearActionRegisters() void EventHandler::clearActionRegisters()
{ {
//std::fill_n(cameraActionRegister, CAMERA_ACTION_NUM_ITEMS, 0); // std::fill_n(cameraActionRegister, CAMERA_ACTION_NUM_ITEMS, 0);
std::fill_n(cameraMouseActionRegister, CAMERA_MOUSE_ACTION_NUM_ITEMS, 0.0); std::fill_n(cameraMouseActionRegister, CAMERA_MOUSE_ACTION_NUM_ITEMS, 0.0);
std::fill_n(windowActionRegister, WINDOW_ACTION_NUM_ITEMS, 0); std::fill_n(windowActionRegister, WINDOW_ACTION_NUM_ITEMS, 0);
std::fill_n(mouseButtonActionRegister, MOUSE_BUTTON_ACTION_NUM_ITEMS, 0); std::fill_n(mouseButtonActionRegister, MOUSE_BUTTON_ACTION_NUM_ITEMS, 0);
@@ -120,9 +118,10 @@ void EventHandler::mouse_callback(GLFWwindow *window, double xpos, double ypos)
cameraMouseActionRegister[cameraMouseActions::cameraMouseDeltaY] += deltaCursorPosY; cameraMouseActionRegister[cameraMouseActions::cameraMouseDeltaY] += deltaCursorPosY;
} }
void EventHandler::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) void EventHandler::mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
{ {
(void) window; (void) mods; (void)window;
(void)mods;
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS)
mouseButtonActionRegister[mouseButtonActions::leftClicked] = true; mouseButtonActionRegister[mouseButtonActions::leftClicked] = true;
@@ -132,22 +131,22 @@ void EventHandler::mouse_button_callback(GLFWwindow* window, int button, int act
mouseButtonActionRegister[mouseButtonActions::middleClicked] = true; mouseButtonActionRegister[mouseButtonActions::middleClicked] = true;
} }
bool * EventHandler::getCameraActionRegister() bool *EventHandler::getCameraActionRegister()
{ {
return cameraActionRegister; return cameraActionRegister;
} }
bool * EventHandler::getWindowActionRegister() bool *EventHandler::getWindowActionRegister()
{ {
return windowActionRegister; return windowActionRegister;
} }
bool * EventHandler::getMouseButtonActionRegister() bool *EventHandler::getMouseButtonActionRegister()
{ {
return mouseButtonActionRegister; return mouseButtonActionRegister;
} }
double * EventHandler::getCursorDelta() double *EventHandler::getCursorDelta()
{ {
return cameraMouseActionRegister; return cameraMouseActionRegister;
} }

View File

@@ -3,8 +3,7 @@
#include <cstddef> #include <cstddef>
#include <iostream> #include <iostream>
Framebuffer::Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram) : Framebuffer::Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram) : shaderProgram(shaderProgram)
shaderProgram(shaderProgram)
{ {
glGenFramebuffers(1, &FBO); glGenFramebuffers(1, &FBO);
@@ -90,7 +89,6 @@ void Framebuffer::generateTextures(uint32_t width, uint32_t height)
unbind(); unbind();
} }
void Framebuffer::setExposureCorrection(bool exposureCorrection) void Framebuffer::setExposureCorrection(bool exposureCorrection)
{ {
shaderProgram->bind(); shaderProgram->bind();
@@ -112,7 +110,8 @@ DepthMap::DepthMap(int TYPE, int RESOLUTION)
glGenTextures(1, &depthMap); glGenTextures(1, &depthMap);
glBindTexture(GL_TEXTURE_2D, depthMap); glBindTexture(GL_TEXTURE_2D, depthMap);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, RESOLUTION, RESOLUTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, RESOLUTION, RESOLUTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -140,11 +139,10 @@ DepthMap::DepthMap(int TYPE, int RESOLUTION)
DepthMap::~DepthMap() DepthMap::~DepthMap()
{ {
if(cubeMap) if (cubeMap)
delete cubeMap; delete cubeMap;
} }
void DepthMap::bind() void DepthMap::bind()
{ {
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO); glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);

View File

@@ -1,13 +1,13 @@
#pragma once #pragma once
#include <glad/glad.h>
#include "ShaderProgram.h" #include "ShaderProgram.h"
#include "Texture.h" #include "Texture.h"
#include <glad/glad.h>
class Framebuffer class Framebuffer
{ {
public: public:
Framebuffer(uint32_t width, uint32_t height, ShaderProgram* shaderProgram); Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram);
~Framebuffer(); ~Framebuffer();
void bind(); void bind();
@@ -31,7 +31,11 @@ private:
ShaderProgram *shaderProgram; ShaderProgram *shaderProgram;
}; };
enum depthMapType {DEPTHMAP_NORMAL, DEPTHMAP_CUBEMAP}; enum depthMapType
{
DEPTHMAP_NORMAL,
DEPTHMAP_CUBEMAP
};
// Framebuffer without color buffer. (Shadows) // Framebuffer without color buffer. (Shadows)
class DepthMap class DepthMap

View File

@@ -1,7 +1,7 @@
#include "Helper.h" #include "Helper.h"
#include <iostream>
#include <algorithm> #include <algorithm>
#include <iostream>
#ifdef __linux__ #ifdef __linux__
#include <unistd.h> #include <unistd.h>
@@ -21,116 +21,117 @@ void Helper::sleep(uint32_t us)
#endif #endif
} }
void Helper::gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) void Helper::gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
const GLchar *message, const void *userParam)
{ {
(void)length; (void)length;
(void)userParam; (void)userParam;
const char* _source; const char *_source;
const char* _type; const char *_type;
const char* _severity; const char *_severity;
// Remove unwanted newline characters from message string // Remove unwanted newline characters from message string
std::string _message = message; std::string _message = message;
_message.erase(std::remove(_message.begin(), _message.end(), '\n'), _message.end()); _message.erase(std::remove(_message.begin(), _message.end(), '\n'), _message.end());
switch (source) { switch (source) {
case GL_DEBUG_SOURCE_API: case GL_DEBUG_SOURCE_API:
_source = "API"; _source = "API";
break; break;
case GL_DEBUG_SOURCE_WINDOW_SYSTEM: case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
_source = "WINDOW SYSTEM"; _source = "WINDOW SYSTEM";
break; break;
case GL_DEBUG_SOURCE_SHADER_COMPILER: case GL_DEBUG_SOURCE_SHADER_COMPILER:
_source = "SHADER COMPILER"; _source = "SHADER COMPILER";
break; break;
case GL_DEBUG_SOURCE_THIRD_PARTY: case GL_DEBUG_SOURCE_THIRD_PARTY:
_source = "THIRD PARTY"; _source = "THIRD PARTY";
break; break;
case GL_DEBUG_SOURCE_APPLICATION: case GL_DEBUG_SOURCE_APPLICATION:
_source = "APPLICATION"; _source = "APPLICATION";
break; break;
case GL_DEBUG_SOURCE_OTHER: case GL_DEBUG_SOURCE_OTHER:
_source = "UNKNOWN"; _source = "UNKNOWN";
break; break;
default: default:
_source = "UNKNOWN"; _source = "UNKNOWN";
break; break;
} }
switch (type) { switch (type) {
case GL_DEBUG_TYPE_ERROR: case GL_DEBUG_TYPE_ERROR:
_type = "ERROR"; _type = "ERROR";
break; break;
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
_type = "DEPRECATED BEHAVIOR"; _type = "DEPRECATED BEHAVIOR";
break; break;
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
_type = "UDEFINED BEHAVIOR"; _type = "UDEFINED BEHAVIOR";
break; break;
case GL_DEBUG_TYPE_PORTABILITY: case GL_DEBUG_TYPE_PORTABILITY:
_type = "PORTABILITY"; _type = "PORTABILITY";
break; break;
case GL_DEBUG_TYPE_PERFORMANCE: case GL_DEBUG_TYPE_PERFORMANCE:
_type = "PERFORMANCE"; _type = "PERFORMANCE";
break; break;
case GL_DEBUG_TYPE_OTHER: case GL_DEBUG_TYPE_OTHER:
_type = "OTHER"; _type = "OTHER";
break; break;
case GL_DEBUG_TYPE_MARKER: case GL_DEBUG_TYPE_MARKER:
_type = "MARKER"; _type = "MARKER";
break; break;
default: default:
_type = "UNKNOWN"; _type = "UNKNOWN";
break; break;
} }
switch (severity) { switch (severity) {
case GL_DEBUG_SEVERITY_HIGH: case GL_DEBUG_SEVERITY_HIGH:
_severity = "HIGH"; _severity = "HIGH";
break; break;
case GL_DEBUG_SEVERITY_MEDIUM: case GL_DEBUG_SEVERITY_MEDIUM:
_severity = "MEDIUM"; _severity = "MEDIUM";
break; break;
case GL_DEBUG_SEVERITY_LOW: case GL_DEBUG_SEVERITY_LOW:
_severity = "LOW"; _severity = "LOW";
break; break;
case GL_DEBUG_SEVERITY_NOTIFICATION: case GL_DEBUG_SEVERITY_NOTIFICATION:
_severity = "NOTIFICATION"; _severity = "NOTIFICATION";
break; break;
default: default:
_severity = "UNKNOWN"; _severity = "UNKNOWN";
break; break;
} }
if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM) if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM)
std::cout << "[OpenGL Debug Message]" << std::endl std::cout << "[OpenGL Debug Message]" << std::endl
<< "Message: " << _message << std::endl << "Message: " << _message << std::endl
<< "Source: " << _source << std::endl << "Source: " << _source << std::endl
<< "Type: " << _type << std::endl << "Type: " << _type << std::endl
<< "ID: " << id << std::endl << "ID: " << id << std::endl
<< "Severity: " << _severity << std::endl << "Severity: " << _severity << std::endl
<< std::endl; << std::endl;
} }
Helper::Timer::Timer(const std::string& name) : name(name) Helper::Timer::Timer(const std::string &name) : name(name)
{ {
start = std::chrono::high_resolution_clock::now(); start = std::chrono::high_resolution_clock::now();
} }

View File

@@ -1,19 +1,20 @@
#pragma once #pragma once
#include <GLFW/glfw3.h>
#include <chrono>
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <chrono>
#include <GLFW/glfw3.h>
namespace Helper namespace Helper {
{
void sleep(uint32_t us); void sleep(uint32_t us);
void gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); void gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message,
const void *userParam);
class Timer { class Timer
{
public: public:
Timer(const std::string& name); Timer(const std::string &name);
~Timer(); ~Timer();
private: private:
@@ -22,4 +23,4 @@ private:
std::chrono::duration<float> duration; std::chrono::duration<float> duration;
}; };
} } // namespace Helper

View File

@@ -1,10 +1,10 @@
#include "JsonParser.h" #include "JsonParser.h"
#include <fstream> #include <fstream>
#include <iostream>
#include <future> #include <future>
#include <iostream>
JsonParser::JsonParser(const std::string& path) JsonParser::JsonParser(const std::string &path)
{ {
std::ifstream file(path.c_str(), std::ifstream::binary); std::ifstream file(path.c_str(), std::ifstream::binary);
@@ -24,17 +24,16 @@ JsonParser::JsonParser(const std::string& path)
} }
JsonParser::~JsonParser() JsonParser::~JsonParser()
{ {}
} std::vector<Model *> JsonParser::getModels()
std::vector<Model*> JsonParser::getModels()
{ {
std::vector<Model*> temp_models; std::vector<Model *> temp_models;
const Json::Value modelsJson = root["models"]; const Json::Value modelsJson = root["models"];
struct ModelSkeleton { struct ModelSkeleton
{
std::string model_name; std::string model_name;
std::string model_path; std::string model_path;
}; };
@@ -51,26 +50,27 @@ std::vector<Model*> JsonParser::getModels()
std::vector<std::future<void>> futures; std::vector<std::future<void>> futures;
std::mutex mutex; std::mutex mutex;
auto* temp_models_ptr = &temp_models; auto *temp_models_ptr = &temp_models;
for (const auto& model_skeleton : model_skeletons) { for (const auto &model_skeleton : model_skeletons) {
auto loadModel = [&]() { auto loadModel = [&]() {
Model *current_model = new Model(model_skeleton.model_name, model_skeleton.model_path); Model *current_model = new Model(model_skeleton.model_name, model_skeleton.model_path);
if(current_model) { if (current_model) {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
temp_models_ptr->push_back(current_model); temp_models_ptr->push_back(current_model);
std::cout << "Loaded Model \"" << model_skeleton.model_name << "\" from \"" << model_skeleton.model_path << "\"" << std::endl; std::cout << "Loaded Model \"" << model_skeleton.model_name << "\" from \"" << model_skeleton.model_path
<< "\"" << std::endl;
} }
}; };
futures.push_back(std::async(std::launch::async, loadModel)); futures.push_back(std::async(std::launch::async, loadModel));
} }
return temp_models; return temp_models;
} }
std::vector<Entity*> JsonParser::getEntities(std::vector<Model*> &models, std::vector<ShaderProgram*> shaderPrograms) std::vector<Entity *> JsonParser::getEntities(std::vector<Model *> &models, std::vector<ShaderProgram *> shaderPrograms)
{ {
std::vector<Entity*> temp_entities; std::vector<Entity *> temp_entities;
const Json::Value entitiesJson = root["entities"]; const Json::Value entitiesJson = root["entities"];
@@ -83,20 +83,21 @@ std::vector<Entity*> JsonParser::getEntities(std::vector<Model*> &models, std::v
ShaderProgram *shaderProgram = nullptr; ShaderProgram *shaderProgram = nullptr;
for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) { for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) {
if((*it)->getUniqueName() == entity_shaderProgram) { if ((*it)->getUniqueName() == entity_shaderProgram) {
shaderProgram = *it; shaderProgram = *it;
} }
} }
if(!shaderProgram) if (!shaderProgram)
std::cout << "[Warning] ShaderProgram could not be found by name \"" << entity_shaderProgram << "\"" << std::endl; std::cout << "[Warning] ShaderProgram could not be found by name \"" << entity_shaderProgram << "\""
<< std::endl;
Model *current_model = nullptr; Model *current_model = nullptr;
for (auto it = models.begin(); it != models.end(); it++) { for (auto it = models.begin(); it != models.end(); it++) {
if((*it)->getUniqueName() == entity_model) { if ((*it)->getUniqueName() == entity_model) {
current_model = *it; current_model = *it;
} }
} }
if(!current_model) { if (!current_model) {
// Apply fallback model (first model in vector) // Apply fallback model (first model in vector)
current_model = models[0]; current_model = models[0];
std::cout << "[Warning] Model could not be found by unique name \"" << entity_model << "\"" << std::endl; std::cout << "[Warning] Model could not be found by unique name \"" << entity_model << "\"" << std::endl;
@@ -105,17 +106,17 @@ std::vector<Entity*> JsonParser::getEntities(std::vector<Model*> &models, std::v
const Json::Value positionJson = entitiesJson[index]["position"]; const Json::Value positionJson = entitiesJson[index]["position"];
const Json::Value rotationJson = entitiesJson[index]["rotation"]; const Json::Value rotationJson = entitiesJson[index]["rotation"];
const Json::Value scaleJson = entitiesJson[index]["scale"]; const Json::Value scaleJson = entitiesJson[index]["scale"];
if(!positionJson.empty()) { if (!positionJson.empty()) {
entitiy_position.x = positionJson[0].asFloat(); entitiy_position.x = positionJson[0].asFloat();
entitiy_position.y = positionJson[1].asFloat(); entitiy_position.y = positionJson[1].asFloat();
entitiy_position.z = positionJson[2].asFloat(); entitiy_position.z = positionJson[2].asFloat();
} }
if(!rotationJson.empty()) { if (!rotationJson.empty()) {
entity_rotation.s = rotationJson[0].asFloat(); entity_rotation.s = rotationJson[0].asFloat();
entity_rotation.t = rotationJson[1].asFloat(); entity_rotation.t = rotationJson[1].asFloat();
entity_rotation.p = rotationJson[2].asFloat(); entity_rotation.p = rotationJson[2].asFloat();
} }
if(!scaleJson.empty()) { if (!scaleJson.empty()) {
entity_scale = scaleJson.asFloat(); entity_scale = scaleJson.asFloat();
} }
@@ -132,7 +133,7 @@ std::vector<Entity*> JsonParser::getEntities(std::vector<Model*> &models, std::v
std::vector<ShaderProgram *> JsonParser::getShaderPrograms() std::vector<ShaderProgram *> JsonParser::getShaderPrograms()
{ {
std::vector<ShaderProgram*> temp_shaderPrograms; std::vector<ShaderProgram *> temp_shaderPrograms;
const Json::Value shaderProgramsJson = root["shaderPrograms"]; const Json::Value shaderProgramsJson = root["shaderPrograms"];
@@ -143,10 +144,12 @@ std::vector<ShaderProgram *> JsonParser::getShaderPrograms()
std::string shaderProgram_geometryPath = shaderProgramsJson[index]["geometryPath"].asString(); std::string shaderProgram_geometryPath = shaderProgramsJson[index]["geometryPath"].asString();
ShaderProgram *current_shaderProgram; ShaderProgram *current_shaderProgram;
if(shaderProgram_geometryPath.empty()) { if (shaderProgram_geometryPath.empty()) {
current_shaderProgram = new ShaderProgram(shaderProgram_name, shaderProgram_vertexPath, shaderProgram_fragmentPath); current_shaderProgram =
new ShaderProgram(shaderProgram_name, shaderProgram_vertexPath, shaderProgram_fragmentPath);
} else { } else {
current_shaderProgram = new ShaderProgram(shaderProgram_name, shaderProgram_vertexPath, shaderProgram_geometryPath, shaderProgram_fragmentPath); current_shaderProgram = new ShaderProgram(shaderProgram_name, shaderProgram_vertexPath,
shaderProgram_geometryPath, shaderProgram_fragmentPath);
} }
temp_shaderPrograms.push_back(current_shaderProgram); temp_shaderPrograms.push_back(current_shaderProgram);
std::cout << "Loaded ShaderProgram \"" << shaderProgram_name << "\"" << std::endl; std::cout << "Loaded ShaderProgram \"" << shaderProgram_name << "\"" << std::endl;
@@ -155,9 +158,9 @@ std::vector<ShaderProgram *> JsonParser::getShaderPrograms()
return temp_shaderPrograms; return temp_shaderPrograms;
} }
std::vector<Light*> JsonParser::getLights(ShaderProgram* shaderProgram) std::vector<Light *> JsonParser::getLights(ShaderProgram *shaderProgram)
{ {
std::vector<Light*> temp_lights; std::vector<Light *> temp_lights;
glm::vec3 light_direction = {1.0f, 0.0f, 0.0f}; glm::vec3 light_direction = {1.0f, 0.0f, 0.0f};
glm::vec3 light_position = {}; glm::vec3 light_position = {};
glm::vec3 light_color = {1.0f, 1.0f, 1.0f}; glm::vec3 light_color = {1.0f, 1.0f, 1.0f};
@@ -169,21 +172,22 @@ std::vector<Light*> JsonParser::getLights(ShaderProgram* shaderProgram)
Json::Value colorJson = directionalLightsJson["color"]; Json::Value colorJson = directionalLightsJson["color"];
Json::Value intensityJson = directionalLightsJson["intensity"]; Json::Value intensityJson = directionalLightsJson["intensity"];
if(!intensityJson.empty()) { if (!intensityJson.empty()) {
light_intensity = intensityJson.asFloat(); light_intensity = intensityJson.asFloat();
} }
if(!directionJson.empty()) { if (!directionJson.empty()) {
light_direction.x = directionJson[0].asFloat(); light_direction.x = directionJson[0].asFloat();
light_direction.y = directionJson[1].asFloat(); light_direction.y = directionJson[1].asFloat();
light_direction.z = directionJson[2].asFloat(); light_direction.z = directionJson[2].asFloat();
} }
if(!colorJson.empty()) { if (!colorJson.empty()) {
light_color.x = colorJson[0].asFloat(); light_color.x = colorJson[0].asFloat();
light_color.y = colorJson[1].asFloat(); light_color.y = colorJson[1].asFloat();
light_color.z = colorJson[2].asFloat(); light_color.z = colorJson[2].asFloat();
} }
DirectionalLight *current_directionalLight = new DirectionalLight(light_direction, light_color, light_intensity, shaderProgram); DirectionalLight *current_directionalLight =
new DirectionalLight(light_direction, light_color, light_intensity, shaderProgram);
current_directionalLight->setActive(true); current_directionalLight->setActive(true);
temp_lights.push_back(current_directionalLight); temp_lights.push_back(current_directionalLight);
@@ -198,15 +202,15 @@ std::vector<Light*> JsonParser::getLights(ShaderProgram* shaderProgram)
colorJson = pointLightsJson[index]["color"]; colorJson = pointLightsJson[index]["color"];
intensityJson = pointLightsJson[index]["intensity"]; intensityJson = pointLightsJson[index]["intensity"];
if(!intensityJson.empty()) { if (!intensityJson.empty()) {
light_intensity = intensityJson.asFloat(); light_intensity = intensityJson.asFloat();
} }
if(!positionJson.empty()) { if (!positionJson.empty()) {
light_position.x = positionJson[0].asFloat(); light_position.x = positionJson[0].asFloat();
light_position.y = positionJson[1].asFloat(); light_position.y = positionJson[1].asFloat();
light_position.z = positionJson[2].asFloat(); light_position.z = positionJson[2].asFloat();
} }
if(!colorJson.empty()) { if (!colorJson.empty()) {
light_color.x = colorJson[0].asFloat(); light_color.x = colorJson[0].asFloat();
light_color.y = colorJson[1].asFloat(); light_color.y = colorJson[1].asFloat();
light_color.z = colorJson[2].asFloat(); light_color.z = colorJson[2].asFloat();
@@ -218,11 +222,12 @@ std::vector<Light*> JsonParser::getLights(ShaderProgram* shaderProgram)
} }
// In case there aren't enough PointLights defined in the Json file // In case there aren't enough PointLights defined in the Json file
for(; NUM_POINT_LIGHTS - index > 0; index++) { for (; NUM_POINT_LIGHTS - index > 0; index++) {
const glm::vec3 default_position(0.0f); const glm::vec3 default_position(0.0f);
const glm::vec3 default_color(1.0f); const glm::vec3 default_color(1.0f);
const float default_intensity = 10.0f; const float default_intensity = 10.0f;
PointLight *current_pointLight = new PointLight(default_position, default_color, default_intensity, shaderProgram); PointLight *current_pointLight =
new PointLight(default_position, default_color, default_intensity, shaderProgram);
current_pointLight->setActive(false); current_pointLight->setActive(false);
temp_lights.push_back(current_pointLight); temp_lights.push_back(current_pointLight);
} }
@@ -230,9 +235,9 @@ std::vector<Light*> JsonParser::getLights(ShaderProgram* shaderProgram)
return temp_lights; return temp_lights;
} }
std::vector<Screen*> JsonParser::getScreens(ShaderProgram *menuProgram, Framebuffer *framebuffer) std::vector<Screen *> JsonParser::getScreens(ShaderProgram *menuProgram, Framebuffer *framebuffer)
{ {
std::vector<Screen*> temp_screens; std::vector<Screen *> temp_screens;
const Json::Value loadingScreenJson = root["loadingScreen"]; const Json::Value loadingScreenJson = root["loadingScreen"];
const Json::Value mainMenuScreenJson = root["mainMenuScreen"]; const Json::Value mainMenuScreenJson = root["mainMenuScreen"];
@@ -251,9 +256,9 @@ std::vector<Screen*> JsonParser::getScreens(ShaderProgram *menuProgram, Framebuf
return temp_screens; return temp_screens;
} }
std::vector<Widget*> JsonParser::getWidgetsFromScreen(const Json::Value &screenJson) std::vector<Widget *> JsonParser::getWidgetsFromScreen(const Json::Value &screenJson)
{ {
std::vector<Widget*> temp_widgets; std::vector<Widget *> temp_widgets;
// Iterate over widgets // Iterate over widgets
unsigned int index = 0; unsigned int index = 0;
@@ -263,16 +268,12 @@ std::vector<Widget*> JsonParser::getWidgetsFromScreen(const Json::Value &screenJ
const Json::Value currentWidgetPosition = currentWidgetJson["position"]; const Json::Value currentWidgetPosition = currentWidgetJson["position"];
const Json::Value currentWidgetDimensions = currentWidgetJson["dimensions"]; const Json::Value currentWidgetDimensions = currentWidgetJson["dimensions"];
std::string name = currentWidgetJson["unique_name"].asString(); std::string name = currentWidgetJson["unique_name"].asString();
Texture *currentWidgetTexture = new Texture(currentWidgetTextureJson.asString().c_str(), textureType::texture_diffuse); Texture *currentWidgetTexture =
Widget *currentWidget = new Widget( new Texture(currentWidgetTextureJson.asString().c_str(), textureType::texture_diffuse);
name, Widget *currentWidget =
currentWidgetTexture, new Widget(name, currentWidgetTexture, currentWidgetPosition[0].asFloat(),
currentWidgetPosition[0].asFloat(), currentWidgetPosition[1].asFloat(), currentWidgetDimensions[0].asFloat(),
currentWidgetPosition[1].asFloat(), currentWidgetDimensions[1].asFloat(), currentWidgetJson["callbackId"].asUInt());
currentWidgetDimensions[0].asFloat(),
currentWidgetDimensions[1].asFloat(),
currentWidgetJson["callbackId"].asUInt()
);
temp_widgets.push_back(currentWidget); temp_widgets.push_back(currentWidget);
} }
return temp_widgets; return temp_widgets;
@@ -280,7 +281,7 @@ std::vector<Widget*> JsonParser::getWidgetsFromScreen(const Json::Value &screenJ
Skybox *JsonParser::getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram) Skybox *JsonParser::getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram)
{ {
Skybox* temp_skybox; Skybox *temp_skybox;
const Json::Value shaderProgramsJson = root["skybox"]; const Json::Value shaderProgramsJson = root["skybox"];

View File

@@ -1,10 +1,10 @@
#pragma once #pragma once
#include "Model.h"
#include "Entity.h" #include "Entity.h"
#include "ShaderProgram.h"
#include "Light.h" #include "Light.h"
#include "Model.h"
#include "Screen.h" #include "Screen.h"
#include "ShaderProgram.h"
#include <jsoncpp/json/json.h> #include <jsoncpp/json/json.h>
#include <string> #include <string>
@@ -13,19 +13,19 @@
class JsonParser class JsonParser
{ {
public: public:
JsonParser(const std::string& path); JsonParser(const std::string &path);
~JsonParser(); ~JsonParser();
std::vector<Model*> getModels(); std::vector<Model *> getModels();
std::vector<Entity*> getEntities(std::vector<Model*> &models, std::vector<ShaderProgram*> shaderPrograms); std::vector<Entity *> getEntities(std::vector<Model *> &models, std::vector<ShaderProgram *> shaderPrograms);
std::vector<Light*> getLights(ShaderProgram *shaderProgram); std::vector<Light *> getLights(ShaderProgram *shaderProgram);
std::vector<Screen*> getScreens(ShaderProgram *menuProgram, Framebuffer *framebuffer); std::vector<Screen *> getScreens(ShaderProgram *menuProgram, Framebuffer *framebuffer);
Skybox *getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram); Skybox *getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram);
std::vector<ShaderProgram*> getShaderPrograms(); std::vector<ShaderProgram *> getShaderPrograms();
private: private:
std::vector<Widget*> getWidgetsFromScreen(const Json::Value &screenJson); std::vector<Widget *> getWidgetsFromScreen(const Json::Value &screenJson);
private: private:
Json::Value root; Json::Value root;

View File

@@ -6,21 +6,19 @@ uint32_t Light::id_counter = 0;
// Light // Light
Light::Light(glm::vec3 color, float intensity, ShaderProgram* shaderProgram) : Light::Light(glm::vec3 color, float intensity, ShaderProgram *shaderProgram)
shaderProgram(shaderProgram), : shaderProgram(shaderProgram), intensity(intensity)
intensity(intensity)
{ {
id = id_counter++; id = id_counter++;
lightColor = color * intensity; lightColor = color * intensity;
} }
glm::vec3 Light::getColor() glm::vec3 Light::getColor()
{ {
return lightColor; return lightColor;
} }
void Light::setShaderProgram(ShaderProgram* shaderProgram) void Light::setShaderProgram(ShaderProgram *shaderProgram)
{ {
this->shaderProgram = shaderProgram; this->shaderProgram = shaderProgram;
update(); update();
@@ -37,7 +35,6 @@ void Light::setIntensity(float intensity)
this->intensity = intensity; this->intensity = intensity;
} }
void Light::setActive(bool active) void Light::setActive(bool active)
{ {
isActive = active; isActive = active;
@@ -46,9 +43,8 @@ void Light::setActive(bool active)
// PointLight // PointLight
PointLight::PointLight(glm::vec3 position, glm::vec3 color, float intensity, ShaderProgram *shaderProgram) : PointLight::PointLight(glm::vec3 position, glm::vec3 color, float intensity, ShaderProgram *shaderProgram)
Light(color, intensity, shaderProgram), : Light(color, intensity, shaderProgram), position(position)
position(position)
{ {
// Empty // Empty
} }
@@ -84,9 +80,8 @@ void PointLight::setPosition(glm::vec3 position)
// DirectionalLight // DirectionalLight
DirectionalLight::DirectionalLight(glm::vec3 direction, glm::vec3 color, float intensity, ShaderProgram *shaderProgram) : DirectionalLight::DirectionalLight(glm::vec3 direction, glm::vec3 color, float intensity, ShaderProgram *shaderProgram)
Light(color, intensity, shaderProgram), : Light(color, intensity, shaderProgram), direction(direction)
direction(direction)
{ {
// Empty // Empty
} }

View File

@@ -9,7 +9,8 @@
class Light class Light
{ {
public: public:
virtual ~Light() {} virtual ~Light()
{}
virtual void update() = 0; virtual void update() = 0;

View File

@@ -1,12 +1,12 @@
#include "Menu.h" #include "Menu.h"
#include "Helper.h"
#include "JsonParser.h" #include "JsonParser.h"
#include "eventActions.h" #include "eventActions.h"
#include "Helper.h"
#include <iostream> #include <iostream>
Menu::Menu(Framebuffer *p_framebuffer, ShaderProgram *p_shaderProgram) : Menu::Menu(Framebuffer *p_framebuffer, ShaderProgram *p_shaderProgram)
framebuffer(p_framebuffer), shaderProgram(p_shaderProgram) : framebuffer(p_framebuffer), shaderProgram(p_shaderProgram)
{ {
JsonParser screenParser("data/screens.json"); JsonParser screenParser("data/screens.json");
screens = screenParser.getScreens(shaderProgram, framebuffer); screens = screenParser.getScreens(shaderProgram, framebuffer);
@@ -20,13 +20,13 @@ Menu::~Menu()
} }
} }
Screen *Menu::getScreenByName(const std::string& name) const Screen *Menu::getScreenByName(const std::string &name) const
{ {
if (m_screen_name_cache.find(name) != m_screen_name_cache.end()) if (m_screen_name_cache.find(name) != m_screen_name_cache.end())
return m_screen_name_cache[name]; return m_screen_name_cache[name];
for (auto it : screens) { for (auto it : screens) {
if(it->getUniqueName() == name) { if (it->getUniqueName() == name) {
m_screen_name_cache[name] = it; m_screen_name_cache[name] = it;
return it; return it;
} }
@@ -40,11 +40,12 @@ Screen *Menu::getActiveScreen() const
return activeScreen; return activeScreen;
} }
void Menu::showScreenByName(const std::string& name) void Menu::showScreenByName(const std::string &name)
{ {
Screen* screen = getScreenByName(name); Screen *screen = getScreenByName(name);
if (!screen) return; if (!screen)
return;
screen->draw(); screen->draw();
activeScreen = screen; activeScreen = screen;
@@ -55,16 +56,16 @@ void Menu::resetActiveScreen()
activeScreen = nullptr; activeScreen = nullptr;
} }
void Menu::handleMouseButtonActionRegister(bool *mouseButtonActionRegister, Window* window) void Menu::handleMouseButtonActionRegister(bool *mouseButtonActionRegister, Window *window)
{ {
if (mouseButtonActionRegister[mouseButtonActions::leftClicked]) { if (mouseButtonActionRegister[mouseButtonActions::leftClicked]) {
auto widgets = activeScreen->getWidgets(); auto widgets = activeScreen->getWidgets();
for (auto it = widgets.begin(); it != widgets.end(); it++) { for (auto it = widgets.begin(); it != widgets.end(); it++) {
if ((*it)->isHovered(window)) { if ((*it)->isHovered(window)) {
// std::cout << (*it)->getUniqueName() << " clicked!" << std::endl; // std::cout << (*it)->getUniqueName() << " clicked!" << std::endl;
if((*it)->getCallbackId() == 1) if ((*it)->getCallbackId() == 1)
resetActiveScreen(); resetActiveScreen();
if((*it)->getCallbackId() == 2) if ((*it)->getCallbackId() == 2)
shouldExit = true; shouldExit = true;
} }
} }
@@ -78,11 +79,7 @@ void Menu::writeWindowActions(bool *windowActionRegister)
} }
void Menu::onPlayPressed() void Menu::onPlayPressed()
{ {}
}
void Menu::onExitPressed() void Menu::onExitPressed()
{ {}
}

View File

@@ -3,9 +3,9 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include "Screen.h"
#include "Framebuffer.h" #include "Framebuffer.h"
#include "JsonParser.h" #include "JsonParser.h"
#include "Screen.h"
#include "eventActions.h" #include "eventActions.h"
class Menu class Menu
@@ -14,15 +14,15 @@ public:
Menu(Framebuffer *p_framebuffer, ShaderProgram *p_shaderProgram); Menu(Framebuffer *p_framebuffer, ShaderProgram *p_shaderProgram);
~Menu(); ~Menu();
Screen *getScreenByName(const std::string& name) const; Screen *getScreenByName(const std::string &name) const;
void showScreenByName(const std::string& name); void showScreenByName(const std::string &name);
Screen *getActiveScreen() const; Screen *getActiveScreen() const;
void writeWindowActions(bool *windowActionRegister); void writeWindowActions(bool *windowActionRegister);
void resetActiveScreen(); void resetActiveScreen();
void handleMouseButtonActionRegister(bool *mouseButtonActionRegister, Window* window); void handleMouseButtonActionRegister(bool *mouseButtonActionRegister, Window *window);
void onPlayPressed(); void onPlayPressed();
void onExitPressed(); void onExitPressed();
@@ -33,12 +33,12 @@ private:
bool shouldExit = false; bool shouldExit = false;
std::vector<Screen*> screens; std::vector<Screen *> screens;
Screen *activeScreen; Screen *activeScreen;
/*Screen *loadingScreen; /*Screen *loadingScreen;
Screen *mainMenuScreen; Screen *mainMenuScreen;
Screen *optionMenuScreen; Screen *optionMenuScreen;
Screen *pauseMenuScreen;*/ Screen *pauseMenuScreen;*/
mutable std::unordered_map<std::string, Screen*> m_screen_name_cache; mutable std::unordered_map<std::string, Screen *> m_screen_name_cache;
}; };

View File

@@ -1,16 +1,16 @@
#include "Mesh.h" #include "Mesh.h"
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<uint32_t> indices, std::vector<Texture *> textures) : Mesh::Mesh(std::vector<Vertex> vertices, std::vector<uint32_t> indices, std::vector<Texture *> textures)
numElements(indices.size()), : numElements(indices.size()), textures(textures),
textures(textures), vertexArray(static_cast<void *>(vertices.data()), static_cast<void *>(indices.data()), vertices.size(),
vertexArray(static_cast<void *>(vertices.data()), static_cast<void *>(indices.data()), vertices.size(), indices.size()) indices.size())
{ {
// Empty... // Empty...
} }
void Mesh::draw(ShaderProgram *shaderProgram) void Mesh::draw(ShaderProgram *shaderProgram)
{ {
uint8_t typeNumberCount[TEXTURE_TYPE_NUM_ITEMS] {0}; uint8_t typeNumberCount[TEXTURE_TYPE_NUM_ITEMS]{0};
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
// Bind all textures in order to its texture unit // Bind all textures in order to its texture unit
for (auto it = textures.begin(); it != textures.end(); it++) { for (auto it = textures.begin(); it != textures.end(); it++) {
@@ -41,7 +41,7 @@ void Mesh::drawWithoutTextures()
vertexArray.unbind(); vertexArray.unbind();
} }
VertexArray* Mesh::getVertexArray() VertexArray *Mesh::getVertexArray()
{ {
return &vertexArray; return &vertexArray;
} }

View File

@@ -3,8 +3,8 @@
#include <vector> #include <vector>
#include "ShaderProgram.h" #include "ShaderProgram.h"
#include "VertexArray.h"
#include "Texture.h" #include "Texture.h"
#include "VertexArray.h"
#include "defines.h" #include "defines.h"
class Mesh class Mesh

View File

@@ -1,12 +1,11 @@
#include "Model.h" #include "Model.h"
#include <iostream>
#include <fstream> #include <fstream>
#include <iostream>
uint32_t Model::id_counter = 0; uint32_t Model::id_counter = 0;
Model::Model(const std::string &modelName, const std::string &modelPath) : Model::Model(const std::string &modelName, const std::string &modelPath) : unique_name(modelName)
unique_name(modelName)
{ {
directory = modelPath.substr(0, modelPath.find_last_of('/')); directory = modelPath.substr(0, modelPath.find_last_of('/'));
@@ -58,12 +57,12 @@ void Model::loadModel(const std::string &pathToModel)
} }
uint32_t numTextures; uint32_t numTextures;
input.read((char *) &numTextures, sizeof(uint32_t)); input.read((char *)&numTextures, sizeof(uint32_t));
std::vector<uint32_t> textureTypes; std::vector<uint32_t> textureTypes;
for (unsigned int i = 0; i < numTextures; i++) { for (unsigned int i = 0; i < numTextures; i++) {
uint32_t currentTextureType; uint32_t currentTextureType;
input.read((char *) &currentTextureType, sizeof(uint32_t)); input.read((char *)&currentTextureType, sizeof(uint32_t));
textureTypes.push_back(currentTextureType); textureTypes.push_back(currentTextureType);
} }
@@ -72,7 +71,7 @@ void Model::loadModel(const std::string &pathToModel)
std::string currentTextureSource; std::string currentTextureSource;
for (unsigned int i = 0; i < 128; i++) { for (unsigned int i = 0; i < 128; i++) {
uint8_t currentChar; uint8_t currentChar;
input.read((char *) &currentChar, sizeof(uint8_t)); input.read((char *)&currentChar, sizeof(uint8_t));
if (currentChar) { if (currentChar) {
currentTextureSource.push_back(currentChar); currentTextureSource.push_back(currentChar);
@@ -81,7 +80,6 @@ void Model::loadModel(const std::string &pathToModel)
textureSources.push_back(currentTextureSource); textureSources.push_back(currentTextureSource);
} }
for (unsigned int i = 0; i < numTextures; i++) { for (unsigned int i = 0; i < numTextures; i++) {
TexturePrototype texture_prototype; TexturePrototype texture_prototype;
std::string texturePath = directory + '/' + textureSources[i].c_str(); std::string texturePath = directory + '/' + textureSources[i].c_str();
@@ -110,7 +108,7 @@ void Model::loadModel(const std::string &pathToModel)
// Here starts the first mesh // Here starts the first mesh
uint32_t numMeshes; uint32_t numMeshes;
input.read((char *) &numMeshes, sizeof(uint32_t)); input.read((char *)&numMeshes, sizeof(uint32_t));
for (unsigned int j = 0; j < numMeshes; j++) { for (unsigned int j = 0; j < numMeshes; j++) {
@@ -118,9 +116,9 @@ void Model::loadModel(const std::string &pathToModel)
uint32_t numMeshVertices, numMeshIndices, numMeshTextureIds; uint32_t numMeshVertices, numMeshIndices, numMeshTextureIds;
input.read((char *) &numMeshVertices, sizeof(uint32_t)); input.read((char *)&numMeshVertices, sizeof(uint32_t));
input.read((char *) &numMeshIndices, sizeof(uint32_t)); input.read((char *)&numMeshIndices, sizeof(uint32_t));
input.read((char *) &numMeshTextureIds, sizeof(uint32_t)); input.read((char *)&numMeshTextureIds, sizeof(uint32_t));
uint32_t vertexBlockSize = numMeshVertices * sizeof(Vertex); uint32_t vertexBlockSize = numMeshVertices * sizeof(Vertex);
uint32_t indexBlockSize = numMeshIndices * sizeof(uint32_t); uint32_t indexBlockSize = numMeshIndices * sizeof(uint32_t);
@@ -129,17 +127,17 @@ void Model::loadModel(const std::string &pathToModel)
std::vector<Vertex> meshVertices; std::vector<Vertex> meshVertices;
meshVertices.resize(numMeshVertices); meshVertices.resize(numMeshVertices);
input.read((char *) meshVertices.data(), vertexBlockSize); input.read((char *)meshVertices.data(), vertexBlockSize);
mesh_prototype.meshVertices = std::move(meshVertices); mesh_prototype.meshVertices = std::move(meshVertices);
std::vector<uint32_t> meshIndices; std::vector<uint32_t> meshIndices;
meshIndices.resize(numMeshIndices); meshIndices.resize(numMeshIndices);
input.read((char *) meshIndices.data(), indexBlockSize); input.read((char *)meshIndices.data(), indexBlockSize);
mesh_prototype.meshIndices = std::move(meshIndices); mesh_prototype.meshIndices = std::move(meshIndices);
for (unsigned int i = 0; i < numMeshTextureIds; i++) { for (unsigned int i = 0; i < numMeshTextureIds; i++) {
uint32_t currentTextureId; uint32_t currentTextureId;
input.read((char *) &currentTextureId, sizeof(uint32_t)); input.read((char *)&currentTextureId, sizeof(uint32_t));
mesh_prototype.textureIds.push_back(currentTextureId); mesh_prototype.textureIds.push_back(currentTextureId);
} }
@@ -159,13 +157,13 @@ void Model::prepareModel()
model_prepared = true; model_prepared = true;
// Create textures on GPU // Create textures on GPU
for (auto& it : modelTexturePrototypes) { for (auto &it : modelTexturePrototypes) {
Texture *newTex = new Texture(it.texturePath.c_str(), it.textureType); Texture *newTex = new Texture(it.texturePath.c_str(), it.textureType);
loadedTextures.push_back(newTex); loadedTextures.push_back(newTex);
} }
// Create meshes on GPU // Create meshes on GPU
for (const auto& it : modelMeshPrototypes) { for (const auto &it : modelMeshPrototypes) {
std::vector<Texture *> meshTextures; std::vector<Texture *> meshTextures;
for (const auto it2 : it.textureIds) { for (const auto it2 : it.textureIds) {
meshTextures.push_back(loadedTextures[it2]); meshTextures.push_back(loadedTextures[it2]);
@@ -176,8 +174,7 @@ void Model::prepareModel()
} }
} }
Mesh *Model::getMesh(unsigned int index)
Mesh* Model::getMesh(unsigned int index)
{ {
return meshes[index]; return meshes[index];
} }

View File

@@ -5,12 +5,14 @@
#include "Mesh.h" #include "Mesh.h"
struct TexturePrototype { struct TexturePrototype
{
uint32_t textureType; uint32_t textureType;
std::string texturePath; std::string texturePath;
}; };
struct MeshPrototype { struct MeshPrototype
{
std::vector<uint32_t> textureIds; std::vector<uint32_t> textureIds;
std::vector<Vertex> meshVertices; std::vector<Vertex> meshVertices;
std::vector<uint32_t> meshIndices; std::vector<uint32_t> meshIndices;
@@ -19,7 +21,7 @@ struct MeshPrototype {
class Model class Model
{ {
public: public:
Model(const std::string& modelName, const std::string& pathToModel); Model(const std::string &modelName, const std::string &pathToModel);
~Model(); ~Model();
void prepareModel(); void prepareModel();
@@ -47,5 +49,4 @@ private:
static uint32_t id_counter; static uint32_t id_counter;
uint32_t id; uint32_t id;
std::string unique_name; std::string unique_name;
}; };

View File

@@ -3,11 +3,9 @@
uint32_t Screen::id_counter = 0; uint32_t Screen::id_counter = 0;
Screen::Screen(const std::string &name, std::vector<Widget*> widgets, Framebuffer *framebuffer, ShaderProgram *shaderProgram) : Screen::Screen(const std::string &name, std::vector<Widget *> widgets, Framebuffer *framebuffer,
unique_name(name), ShaderProgram *shaderProgram)
framebuffer(framebuffer), : unique_name(name), framebuffer(framebuffer), shaderProgram(shaderProgram), widgets(widgets)
shaderProgram(shaderProgram),
widgets(widgets)
{ {
id = id_counter++; id = id_counter++;
} }
@@ -15,31 +13,31 @@ Screen::Screen(const std::string &name, std::vector<Widget*> widgets, Framebuffe
Screen::~Screen() Screen::~Screen()
{ {
// Iterate over Widgets and Textures to delete all of them // Iterate over Widgets and Textures to delete all of them
for(auto it = widgets.begin(); it != widgets.end(); it++) { for (auto it = widgets.begin(); it != widgets.end(); it++) {
delete *it; delete *it;
} }
for(auto it = textures.begin(); it != textures.end(); it++) { for (auto it = textures.begin(); it != textures.end(); it++) {
delete *it; delete *it;
} }
} }
const std::string& Screen::getUniqueName() const const std::string &Screen::getUniqueName() const
{ {
return unique_name; return unique_name;
} }
std::vector<Widget*> Screen::getWidgets() const std::vector<Widget *> Screen::getWidgets() const
{ {
return widgets; return widgets;
} }
Widget *Screen::getWidgetByName(const std::string& name) const Widget *Screen::getWidgetByName(const std::string &name) const
{ {
if (m_widget_name_cache.find(name) != m_widget_name_cache.end()) if (m_widget_name_cache.find(name) != m_widget_name_cache.end())
return m_widget_name_cache[name]; return m_widget_name_cache[name];
for (auto it : widgets) { for (auto it : widgets) {
if(it->getUniqueName() == name) { if (it->getUniqueName() == name) {
m_widget_name_cache[name] = it; m_widget_name_cache[name] = it;
return it; return it;
} }
@@ -56,8 +54,8 @@ void Screen::draw() const
{ {
framebuffer->setExposureCorrection(false); framebuffer->setExposureCorrection(false);
framebuffer->bind(); framebuffer->bind();
for(auto it = widgets.begin(); it != widgets.end(); it++) { for (auto it = widgets.begin(); it != widgets.end(); it++) {
(*it)->draw(shaderProgram); (*it)->draw(shaderProgram);
} }
@@ -65,4 +63,3 @@ void Screen::draw() const
framebuffer->render(); framebuffer->render();
framebuffer->setExposureCorrection(true); framebuffer->setExposureCorrection(true);
} }

View File

@@ -2,8 +2,8 @@
#include <unordered_map> #include <unordered_map>
#include "ShaderProgram.h"
#include "Framebuffer.h" #include "Framebuffer.h"
#include "ShaderProgram.h"
#include "Widget.h" #include "Widget.h"
class Menu; class Menu;
@@ -11,16 +11,17 @@ class Menu;
class Screen class Screen
{ {
public: public:
Screen(const std::string& name, std::vector<Widget*> widgets, Framebuffer* framebuffer, ShaderProgram* shaderProgram); Screen(const std::string &name, std::vector<Widget *> widgets, Framebuffer *framebuffer,
ShaderProgram *shaderProgram);
~Screen(); ~Screen();
void addWidget(Widget *widget); void addWidget(Widget *widget);
void draw() const; void draw() const;
const std::string& getUniqueName() const; const std::string &getUniqueName() const;
std::vector<Widget*> getWidgets() const; std::vector<Widget *> getWidgets() const;
Widget *getWidgetByName(const std::string& name) const; Widget *getWidgetByName(const std::string &name) const;
private: private:
uint32_t id; uint32_t id;
static uint32_t id_counter; static uint32_t id_counter;
@@ -28,9 +29,9 @@ private:
Framebuffer *framebuffer; Framebuffer *framebuffer;
ShaderProgram *shaderProgram; ShaderProgram *shaderProgram;
std::vector<Texture*> textures;
std::vector<Widget*> widgets;
mutable std::unordered_map<std::string, Widget*> m_widget_name_cache; std::vector<Texture *> textures;
std::vector<Widget *> widgets;
mutable std::unordered_map<std::string, Widget *> m_widget_name_cache;
}; };

View File

@@ -1,13 +1,14 @@
#include <iostream>
#include <fstream> #include <fstream>
#include <string>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
#include <iostream>
#include <string>
#include "ShaderProgram.h" #include "ShaderProgram.h"
ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath, const std::string &fragmentShaderPath) : ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath,
unique_name(name) const std::string &fragmentShaderPath)
: unique_name(name)
{ {
std::string vertexShaderSource = parse(vertexShaderPath.c_str()); std::string vertexShaderSource = parse(vertexShaderPath.c_str());
std::string fragmentShaderSource = parse(fragmentShaderPath.c_str()); std::string fragmentShaderSource = parse(fragmentShaderPath.c_str());
@@ -36,8 +37,9 @@ ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexS
#endif #endif
} }
ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath, const std::string &geometryShaderPath, const std::string &fragmentShaderPath) : ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath,
unique_name(name) const std::string &geometryShaderPath, const std::string &fragmentShaderPath)
: unique_name(name)
{ {
std::string vertexShaderSource = parse(vertexShaderPath.c_str()); std::string vertexShaderSource = parse(vertexShaderPath.c_str());
std::string geometryShaderSource = parse(geometryShaderPath.c_str()); std::string geometryShaderSource = parse(geometryShaderPath.c_str());
@@ -57,7 +59,8 @@ ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexS
GLint isLinked = 0; GLint isLinked = 0;
glGetProgramiv(shaderProgramId, GL_LINK_STATUS, &isLinked); glGetProgramiv(shaderProgramId, GL_LINK_STATUS, &isLinked);
if (!isLinked) { if (!isLinked) {
std::cout << "Failed to link shaderProgram: " << vertexShaderPath << ", " << geometryShaderPath << ", " << fragmentShaderPath << std::endl; std::cout << "Failed to link shaderProgram: " << vertexShaderPath << ", " << geometryShaderPath << ", "
<< fragmentShaderPath << std::endl;
} }
#ifdef _RELEASE #ifdef _RELEASE
@@ -86,7 +89,7 @@ void ShaderProgram::unbind()
glUseProgram(0); glUseProgram(0);
} }
std::string ShaderProgram::parse(const std::string& filename) std::string ShaderProgram::parse(const std::string &filename)
{ {
std::fstream shaderfile; std::fstream shaderfile;
shaderfile.open(filename, std::ios::in); shaderfile.open(filename, std::ios::in);
@@ -101,7 +104,7 @@ std::string ShaderProgram::parse(const std::string& filename)
return contents; return contents;
} }
GLuint ShaderProgram::compile(const std::string& shaderSource, GLenum type) GLuint ShaderProgram::compile(const std::string &shaderSource, GLenum type)
{ {
GLuint shaderId = glCreateShader(type); GLuint shaderId = glCreateShader(type);
const char *src = shaderSource.c_str(); const char *src = shaderSource.c_str();
@@ -122,7 +125,8 @@ GLuint ShaderProgram::compile(const std::string& shaderSource, GLenum type)
return shaderId; return shaderId;
} }
GLint ShaderProgram::retrieveUniformLocation(const std::string& name) const { GLint ShaderProgram::retrieveUniformLocation(const std::string &name) const
{
if (uniformLocationCache.find(name) != uniformLocationCache.end()) if (uniformLocationCache.find(name) != uniformLocationCache.end())
return uniformLocationCache[name]; return uniformLocationCache[name];
@@ -132,37 +136,37 @@ GLint ShaderProgram::retrieveUniformLocation(const std::string& name) const {
return location; return location;
} }
void ShaderProgram::setUniform(const std::string& name, bool value) const void ShaderProgram::setUniform(const std::string &name, bool value) const
{ {
GLint location = retrieveUniformLocation(name); GLint location = retrieveUniformLocation(name);
glUniform1i(location, (int)value); glUniform1i(location, (int)value);
} }
void ShaderProgram::setUniform(const std::string& name, int value) const void ShaderProgram::setUniform(const std::string &name, int value) const
{ {
GLint location = retrieveUniformLocation(name); GLint location = retrieveUniformLocation(name);
glUniform1i(location, value); glUniform1i(location, value);
} }
void ShaderProgram::setUniform(const std::string& name, float value) const void ShaderProgram::setUniform(const std::string &name, float value) const
{ {
GLint location = retrieveUniformLocation(name); GLint location = retrieveUniformLocation(name);
glUniform1f(location, value); glUniform1f(location, value);
} }
void ShaderProgram::setUniform(const std::string& name, glm::vec3 vector) const void ShaderProgram::setUniform(const std::string &name, glm::vec3 vector) const
{ {
GLint location = retrieveUniformLocation(name); GLint location = retrieveUniformLocation(name);
glUniform3f(location, vector.x, vector.y, vector.z); glUniform3f(location, vector.x, vector.y, vector.z);
} }
void ShaderProgram::setUniform(const std::string& name, glm::mat3 matrix) const void ShaderProgram::setUniform(const std::string &name, glm::mat3 matrix) const
{ {
GLint location = retrieveUniformLocation(name); GLint location = retrieveUniformLocation(name);
glUniformMatrix3fv(location, 1, GL_FALSE, glm::value_ptr(matrix)); glUniformMatrix3fv(location, 1, GL_FALSE, glm::value_ptr(matrix));
} }
void ShaderProgram::setUniform(const std::string& name, glm::mat4 matrix) const void ShaderProgram::setUniform(const std::string &name, glm::mat4 matrix) const
{ {
GLint location = retrieveUniformLocation(name); GLint location = retrieveUniformLocation(name);
glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(matrix)); glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(matrix));

View File

@@ -2,35 +2,36 @@
#include <glad/glad.h> #include <glad/glad.h>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <unordered_map>
#include <string> #include <string>
#include <unordered_map>
class ShaderProgram class ShaderProgram
{ {
public: public:
ShaderProgram(const std::string &name, const std::string &vertexShaderPath, const std::string &fragmentShaderPath); ShaderProgram(const std::string &name, const std::string &vertexShaderPath, const std::string &fragmentShaderPath);
ShaderProgram(const std::string &name, const std::string &vertexShaderPath, const std::string &geometryShaderPath, const std::string &fragmentShaderPath); ShaderProgram(const std::string &name, const std::string &vertexShaderPath, const std::string &geometryShaderPath,
const std::string &fragmentShaderPath);
~ShaderProgram(); ~ShaderProgram();
void bind(); void bind();
void unbind(); void unbind();
GLint retrieveUniformLocation(const std::string& name) const; GLint retrieveUniformLocation(const std::string &name) const;
// May be rewritten... // May be rewritten...
void setUniform(const std::string& name, bool value) const; void setUniform(const std::string &name, bool value) const;
void setUniform(const std::string& name, int value) const; void setUniform(const std::string &name, int value) const;
void setUniform(const std::string& name, float value) const; void setUniform(const std::string &name, float value) const;
void setUniform(const std::string& name, glm::vec3 vector) const; void setUniform(const std::string &name, glm::vec3 vector) const;
void setUniform(const std::string& name, glm::mat3 matrix) const; void setUniform(const std::string &name, glm::mat3 matrix) const;
void setUniform(const std::string& name, glm::mat4 matrix) const; void setUniform(const std::string &name, glm::mat4 matrix) const;
public: public:
GLuint getShaderProgramId(); GLuint getShaderProgramId();
std::string getUniqueName(); std::string getUniqueName();
private: private:
std::string parse(const std::string& filename); std::string parse(const std::string &filename);
GLuint compile(const std::string& shaderSource, GLenum type); GLuint compile(const std::string &shaderSource, GLenum type);
private: private:
GLuint shaderProgramId; GLuint shaderProgramId;

View File

@@ -1,10 +1,10 @@
#include "Texture.h" #include "Texture.h"
#include <stb/stb_image.h>
#include <iostream> #include <iostream>
#include <stb/stb_image.h>
Texture::Texture(const std::string& texturePath, uint8_t textureType) : Texture::Texture(const std::string &texturePath, uint8_t textureType)
texturePath(texturePath), textureType(textureType) : texturePath(texturePath), textureType(textureType)
{ {
stbi_set_flip_vertically_on_load(1); stbi_set_flip_vertically_on_load(1);
auto *textureBuffer = stbi_load(texturePath.c_str(), &textureWidth, &textureHeight, &numComponents, 0); auto *textureBuffer = stbi_load(texturePath.c_str(), &textureWidth, &textureHeight, &numComponents, 0);
@@ -33,13 +33,13 @@ Texture::Texture(const std::string& texturePath, uint8_t textureType) :
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (!textureBuffer) { if (!textureBuffer) {
std::cout << "[Warning] Texture " << texturePath << " not found!" << std::endl; std::cout << "[Warning] Texture " << texturePath << " not found!" << std::endl;
return; return;
} }
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, textureWidth, textureHeight, 0, dataFormat, GL_UNSIGNED_BYTE, textureBuffer); glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, textureWidth, textureHeight, 0, dataFormat, GL_UNSIGNED_BYTE,
textureBuffer);
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
stbi_image_free(textureBuffer); stbi_image_free(textureBuffer);
@@ -124,36 +124,34 @@ CubeMap::CubeMap(const char *texturePseudoPath)
int32_t numComponents; int32_t numComponents;
auto *textureBuffer = stbi_load(texturePaths[i].c_str(), &textureWidth, &textureHeight, &numComponents, 0); auto *textureBuffer = stbi_load(texturePaths[i].c_str(), &textureWidth, &textureHeight, &numComponents, 0);
GLenum internalFormat; GLenum internalFormat;
GLenum dataFormat; GLenum dataFormat;
if (numComponents == 1) { if (numComponents == 1) {
internalFormat = GL_RED; internalFormat = GL_RED;
dataFormat = GL_RED; dataFormat = GL_RED;
} else if (numComponents == 3) { } else if (numComponents == 3) {
internalFormat = GL_SRGB8; internalFormat = GL_SRGB8;
dataFormat = GL_RGB; dataFormat = GL_RGB;
} else if (numComponents == 4) { } else if (numComponents == 4) {
internalFormat = GL_SRGB8_ALPHA8; internalFormat = GL_SRGB8_ALPHA8;
dataFormat = GL_RGBA; dataFormat = GL_RGBA;
} }
if (!textureBuffer) { if (!textureBuffer) {
std::cout << "[Warning] CubeMap Texture " << texturePaths[i].c_str() << " not found!" << std::endl; std::cout << "[Warning] CubeMap Texture " << texturePaths[i].c_str() << " not found!" << std::endl;
return; return;
} }
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, textureWidth, textureHeight, 0, dataFormat, GL_UNSIGNED_BYTE, textureBuffer); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, textureWidth, textureHeight, 0, dataFormat,
GL_UNSIGNED_BYTE, textureBuffer);
stbi_image_free(textureBuffer); stbi_image_free(textureBuffer);
} }
glBindTexture(GL_TEXTURE_CUBE_MAP, 0); glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
} }
CubeMap::CubeMap(int RESOLUTION) : CubeMap::CubeMap(int RESOLUTION) : textureWidth(RESOLUTION), textureHeight(RESOLUTION)
textureWidth(RESOLUTION),
textureHeight(RESOLUTION)
{ {
glGenTextures(1, &textureId); glGenTextures(1, &textureId);
@@ -167,7 +165,8 @@ CubeMap::CubeMap(int RESOLUTION) :
const unsigned int CUBEMAP_NUM_FACES = 6; const unsigned int CUBEMAP_NUM_FACES = 6;
for (unsigned int i = 0; i < CUBEMAP_NUM_FACES; i++) { for (unsigned int i = 0; i < CUBEMAP_NUM_FACES; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT24, RESOLUTION, RESOLUTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT24, RESOLUTION, RESOLUTION, 0,
GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
} }
glBindTexture(GL_TEXTURE_CUBE_MAP, 0); glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
@@ -195,12 +194,12 @@ void CubeMap::unbind()
void CubeMap::fillTexturePathVector(const char *texturePseudoPath) void CubeMap::fillTexturePathVector(const char *texturePseudoPath)
{ {
for (unsigned int i = 0; i < CUBEMAP_FACES_NUM_ITEMS; i++) { for (unsigned int i = 0; i < CUBEMAP_FACES_NUM_ITEMS; i++) {
texturePaths[cm_front] = std::string(texturePseudoPath) + "front.png"; texturePaths[cm_front] = std::string(texturePseudoPath) + "front.png";
texturePaths[cm_back] = std::string(texturePseudoPath) + "back.png"; texturePaths[cm_back] = std::string(texturePseudoPath) + "back.png";
texturePaths[cm_top] = std::string(texturePseudoPath) + "top.png"; texturePaths[cm_top] = std::string(texturePseudoPath) + "top.png";
texturePaths[cm_bottom] = std::string(texturePseudoPath) + "bottom.png"; texturePaths[cm_bottom] = std::string(texturePseudoPath) + "bottom.png";
texturePaths[cm_left] = std::string(texturePseudoPath) + "left.png"; texturePaths[cm_left] = std::string(texturePseudoPath) + "left.png";
texturePaths[cm_right] = std::string(texturePseudoPath) + "right.png"; texturePaths[cm_right] = std::string(texturePseudoPath) + "right.png";
} }
} }

View File

@@ -10,12 +10,21 @@
#include <vector> #include <vector>
// Order is important! // Order is important!
enum cubeMapFaces {cm_right, cm_left, cm_top, cm_bottom, cm_back, cm_front, CUBEMAP_FACES_NUM_ITEMS}; enum cubeMapFaces
{
cm_right,
cm_left,
cm_top,
cm_bottom,
cm_back,
cm_front,
CUBEMAP_FACES_NUM_ITEMS
};
class Texture class Texture
{ {
public: public:
Texture(const std::string& texturePath, uint8_t textureType); Texture(const std::string &texturePath, uint8_t textureType);
~Texture(); ~Texture();
void bind(uint8_t textureUnit, ShaderProgram *shaderProgram, uint8_t textureTypeNum); void bind(uint8_t textureUnit, ShaderProgram *shaderProgram, uint8_t textureTypeNum);

View File

@@ -19,23 +19,23 @@ VertexArray::VertexArray(void *vertexData, void *indexData, uint32_t numVertices
// Position // Position
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *) offsetof(struct Vertex, position)); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(struct Vertex, position));
// UV Texture Mapping // UV Texture Mapping
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *) offsetof(struct Vertex, textureCoords)); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(struct Vertex, textureCoords));
// Normal vectors // Normal vectors
glEnableVertexAttribArray(2); glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *) offsetof(struct Vertex, normalVec)); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(struct Vertex, normalVec));
// Tangent vectors // Tangent vectors
glEnableVertexAttribArray(3); glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *) offsetof(struct Vertex, tangentVec)); glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(struct Vertex, tangentVec));
// Bitangent vectors // Bitangent vectors
glEnableVertexAttribArray(4); glEnableVertexAttribArray(4);
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *) offsetof(struct Vertex, bitangentVec)); glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(struct Vertex, bitangentVec));
// This will also unbind the vertex buffer and index buffer // This will also unbind the vertex buffer and index buffer
glBindVertexArray(0); glBindVertexArray(0);
@@ -56,18 +56,19 @@ void VertexArray::unbind()
glBindVertexArray(0); glBindVertexArray(0);
} }
std::vector<Vertex> VertexArray::createVertices(double *vertices, uint32_t numVertices, float *textureCoordinates) { std::vector<Vertex> VertexArray::createVertices(double *vertices, uint32_t numVertices, float *textureCoordinates)
{
std::vector<Vertex> vertexVec; std::vector<Vertex> vertexVec;
uint32_t i = 0; uint32_t i = 0;
uint32_t k = 0; uint32_t k = 0;
for(; i < numVertices; i+=3) { for (; i < numVertices; i += 3) {
Vertex currentVertex = {}; Vertex currentVertex = {};
currentVertex.position.x = vertices[i]; currentVertex.position.x = vertices[i];
currentVertex.position.y = vertices[i+1]; currentVertex.position.y = vertices[i + 1];
currentVertex.position.z = vertices[i+2]; currentVertex.position.z = vertices[i + 2];
currentVertex.textureCoords.x = textureCoordinates[k]; currentVertex.textureCoords.x = textureCoordinates[k];
currentVertex.textureCoords.y = textureCoordinates[k+1]; currentVertex.textureCoords.y = textureCoordinates[k + 1];
k+=2; k += 2;
vertexVec.push_back(currentVertex); vertexVec.push_back(currentVertex);
} }
return vertexVec; return vertexVec;

View File

@@ -12,7 +12,7 @@ public:
void bind(); void bind();
void unbind(); void unbind();
static std::vector<Vertex> createVertices(double *vertices, uint32_t numVertices, float *textureCoordinates); static std::vector<Vertex> createVertices(double *vertices, uint32_t numVertices, float *textureCoordinates);
private: private:

View File

@@ -1,36 +1,23 @@
#include "Widget.h" #include "Widget.h"
#include "VertexArray.h"
#include "Menu.h" #include "Menu.h"
#include "VertexArray.h"
Widget::Widget(std::string &name, Texture *texture, float p_x, float p_y, float p_w, float p_h, uint16_t callbackId) : Widget::Widget(std::string &name, Texture *texture, float p_x, float p_y, float p_w, float p_h, uint16_t callbackId)
x(p_x), : x(p_x), y(p_y), w(p_w), h(p_h), unique_name(name), callbackId(callbackId)
y(p_y),
w(p_w),
h(p_h),
unique_name(name),
callbackId(callbackId)
{ {
widgetTextures.push_back(texture); widgetTextures.push_back(texture);
double widgetVerticesData[12] = { double widgetVerticesData[12] = {
2 * (x + w) - 1.0f, 2 * (y) - 1.0f, 0.0f, // Bottom right 2 * (x + w) - 1.0f, 2 * (y)-1.0f, 0.0f, // Bottom right
2 * (x) - 1.0f, 2 * (y + h) - 1.0f, 0.0f, // Top left 2 * (x)-1.0f, 2 * (y + h) - 1.0f, 0.0f, // Top left
2 * (x) - 1.0f, 2 * (y) - 1.0f, 0.0f, // Bottom left 2 * (x)-1.0f, 2 * (y)-1.0f, 0.0f, // Bottom left
2 * (x + w) - 1.0f, 2 * (y + h) - 1.0f, 0.0f // Top right 2 * (x + w) - 1.0f, 2 * (y + h) - 1.0f, 0.0f // Top right
}; };
unsigned int widgetIndicesData[6] = { unsigned int widgetIndicesData[6] = {0, 1, 2, 0, 3, 1};
0, 1, 2,
0, 3, 1 float widgetTextureCoordinates[8] = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f};
};
float widgetTextureCoordinates[8] = {
1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 1.0f
};
widgetVertices = VertexArray::createVertices(widgetVerticesData, 12, widgetTextureCoordinates); widgetVertices = VertexArray::createVertices(widgetVerticesData, 12, widgetTextureCoordinates);
widgetIndices.assign(widgetIndicesData, widgetIndicesData + 6); widgetIndices.assign(widgetIndicesData, widgetIndicesData + 6);
widgetMesh = new Mesh(widgetVertices, widgetIndices, widgetTextures); widgetMesh = new Mesh(widgetVertices, widgetIndices, widgetTextures);
@@ -69,7 +56,7 @@ bool Widget::isHovered(Window *window)
double yrel = -ypos / height + 1; double yrel = -ypos / height + 1;
bool isHovered = false; bool isHovered = false;
if(xrel >= x && xrel <= x + w && yrel >= y && yrel <= y + h) if (xrel >= x && xrel <= x + w && yrel >= y && yrel <= y + h)
isHovered = true; isHovered = true;
return isHovered; return isHovered;

View File

@@ -1,8 +1,8 @@
#pragma once #pragma once
#include "Texture.h"
#include "Mesh.h"
#include "Framebuffer.h" #include "Framebuffer.h"
#include "Mesh.h"
#include "Texture.h"
#include "Window.h" #include "Window.h"
#include "eventActions.h" #include "eventActions.h"
@@ -13,7 +13,7 @@ class Widget
public: public:
Widget(std::string &name, Texture *texture, float x, float y, float w, float h, uint16_t callbackId); Widget(std::string &name, Texture *texture, float x, float y, float w, float h, uint16_t callbackId);
~Widget(); ~Widget();
void draw(ShaderProgram *shaderProgram); void draw(ShaderProgram *shaderProgram);
std::string getUniqueName(); std::string getUniqueName();
@@ -27,10 +27,10 @@ private:
std::string unique_name; std::string unique_name;
uint16_t callbackId; uint16_t callbackId;
std::vector<Vertex> widgetVertices; std::vector<Vertex> widgetVertices;
std::vector<uint32_t> widgetIndices; std::vector<uint32_t> widgetIndices;
std::vector<Texture*> widgetTextures; std::vector<Texture *> widgetTextures;
Mesh *widgetMesh; Mesh *widgetMesh;
}; };

View File

@@ -1,10 +1,10 @@
#include <iostream>
#include <glad/glad.h> #include <glad/glad.h>
#include <iostream>
#include "Window.h"
#include "eventActions.h"
#include "defines.h"
#include "Helper.h" #include "Helper.h"
#include "Window.h"
#include "defines.h"
#include "eventActions.h"
Window::Window() Window::Window()
{ {
@@ -76,7 +76,7 @@ Window::Window()
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
// Tell GLFW which function to call when window is resized // Tell GLFW which function to call when window is resized
//glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); // glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
} }
Window::~Window() Window::~Window()
@@ -102,7 +102,6 @@ void Window::updateWindowDimensions()
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
} }
void Window::setCatchedCursor(bool value) void Window::setCatchedCursor(bool value)
{ {
if (value) { if (value) {
@@ -148,7 +147,7 @@ void Window::framebuffer_size_callback(GLFWwindow *window, int width, int height
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
} }
GLFWwindow* Window::getGLFWwindow() GLFWwindow *Window::getGLFWwindow()
{ {
return window; return window;
} }
@@ -165,7 +164,7 @@ int Window::getWindowHeight()
float Window::getWindowAspectRatio() float Window::getWindowAspectRatio()
{ {
return (float) width / (float) height; return (float)width / (float)height;
} }
bool Window::getMouseIsCatched() bool Window::getMouseIsCatched()

View File

@@ -1,12 +1,12 @@
#include "World.h" #include "World.h"
#include "JsonParser.h"
#include "Controller.h" #include "Controller.h"
#include "JsonParser.h"
#include <iostream> #include <iostream>
World::World(std::vector<ShaderProgram*> shaderPrograms) : World::World(std::vector<ShaderProgram *> shaderPrograms)
shaderProgram(Controller::getShaderProgramByName(shaderPrograms, "defaultProgram")), : shaderProgram(Controller::getShaderProgramByName(shaderPrograms, "defaultProgram")),
depthMapDirectionalFBO(DEPTHMAP_NORMAL, SHADOW_RES) depthMapDirectionalFBO(DEPTHMAP_NORMAL, SHADOW_RES)
{ {
// Create 4 depthMaps // Create 4 depthMaps
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
@@ -22,12 +22,13 @@ World::World(std::vector<ShaderProgram*> shaderPrograms) :
JsonParser modelParser("data/models.json"); JsonParser modelParser("data/models.json");
models = modelParser.getModels(); models = modelParser.getModels();
for (const auto& it : models) { for (const auto &it : models) {
it->prepareModel(); it->prepareModel();
} }
entities = modelParser.getEntities(models, shaderPrograms); entities = modelParser.getEntities(models, shaderPrograms);
skybox = modelParser.getSkybox(getModelByName("cube"), Controller::getShaderProgramByName(shaderPrograms, "skyboxProgram")); skybox = modelParser.getSkybox(getModelByName("cube"),
Controller::getShaderProgramByName(shaderPrograms, "skyboxProgram"));
JsonParser lightParser("data/lights.json"); JsonParser lightParser("data/lights.json");
lights = lightParser.getLights(shaderProgram); lights = lightParser.getLights(shaderProgram);
@@ -76,7 +77,7 @@ void World::clearEntities()
void World::updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color, float intensity) void World::updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color, float intensity)
{ {
std::vector<PointLight*> pointLights = getPointLights(); std::vector<PointLight *> pointLights = getPointLights();
pointLights[lightId]->setActive(active); pointLights[lightId]->setActive(active);
pointLights[lightId]->setPosition(position); pointLights[lightId]->setPosition(position);
pointLights[lightId]->setIntensity(intensity); pointLights[lightId]->setIntensity(intensity);
@@ -117,7 +118,8 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
// --- Directional shadows --- // --- Directional shadows ---
glm::mat4 directionalLightView = glm::lookAt(-5.0f * glm::vec3(-0.2f, -1.0f, -0.3f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); glm::mat4 directionalLightView =
glm::lookAt(-5.0f * glm::vec3(-0.2f, -1.0f, -0.3f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 directionalLightViewProjectionMatrix = directionalLightProjection * directionalLightView; glm::mat4 directionalLightViewProjectionMatrix = directionalLightProjection * directionalLightView;
// Draw scene from light perspective // Draw scene from light perspective
@@ -142,7 +144,7 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
shaderProgram->unbind(); shaderProgram->unbind();
// --- Point shadows --- // --- Point shadows ---
std::vector<PointLight*> pointLights = getPointLights(); std::vector<PointLight *> pointLights = getPointLights();
// 4 depthMaps for 4 point lights // 4 depthMaps for 4 point lights
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
@@ -153,17 +155,24 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
// Create 6 view matrices for every face of the cubeMap // Create 6 view matrices for every face of the cubeMap
std::vector<glm::mat4> viewProjMatrices; std::vector<glm::mat4> viewProjMatrices;
glm::vec3 lightPos = pointLights[i]->getPosition(); glm::vec3 lightPos = pointLights[i]->getPosition();
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f))); viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(1.0f, 0.0f, 0.0f),
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f))); glm::vec3(0.0f, -1.0f, 0.0f)));
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f))); viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(-1.0f, 0.0f, 0.0f),
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f))); glm::vec3(0.0f, -1.0f, 0.0f)));
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f))); viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 1.0f, 0.0f),
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))); glm::vec3(0.0f, 0.0f, 1.0f)));
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, -1.0f, 0.0f),
glm::vec3(0.0f, 0.0f, -1.0f)));
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, 1.0f),
glm::vec3(0.0f, -1.0f, 0.0f)));
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, -1.0f),
glm::vec3(0.0f, -1.0f, 0.0f)));
pointShaderProgram->bind(); pointShaderProgram->bind();
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
pointShaderProgram->setUniform(("u_shadowMatrices[" + std::to_string(i) + "]").c_str(), viewProjMatrices[i]); pointShaderProgram->setUniform(("u_shadowMatrices[" + std::to_string(i) + "]").c_str(),
viewProjMatrices[i]);
} }
pointShaderProgram->setUniform("pointShadowDepthMapFarPlane", far_plane_point); pointShaderProgram->setUniform("pointShadowDepthMapFarPlane", far_plane_point);
@@ -194,10 +203,10 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
glCullFace(GL_FRONT); glCullFace(GL_FRONT);
} }
Model* World::getModelByName(std::string name) Model *World::getModelByName(std::string name)
{ {
for (auto it = models.begin(); it != models.end(); it++) { for (auto it = models.begin(); it != models.end(); it++) {
if((*it)->getUniqueName() == name) { if ((*it)->getUniqueName() == name) {
return *it; return *it;
} }
} }
@@ -205,10 +214,10 @@ Model* World::getModelByName(std::string name)
return nullptr; return nullptr;
} }
Entity* World::getEntityByName(std::string name) Entity *World::getEntityByName(std::string name)
{ {
for (auto it = entities.begin(); it != entities.end(); it++) { for (auto it = entities.begin(); it != entities.end(); it++) {
if((*it)->getUniqueName() == name) { if ((*it)->getUniqueName() == name) {
return *it; return *it;
} }
} }
@@ -216,10 +225,10 @@ Entity* World::getEntityByName(std::string name)
return nullptr; return nullptr;
} }
Entity* World::getEntityById(uint32_t id) Entity *World::getEntityById(uint32_t id)
{ {
for (auto it = entities.begin(); it != entities.end(); it++) { for (auto it = entities.begin(); it != entities.end(); it++) {
if((*it)->getId() == id) { if ((*it)->getId() == id) {
return *it; return *it;
} }
} }
@@ -227,12 +236,12 @@ Entity* World::getEntityById(uint32_t id)
return nullptr; return nullptr;
} }
std::vector<PointLight*> World::getPointLights() std::vector<PointLight *> World::getPointLights()
{ {
std::vector<PointLight*> temp_pointLights; std::vector<PointLight *> temp_pointLights;
for (auto it = lights.begin(); it != lights.end(); it++) { for (auto it = lights.begin(); it != lights.end(); it++) {
PointLight *temp_pointLight = dynamic_cast<PointLight*>(*it); PointLight *temp_pointLight = dynamic_cast<PointLight *>(*it);
if (temp_pointLight) { if (temp_pointLight) {
temp_pointLights.push_back(temp_pointLight); temp_pointLights.push_back(temp_pointLight);
} }
@@ -241,25 +250,25 @@ std::vector<PointLight*> World::getPointLights()
return temp_pointLights; return temp_pointLights;
} }
DirectionalLight * World::getDirectionalLight() DirectionalLight *World::getDirectionalLight()
{ {
DirectionalLight *temp_directionalLight = nullptr; DirectionalLight *temp_directionalLight = nullptr;
for (auto it = lights.begin(); it != lights.end(); it++) { for (auto it = lights.begin(); it != lights.end(); it++) {
temp_directionalLight = dynamic_cast<DirectionalLight*>(*it); temp_directionalLight = dynamic_cast<DirectionalLight *>(*it);
if(temp_directionalLight) if (temp_directionalLight)
break; break;
} }
return temp_directionalLight; return temp_directionalLight;
} }
std::vector<Entity*> World::getEntities() std::vector<Entity *> World::getEntities()
{ {
return entities; return entities;
} }
Skybox* World::getSkybox() Skybox *World::getSkybox()
{ {
return skybox; return skybox;
} }

View File

@@ -2,16 +2,16 @@
#include <vector> #include <vector>
#include "Light.h"
#include "Camera.h" #include "Camera.h"
#include "Entity.h" #include "Entity.h"
#include "ShaderProgram.h"
#include "Framebuffer.h" #include "Framebuffer.h"
#include "Light.h"
#include "ShaderProgram.h"
class World class World
{ {
public: public:
World(std::vector<ShaderProgram*> shaderPrograms); World(std::vector<ShaderProgram *> shaderPrograms);
~World(); ~World();
void addEntity(Entity *entity); void addEntity(Entity *entity);
@@ -21,13 +21,13 @@ public:
void updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color, float intensity); void updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color, float intensity);
void updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color); void updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color);
std::vector<Entity*> getEntities(); std::vector<Entity *> getEntities();
std::vector<PointLight*> getPointLights(); std::vector<PointLight *> getPointLights();
DirectionalLight * getDirectionalLight(); DirectionalLight *getDirectionalLight();
Skybox *getSkybox(); Skybox *getSkybox();
Entity* getEntityByName(std::string name); Entity *getEntityByName(std::string name);
Entity* getEntityById(uint32_t id); Entity *getEntityById(uint32_t id);
Model* getModelByName(std::string name); Model *getModelByName(std::string name);
void draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition); void draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition);
void calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProgram *pointShaderProgram); void calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProgram *pointShaderProgram);
@@ -35,12 +35,12 @@ public:
private: private:
ShaderProgram *shaderProgram; ShaderProgram *shaderProgram;
std::vector<Model*> models; std::vector<Model *> models;
std::vector<Entity*> entities; std::vector<Entity *> entities;
Skybox *skybox; Skybox *skybox;
// Lights // Lights
std::vector<Light*> lights; std::vector<Light *> lights;
// Shadows // Shadows
const int SHADOW_RES = 4096 / 4; const int SHADOW_RES = 4096 / 4;
@@ -49,9 +49,11 @@ private:
// Shadow projection matrices // Shadow projection matrices
const float near_plane_directional = 1.0f; const float near_plane_directional = 1.0f;
const float far_plane_directional = 15.0f; const float far_plane_directional = 15.0f;
glm::mat4 directionalLightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane_directional, far_plane_directional); glm::mat4 directionalLightProjection =
glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane_directional, far_plane_directional);
const float aspect_ratio_point = 1.0f; const float aspect_ratio_point = 1.0f;
const float near_plane_point = 1.0f; const float near_plane_point = 1.0f;
const float far_plane_point = 25.0f; const float far_plane_point = 25.0f;
glm::mat4 pointLightProjection = glm::perspective(glm::radians(90.0f), aspect_ratio_point, near_plane_point, far_plane_point); glm::mat4 pointLightProjection =
glm::perspective(glm::radians(90.0f), aspect_ratio_point, near_plane_point, far_plane_point);
}; };

View File

@@ -5,7 +5,8 @@
#define INIT_WINDOW_WIDTH 1280 #define INIT_WINDOW_WIDTH 1280
#define INIT_WINDOW_HEIGHT 720 #define INIT_WINDOW_HEIGHT 720
enum textureType { enum textureType
{
texture_diffuse, texture_diffuse,
texture_specular, texture_specular,
texture_normal, texture_normal,

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
enum cameraActions { enum cameraActions
{
cameraUp, cameraUp,
cameraDown, cameraDown,
cameraForward, cameraForward,
@@ -10,20 +11,23 @@ enum cameraActions {
CAMERA_ACTION_NUM_ITEMS CAMERA_ACTION_NUM_ITEMS
}; };
enum cameraMouseActions { enum cameraMouseActions
{
cameraMouseDeltaX, cameraMouseDeltaX,
cameraMouseDeltaY, cameraMouseDeltaY,
CAMERA_MOUSE_ACTION_NUM_ITEMS CAMERA_MOUSE_ACTION_NUM_ITEMS
}; };
enum windowActions { enum windowActions
{
wireFrameToggle, wireFrameToggle,
mouseCatchToggle, mouseCatchToggle,
windowShouldClose, windowShouldClose,
WINDOW_ACTION_NUM_ITEMS WINDOW_ACTION_NUM_ITEMS
}; };
enum mouseButtonActions { enum mouseButtonActions
{
leftClicked, leftClicked,
rightClicked, rightClicked,
middleClicked, middleClicked,

View File

@@ -1,6 +1,6 @@
#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <glad/glad.h>
#include <iostream>
#include "Controller.h" #include "Controller.h"
@@ -17,13 +17,13 @@ int main(int argc, char **argv)
// Create controller // Create controller
Controller *mainController = new Controller(); Controller *mainController = new Controller();
const char* fps_env = std::getenv("MAXFPS"); const char *fps_env = std::getenv("MAXFPS");
if(fps_env) { if (fps_env) {
uint16_t maxfps = std::stoul(fps_env); uint16_t maxfps = std::stoul(fps_env);
mainController->setMaxFps(maxfps); mainController->setMaxFps(maxfps);
std::cout << "[Warning] Default max FPS overridden with " << maxfps << " by environment." << std::endl; std::cout << "[Warning] Default max FPS overridden with " << maxfps << " by environment." << std::endl;
} }
mainController->run(); mainController->run();
delete mainController; delete mainController;