Format code with clang-format.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#include "Camera.h"
|
||||
#include "eventActions.h"
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
Camera::Camera(float fov, float aspectRatio)
|
||||
{
|
||||
@@ -19,7 +19,7 @@ void Camera::updateVPM()
|
||||
|
||||
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);
|
||||
updateVPM();
|
||||
}
|
||||
@@ -79,7 +79,7 @@ void Camera::updateDirectionFromMouseInput(double *cameraMouseActionRegister)
|
||||
pitch += cameraMouseActionRegister[cameraMouseDeltaY];
|
||||
|
||||
if (pitch > 89.0f) {
|
||||
pitch = 89.0f;
|
||||
pitch = 89.0f;
|
||||
}
|
||||
if (pitch < -89.0f) {
|
||||
pitch = -89.0f;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include "ShaderProgram.h"
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class Camera
|
||||
{
|
||||
@@ -34,7 +34,7 @@ private:
|
||||
|
||||
glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.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 yaw = -90.0f;
|
||||
@@ -43,5 +43,3 @@ private:
|
||||
|
||||
float fov;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
#include <imgui_impl_opengl3.h>
|
||||
#endif
|
||||
|
||||
#include "Helper.h"
|
||||
#include "Controller.h"
|
||||
#include "VertexArray.h"
|
||||
#include "Texture.h"
|
||||
#include "Model.h"
|
||||
#include "Entity.h"
|
||||
#include "World.h"
|
||||
#include "Widget.h"
|
||||
#include "Screen.h"
|
||||
#include "Helper.h"
|
||||
#include "JsonParser.h"
|
||||
#include "Model.h"
|
||||
#include "Screen.h"
|
||||
#include "Texture.h"
|
||||
#include "VertexArray.h"
|
||||
#include "Widget.h"
|
||||
#include "World.h"
|
||||
|
||||
Controller::Controller()
|
||||
{
|
||||
@@ -33,7 +33,8 @@ Controller::Controller()
|
||||
JsonParser shaderParser("data/shaderPrograms.json");
|
||||
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"));
|
||||
|
||||
@@ -119,7 +120,7 @@ void Controller::run()
|
||||
getShaderProgramByName("lightProgram")->unbind();
|
||||
|
||||
// --- Render and buffer swap ---
|
||||
|
||||
|
||||
// Calc shadows
|
||||
static bool drawShadows = false;
|
||||
static bool firstRun = true;
|
||||
@@ -128,13 +129,14 @@ void Controller::run()
|
||||
getShaderProgramByName("defaultProgram")->unbind();
|
||||
if (drawShadows || firstRun) {
|
||||
firstRun = false;
|
||||
world->calculateShadows(getShaderProgramByName("directionalShadowDepthProgram"), getShaderProgramByName("pointShadowDepthProgram"));
|
||||
world->calculateShadows(getShaderProgramByName("directionalShadowDepthProgram"),
|
||||
getShaderProgramByName("pointShadowDepthProgram"));
|
||||
}
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
auto activeScreen = menu->getActiveScreen();
|
||||
if(activeScreen) {
|
||||
if (activeScreen) {
|
||||
activeScreen->draw();
|
||||
} else {
|
||||
pp_framebuffer->bind();
|
||||
@@ -150,7 +152,8 @@ void Controller::run()
|
||||
pp_framebuffer->render();
|
||||
|
||||
#ifdef _DEBUG
|
||||
renderImGui(world, &lightColor, &rotateEntity, &rotateLightSource, getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows);
|
||||
renderImGui(world, &lightColor, &rotateEntity, &rotateLightSource,
|
||||
getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows);
|
||||
#endif
|
||||
}
|
||||
glfwSwapBuffers(gameWindow->getGLFWwindow());
|
||||
@@ -168,7 +171,7 @@ void Controller::run()
|
||||
if (gameWindow->getMouseIsCatched()) {
|
||||
camera->updateDirectionFromMouseInput(gameEventHandler->getCursorDelta());
|
||||
}
|
||||
|
||||
|
||||
menu->writeWindowActions(gameEventHandler->getWindowActionRegister());
|
||||
gameWindow->handleWindowActionRegister(gameEventHandler->getWindowActionRegister());
|
||||
|
||||
@@ -210,10 +213,10 @@ void Controller::updateExposure(ShaderProgram *shaderProgram)
|
||||
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++) {
|
||||
if((*it)->getUniqueName() == name) {
|
||||
if ((*it)->getUniqueName() == name) {
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
@@ -221,10 +224,10 @@ ShaderProgram* Controller::getShaderProgramByName(const std::string& name)
|
||||
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++) {
|
||||
if((*it)->getUniqueName() == name) {
|
||||
if ((*it)->getUniqueName() == name) {
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
@@ -238,13 +241,13 @@ void Controller::setMaxFps(uint16_t fps)
|
||||
}
|
||||
|
||||
#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_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
|
||||
// render your GUI
|
||||
ImGui::Begin("Debug Utils");
|
||||
ImGui::Text("Object");
|
||||
@@ -283,8 +286,8 @@ void Controller::renderImGui(World *world, glm::vec3 *lightColor, bool *rotateEn
|
||||
ImGui::Checkbox("Draw Shadows", drawShadows);
|
||||
ImGui::Checkbox("Rotate Lightsource", rotateLightSource);
|
||||
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)",
|
||||
1000.0 / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0 / ImGui::GetIO().Framerate,
|
||||
ImGui::GetIO().Framerate);
|
||||
|
||||
ImGui::End();
|
||||
|
||||
|
||||
@@ -2,17 +2,16 @@
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "Window.h"
|
||||
#include "EventHandler.h"
|
||||
#include "Camera.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Entity.h"
|
||||
#include "defines.h"
|
||||
#include "Light.h"
|
||||
#include "EventHandler.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "Light.h"
|
||||
#include "Menu.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Window.h"
|
||||
#include "World.h"
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
class Controller
|
||||
{
|
||||
@@ -24,7 +23,7 @@ public:
|
||||
|
||||
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:
|
||||
void limit_framerate();
|
||||
@@ -32,9 +31,10 @@ private:
|
||||
void updateWindowDimensions();
|
||||
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:
|
||||
Window *gameWindow;
|
||||
@@ -45,11 +45,10 @@ private:
|
||||
Camera *camera;
|
||||
Menu *menu;
|
||||
|
||||
std::vector<ShaderProgram*> shaderPrograms;
|
||||
std::vector<ShaderProgram *> shaderPrograms;
|
||||
|
||||
Framebuffer *pp_framebuffer;
|
||||
|
||||
|
||||
uint16_t MAX_FPS = 60;
|
||||
double deltaTime;
|
||||
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
#include "Entity.h"
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
uint32_t Entity::id_counter = 0;
|
||||
|
||||
Entity::Entity(std::string name, Model *model, ShaderProgram *shaderProgram) :
|
||||
unique_name(name),
|
||||
model(model),
|
||||
shaderProgram(shaderProgram)
|
||||
Entity::Entity(std::string name, Model *model, ShaderProgram *shaderProgram)
|
||||
: unique_name(name), model(model), shaderProgram(shaderProgram)
|
||||
{
|
||||
id = id_counter++;
|
||||
}
|
||||
@@ -147,11 +145,9 @@ bool Entity::getIsLightSource()
|
||||
return isLightSource;
|
||||
}
|
||||
|
||||
Skybox::Skybox(Model *cubeModel, ShaderProgram *shaderProgram, const char *texturePseudoPath) :
|
||||
cubeModel(cubeModel),
|
||||
shaderProgram(shaderProgram),
|
||||
cubeMap(texturePseudoPath),
|
||||
vertexArray(cubeModel->getMesh(0)->getVertexArray())
|
||||
Skybox::Skybox(Model *cubeModel, ShaderProgram *shaderProgram, const char *texturePseudoPath)
|
||||
: cubeModel(cubeModel), shaderProgram(shaderProgram), cubeMap(texturePseudoPath),
|
||||
vertexArray(cubeModel->getMesh(0)->getVertexArray())
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "Model.h"
|
||||
#include "Texture.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Texture.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
@@ -10,9 +10,7 @@ bool EventHandler::windowActionRegister[WINDOW_ACTION_NUM_ITEMS] = {0};
|
||||
bool EventHandler::firstMouseInput = 1;
|
||||
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);
|
||||
glfwSetCursorPosCallback(window, mouse_callback);
|
||||
@@ -27,7 +25,7 @@ void EventHandler::handleEvents()
|
||||
|
||||
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(windowActionRegister, WINDOW_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;
|
||||
}
|
||||
|
||||
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)
|
||||
mouseButtonActionRegister[mouseButtonActions::leftClicked] = true;
|
||||
@@ -132,22 +131,22 @@ void EventHandler::mouse_button_callback(GLFWwindow* window, int button, int act
|
||||
mouseButtonActionRegister[mouseButtonActions::middleClicked] = true;
|
||||
}
|
||||
|
||||
bool * EventHandler::getCameraActionRegister()
|
||||
bool *EventHandler::getCameraActionRegister()
|
||||
{
|
||||
return cameraActionRegister;
|
||||
}
|
||||
|
||||
bool * EventHandler::getWindowActionRegister()
|
||||
bool *EventHandler::getWindowActionRegister()
|
||||
{
|
||||
return windowActionRegister;
|
||||
}
|
||||
|
||||
bool * EventHandler::getMouseButtonActionRegister()
|
||||
bool *EventHandler::getMouseButtonActionRegister()
|
||||
{
|
||||
return mouseButtonActionRegister;
|
||||
}
|
||||
|
||||
double * EventHandler::getCursorDelta()
|
||||
double *EventHandler::getCursorDelta()
|
||||
{
|
||||
return cameraMouseActionRegister;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
|
||||
Framebuffer::Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram) :
|
||||
shaderProgram(shaderProgram)
|
||||
Framebuffer::Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram) : shaderProgram(shaderProgram)
|
||||
{
|
||||
glGenFramebuffers(1, &FBO);
|
||||
|
||||
@@ -90,7 +89,6 @@ void Framebuffer::generateTextures(uint32_t width, uint32_t height)
|
||||
unbind();
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::setExposureCorrection(bool exposureCorrection)
|
||||
{
|
||||
shaderProgram->bind();
|
||||
@@ -112,7 +110,8 @@ DepthMap::DepthMap(int TYPE, int RESOLUTION)
|
||||
|
||||
glGenTextures(1, &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_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
@@ -140,11 +139,10 @@ DepthMap::DepthMap(int TYPE, int RESOLUTION)
|
||||
|
||||
DepthMap::~DepthMap()
|
||||
{
|
||||
if(cubeMap)
|
||||
if (cubeMap)
|
||||
delete cubeMap;
|
||||
}
|
||||
|
||||
|
||||
void DepthMap::bind()
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include "ShaderProgram.h"
|
||||
#include "Texture.h"
|
||||
#include <glad/glad.h>
|
||||
|
||||
class Framebuffer
|
||||
{
|
||||
public:
|
||||
Framebuffer(uint32_t width, uint32_t height, ShaderProgram* shaderProgram);
|
||||
Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram);
|
||||
~Framebuffer();
|
||||
|
||||
void bind();
|
||||
@@ -31,7 +31,11 @@ private:
|
||||
ShaderProgram *shaderProgram;
|
||||
};
|
||||
|
||||
enum depthMapType {DEPTHMAP_NORMAL, DEPTHMAP_CUBEMAP};
|
||||
enum depthMapType
|
||||
{
|
||||
DEPTHMAP_NORMAL,
|
||||
DEPTHMAP_CUBEMAP
|
||||
};
|
||||
|
||||
// Framebuffer without color buffer. (Shadows)
|
||||
class DepthMap
|
||||
|
||||
145
src/Helper.cpp
145
src/Helper.cpp
@@ -1,7 +1,7 @@
|
||||
#include "Helper.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
@@ -21,116 +21,117 @@ void Helper::sleep(uint32_t us)
|
||||
#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)userParam;
|
||||
|
||||
const char* _source;
|
||||
const char* _type;
|
||||
const char* _severity;
|
||||
const char *_source;
|
||||
const char *_type;
|
||||
const char *_severity;
|
||||
|
||||
// Remove unwanted newline characters from message string
|
||||
std::string _message = message;
|
||||
_message.erase(std::remove(_message.begin(), _message.end(), '\n'), _message.end());
|
||||
|
||||
switch (source) {
|
||||
case GL_DEBUG_SOURCE_API:
|
||||
_source = "API";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_API:
|
||||
_source = "API";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
|
||||
_source = "WINDOW SYSTEM";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
|
||||
_source = "WINDOW SYSTEM";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SOURCE_SHADER_COMPILER:
|
||||
_source = "SHADER COMPILER";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_SHADER_COMPILER:
|
||||
_source = "SHADER COMPILER";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SOURCE_THIRD_PARTY:
|
||||
_source = "THIRD PARTY";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_THIRD_PARTY:
|
||||
_source = "THIRD PARTY";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SOURCE_APPLICATION:
|
||||
_source = "APPLICATION";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_APPLICATION:
|
||||
_source = "APPLICATION";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SOURCE_OTHER:
|
||||
_source = "UNKNOWN";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_OTHER:
|
||||
_source = "UNKNOWN";
|
||||
break;
|
||||
|
||||
default:
|
||||
_source = "UNKNOWN";
|
||||
break;
|
||||
default:
|
||||
_source = "UNKNOWN";
|
||||
break;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case GL_DEBUG_TYPE_ERROR:
|
||||
_type = "ERROR";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_ERROR:
|
||||
_type = "ERROR";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
||||
_type = "DEPRECATED BEHAVIOR";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
||||
_type = "DEPRECATED BEHAVIOR";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
||||
_type = "UDEFINED BEHAVIOR";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
||||
_type = "UDEFINED BEHAVIOR";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_TYPE_PORTABILITY:
|
||||
_type = "PORTABILITY";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PORTABILITY:
|
||||
_type = "PORTABILITY";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_TYPE_PERFORMANCE:
|
||||
_type = "PERFORMANCE";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PERFORMANCE:
|
||||
_type = "PERFORMANCE";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_TYPE_OTHER:
|
||||
_type = "OTHER";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_OTHER:
|
||||
_type = "OTHER";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_TYPE_MARKER:
|
||||
_type = "MARKER";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_MARKER:
|
||||
_type = "MARKER";
|
||||
break;
|
||||
|
||||
default:
|
||||
_type = "UNKNOWN";
|
||||
break;
|
||||
default:
|
||||
_type = "UNKNOWN";
|
||||
break;
|
||||
}
|
||||
|
||||
switch (severity) {
|
||||
case GL_DEBUG_SEVERITY_HIGH:
|
||||
_severity = "HIGH";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_HIGH:
|
||||
_severity = "HIGH";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SEVERITY_MEDIUM:
|
||||
_severity = "MEDIUM";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_MEDIUM:
|
||||
_severity = "MEDIUM";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
_severity = "LOW";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
_severity = "LOW";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
||||
_severity = "NOTIFICATION";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
||||
_severity = "NOTIFICATION";
|
||||
break;
|
||||
|
||||
default:
|
||||
_severity = "UNKNOWN";
|
||||
break;
|
||||
default:
|
||||
_severity = "UNKNOWN";
|
||||
break;
|
||||
}
|
||||
|
||||
if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM)
|
||||
std::cout << "[OpenGL Debug Message]" << std::endl
|
||||
<< "Message: " << _message << std::endl
|
||||
<< "Source: " << _source << std::endl
|
||||
<< "Type: " << _type << std::endl
|
||||
<< "ID: " << id << std::endl
|
||||
<< "Severity: " << _severity << std::endl
|
||||
<< std::endl;
|
||||
<< "Message: " << _message << std::endl
|
||||
<< "Source: " << _source << std::endl
|
||||
<< "Type: " << _type << std::endl
|
||||
<< "ID: " << id << std::endl
|
||||
<< "Severity: " << _severity << 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();
|
||||
}
|
||||
|
||||
17
src/Helper.h
17
src/Helper.h
@@ -1,19 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <chrono>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
namespace Helper
|
||||
{
|
||||
namespace Helper {
|
||||
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:
|
||||
Timer(const std::string& name);
|
||||
Timer(const std::string &name);
|
||||
~Timer();
|
||||
|
||||
private:
|
||||
@@ -22,4 +23,4 @@ private:
|
||||
std::chrono::duration<float> duration;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Helper
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "JsonParser.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#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);
|
||||
|
||||
@@ -24,17 +24,16 @@ JsonParser::JsonParser(const std::string& path)
|
||||
}
|
||||
|
||||
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"];
|
||||
|
||||
struct ModelSkeleton {
|
||||
struct ModelSkeleton
|
||||
{
|
||||
std::string model_name;
|
||||
std::string model_path;
|
||||
};
|
||||
@@ -51,26 +50,27 @@ std::vector<Model*> JsonParser::getModels()
|
||||
std::vector<std::future<void>> futures;
|
||||
std::mutex mutex;
|
||||
|
||||
auto* temp_models_ptr = &temp_models;
|
||||
for (const auto& model_skeleton : model_skeletons) {
|
||||
auto *temp_models_ptr = &temp_models;
|
||||
for (const auto &model_skeleton : model_skeletons) {
|
||||
auto loadModel = [&]() {
|
||||
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);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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"];
|
||||
|
||||
@@ -83,20 +83,21 @@ std::vector<Entity*> JsonParser::getEntities(std::vector<Model*> &models, std::v
|
||||
|
||||
ShaderProgram *shaderProgram = nullptr;
|
||||
for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) {
|
||||
if((*it)->getUniqueName() == entity_shaderProgram) {
|
||||
if ((*it)->getUniqueName() == entity_shaderProgram) {
|
||||
shaderProgram = *it;
|
||||
}
|
||||
}
|
||||
if(!shaderProgram)
|
||||
std::cout << "[Warning] ShaderProgram could not be found by name \"" << entity_shaderProgram << "\"" << std::endl;
|
||||
if (!shaderProgram)
|
||||
std::cout << "[Warning] ShaderProgram could not be found by name \"" << entity_shaderProgram << "\""
|
||||
<< std::endl;
|
||||
|
||||
Model *current_model = nullptr;
|
||||
for (auto it = models.begin(); it != models.end(); it++) {
|
||||
if((*it)->getUniqueName() == entity_model) {
|
||||
if ((*it)->getUniqueName() == entity_model) {
|
||||
current_model = *it;
|
||||
}
|
||||
}
|
||||
if(!current_model) {
|
||||
if (!current_model) {
|
||||
// Apply fallback model (first model in vector)
|
||||
current_model = models[0];
|
||||
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 rotationJson = entitiesJson[index]["rotation"];
|
||||
const Json::Value scaleJson = entitiesJson[index]["scale"];
|
||||
if(!positionJson.empty()) {
|
||||
if (!positionJson.empty()) {
|
||||
entitiy_position.x = positionJson[0].asFloat();
|
||||
entitiy_position.y = positionJson[1].asFloat();
|
||||
entitiy_position.z = positionJson[2].asFloat();
|
||||
}
|
||||
if(!rotationJson.empty()) {
|
||||
if (!rotationJson.empty()) {
|
||||
entity_rotation.s = rotationJson[0].asFloat();
|
||||
entity_rotation.t = rotationJson[1].asFloat();
|
||||
entity_rotation.p = rotationJson[2].asFloat();
|
||||
}
|
||||
if(!scaleJson.empty()) {
|
||||
if (!scaleJson.empty()) {
|
||||
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*> temp_shaderPrograms;
|
||||
std::vector<ShaderProgram *> temp_shaderPrograms;
|
||||
|
||||
const Json::Value shaderProgramsJson = root["shaderPrograms"];
|
||||
|
||||
@@ -143,10 +144,12 @@ std::vector<ShaderProgram *> JsonParser::getShaderPrograms()
|
||||
std::string shaderProgram_geometryPath = shaderProgramsJson[index]["geometryPath"].asString();
|
||||
|
||||
ShaderProgram *current_shaderProgram;
|
||||
if(shaderProgram_geometryPath.empty()) {
|
||||
current_shaderProgram = new ShaderProgram(shaderProgram_name, shaderProgram_vertexPath, shaderProgram_fragmentPath);
|
||||
if (shaderProgram_geometryPath.empty()) {
|
||||
current_shaderProgram =
|
||||
new ShaderProgram(shaderProgram_name, shaderProgram_vertexPath, shaderProgram_fragmentPath);
|
||||
} 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);
|
||||
std::cout << "Loaded ShaderProgram \"" << shaderProgram_name << "\"" << std::endl;
|
||||
@@ -155,9 +158,9 @@ std::vector<ShaderProgram *> JsonParser::getShaderPrograms()
|
||||
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_position = {};
|
||||
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 intensityJson = directionalLightsJson["intensity"];
|
||||
|
||||
if(!intensityJson.empty()) {
|
||||
if (!intensityJson.empty()) {
|
||||
light_intensity = intensityJson.asFloat();
|
||||
}
|
||||
if(!directionJson.empty()) {
|
||||
if (!directionJson.empty()) {
|
||||
light_direction.x = directionJson[0].asFloat();
|
||||
light_direction.y = directionJson[1].asFloat();
|
||||
light_direction.z = directionJson[2].asFloat();
|
||||
}
|
||||
if(!colorJson.empty()) {
|
||||
if (!colorJson.empty()) {
|
||||
light_color.x = colorJson[0].asFloat();
|
||||
light_color.y = colorJson[1].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);
|
||||
temp_lights.push_back(current_directionalLight);
|
||||
|
||||
@@ -198,15 +202,15 @@ std::vector<Light*> JsonParser::getLights(ShaderProgram* shaderProgram)
|
||||
colorJson = pointLightsJson[index]["color"];
|
||||
intensityJson = pointLightsJson[index]["intensity"];
|
||||
|
||||
if(!intensityJson.empty()) {
|
||||
if (!intensityJson.empty()) {
|
||||
light_intensity = intensityJson.asFloat();
|
||||
}
|
||||
if(!positionJson.empty()) {
|
||||
if (!positionJson.empty()) {
|
||||
light_position.x = positionJson[0].asFloat();
|
||||
light_position.y = positionJson[1].asFloat();
|
||||
light_position.z = positionJson[2].asFloat();
|
||||
}
|
||||
if(!colorJson.empty()) {
|
||||
if (!colorJson.empty()) {
|
||||
light_color.x = colorJson[0].asFloat();
|
||||
light_color.y = colorJson[1].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
|
||||
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_color(1.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);
|
||||
temp_lights.push_back(current_pointLight);
|
||||
}
|
||||
@@ -230,9 +235,9 @@ std::vector<Light*> JsonParser::getLights(ShaderProgram* shaderProgram)
|
||||
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 mainMenuScreenJson = root["mainMenuScreen"];
|
||||
@@ -251,9 +256,9 @@ std::vector<Screen*> JsonParser::getScreens(ShaderProgram *menuProgram, Framebuf
|
||||
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
|
||||
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 currentWidgetDimensions = currentWidgetJson["dimensions"];
|
||||
std::string name = currentWidgetJson["unique_name"].asString();
|
||||
Texture *currentWidgetTexture = new Texture(currentWidgetTextureJson.asString().c_str(), textureType::texture_diffuse);
|
||||
Widget *currentWidget = new Widget(
|
||||
name,
|
||||
currentWidgetTexture,
|
||||
currentWidgetPosition[0].asFloat(),
|
||||
currentWidgetPosition[1].asFloat(),
|
||||
currentWidgetDimensions[0].asFloat(),
|
||||
currentWidgetDimensions[1].asFloat(),
|
||||
currentWidgetJson["callbackId"].asUInt()
|
||||
);
|
||||
Texture *currentWidgetTexture =
|
||||
new Texture(currentWidgetTextureJson.asString().c_str(), textureType::texture_diffuse);
|
||||
Widget *currentWidget =
|
||||
new Widget(name, currentWidgetTexture, currentWidgetPosition[0].asFloat(),
|
||||
currentWidgetPosition[1].asFloat(), currentWidgetDimensions[0].asFloat(),
|
||||
currentWidgetDimensions[1].asFloat(), currentWidgetJson["callbackId"].asUInt());
|
||||
temp_widgets.push_back(currentWidget);
|
||||
}
|
||||
return temp_widgets;
|
||||
@@ -280,7 +281,7 @@ std::vector<Widget*> JsonParser::getWidgetsFromScreen(const Json::Value &screenJ
|
||||
|
||||
Skybox *JsonParser::getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram)
|
||||
{
|
||||
Skybox* temp_skybox;
|
||||
Skybox *temp_skybox;
|
||||
|
||||
const Json::Value shaderProgramsJson = root["skybox"];
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "Model.h"
|
||||
#include "Entity.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Light.h"
|
||||
#include "Model.h"
|
||||
#include "Screen.h"
|
||||
#include "ShaderProgram.h"
|
||||
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include <string>
|
||||
@@ -13,19 +13,19 @@
|
||||
class JsonParser
|
||||
{
|
||||
public:
|
||||
JsonParser(const std::string& path);
|
||||
JsonParser(const std::string &path);
|
||||
~JsonParser();
|
||||
|
||||
std::vector<Model*> getModels();
|
||||
std::vector<Entity*> getEntities(std::vector<Model*> &models, std::vector<ShaderProgram*> shaderPrograms);
|
||||
std::vector<Light*> getLights(ShaderProgram *shaderProgram);
|
||||
std::vector<Screen*> getScreens(ShaderProgram *menuProgram, Framebuffer *framebuffer);
|
||||
std::vector<Model *> getModels();
|
||||
std::vector<Entity *> getEntities(std::vector<Model *> &models, std::vector<ShaderProgram *> shaderPrograms);
|
||||
std::vector<Light *> getLights(ShaderProgram *shaderProgram);
|
||||
std::vector<Screen *> getScreens(ShaderProgram *menuProgram, Framebuffer *framebuffer);
|
||||
Skybox *getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram);
|
||||
|
||||
std::vector<ShaderProgram*> getShaderPrograms();
|
||||
std::vector<ShaderProgram *> getShaderPrograms();
|
||||
|
||||
private:
|
||||
std::vector<Widget*> getWidgetsFromScreen(const Json::Value &screenJson);
|
||||
std::vector<Widget *> getWidgetsFromScreen(const Json::Value &screenJson);
|
||||
|
||||
private:
|
||||
Json::Value root;
|
||||
|
||||
@@ -6,21 +6,19 @@ uint32_t Light::id_counter = 0;
|
||||
|
||||
// Light
|
||||
|
||||
Light::Light(glm::vec3 color, float intensity, ShaderProgram* shaderProgram) :
|
||||
shaderProgram(shaderProgram),
|
||||
intensity(intensity)
|
||||
Light::Light(glm::vec3 color, float intensity, ShaderProgram *shaderProgram)
|
||||
: shaderProgram(shaderProgram), intensity(intensity)
|
||||
{
|
||||
id = id_counter++;
|
||||
lightColor = color * intensity;
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 Light::getColor()
|
||||
{
|
||||
return lightColor;
|
||||
}
|
||||
|
||||
void Light::setShaderProgram(ShaderProgram* shaderProgram)
|
||||
void Light::setShaderProgram(ShaderProgram *shaderProgram)
|
||||
{
|
||||
this->shaderProgram = shaderProgram;
|
||||
update();
|
||||
@@ -37,7 +35,6 @@ void Light::setIntensity(float intensity)
|
||||
this->intensity = intensity;
|
||||
}
|
||||
|
||||
|
||||
void Light::setActive(bool active)
|
||||
{
|
||||
isActive = active;
|
||||
@@ -46,9 +43,8 @@ void Light::setActive(bool active)
|
||||
|
||||
// PointLight
|
||||
|
||||
PointLight::PointLight(glm::vec3 position, glm::vec3 color, float intensity, ShaderProgram *shaderProgram) :
|
||||
Light(color, intensity, shaderProgram),
|
||||
position(position)
|
||||
PointLight::PointLight(glm::vec3 position, glm::vec3 color, float intensity, ShaderProgram *shaderProgram)
|
||||
: Light(color, intensity, shaderProgram), position(position)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
@@ -84,9 +80,8 @@ void PointLight::setPosition(glm::vec3 position)
|
||||
|
||||
// DirectionalLight
|
||||
|
||||
DirectionalLight::DirectionalLight(glm::vec3 direction, glm::vec3 color, float intensity, ShaderProgram *shaderProgram) :
|
||||
Light(color, intensity, shaderProgram),
|
||||
direction(direction)
|
||||
DirectionalLight::DirectionalLight(glm::vec3 direction, glm::vec3 color, float intensity, ShaderProgram *shaderProgram)
|
||||
: Light(color, intensity, shaderProgram), direction(direction)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
class Light
|
||||
{
|
||||
public:
|
||||
virtual ~Light() {}
|
||||
virtual ~Light()
|
||||
{}
|
||||
|
||||
virtual void update() = 0;
|
||||
|
||||
|
||||
31
src/Menu.cpp
31
src/Menu.cpp
@@ -1,12 +1,12 @@
|
||||
#include "Menu.h"
|
||||
#include "Helper.h"
|
||||
#include "JsonParser.h"
|
||||
#include "eventActions.h"
|
||||
#include "Helper.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Menu::Menu(Framebuffer *p_framebuffer, ShaderProgram *p_shaderProgram) :
|
||||
framebuffer(p_framebuffer), shaderProgram(p_shaderProgram)
|
||||
Menu::Menu(Framebuffer *p_framebuffer, ShaderProgram *p_shaderProgram)
|
||||
: framebuffer(p_framebuffer), shaderProgram(p_shaderProgram)
|
||||
{
|
||||
JsonParser screenParser("data/screens.json");
|
||||
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())
|
||||
return m_screen_name_cache[name];
|
||||
|
||||
for (auto it : screens) {
|
||||
if(it->getUniqueName() == name) {
|
||||
if (it->getUniqueName() == name) {
|
||||
m_screen_name_cache[name] = it;
|
||||
return it;
|
||||
}
|
||||
@@ -40,11 +40,12 @@ Screen *Menu::getActiveScreen() const
|
||||
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();
|
||||
activeScreen = screen;
|
||||
@@ -55,16 +56,16 @@ void Menu::resetActiveScreen()
|
||||
activeScreen = nullptr;
|
||||
}
|
||||
|
||||
void Menu::handleMouseButtonActionRegister(bool *mouseButtonActionRegister, Window* window)
|
||||
void Menu::handleMouseButtonActionRegister(bool *mouseButtonActionRegister, Window *window)
|
||||
{
|
||||
if (mouseButtonActionRegister[mouseButtonActions::leftClicked]) {
|
||||
auto widgets = activeScreen->getWidgets();
|
||||
for (auto it = widgets.begin(); it != widgets.end(); it++) {
|
||||
if ((*it)->isHovered(window)) {
|
||||
// std::cout << (*it)->getUniqueName() << " clicked!" << std::endl;
|
||||
if((*it)->getCallbackId() == 1)
|
||||
if ((*it)->getCallbackId() == 1)
|
||||
resetActiveScreen();
|
||||
if((*it)->getCallbackId() == 2)
|
||||
if ((*it)->getCallbackId() == 2)
|
||||
shouldExit = true;
|
||||
}
|
||||
}
|
||||
@@ -78,11 +79,7 @@ void Menu::writeWindowActions(bool *windowActionRegister)
|
||||
}
|
||||
|
||||
void Menu::onPlayPressed()
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
void Menu::onExitPressed()
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
12
src/Menu.h
12
src/Menu.h
@@ -3,9 +3,9 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Screen.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "JsonParser.h"
|
||||
#include "Screen.h"
|
||||
#include "eventActions.h"
|
||||
|
||||
class Menu
|
||||
@@ -14,15 +14,15 @@ public:
|
||||
Menu(Framebuffer *p_framebuffer, ShaderProgram *p_shaderProgram);
|
||||
~Menu();
|
||||
|
||||
Screen *getScreenByName(const std::string& name) const;
|
||||
void showScreenByName(const std::string& name);
|
||||
Screen *getScreenByName(const std::string &name) const;
|
||||
void showScreenByName(const std::string &name);
|
||||
|
||||
Screen *getActiveScreen() const;
|
||||
void writeWindowActions(bool *windowActionRegister);
|
||||
|
||||
void resetActiveScreen();
|
||||
|
||||
void handleMouseButtonActionRegister(bool *mouseButtonActionRegister, Window* window);
|
||||
void handleMouseButtonActionRegister(bool *mouseButtonActionRegister, Window *window);
|
||||
|
||||
void onPlayPressed();
|
||||
void onExitPressed();
|
||||
@@ -33,12 +33,12 @@ private:
|
||||
|
||||
bool shouldExit = false;
|
||||
|
||||
std::vector<Screen*> screens;
|
||||
std::vector<Screen *> screens;
|
||||
Screen *activeScreen;
|
||||
/*Screen *loadingScreen;
|
||||
Screen *mainMenuScreen;
|
||||
Screen *optionMenuScreen;
|
||||
Screen *pauseMenuScreen;*/
|
||||
|
||||
mutable std::unordered_map<std::string, Screen*> m_screen_name_cache;
|
||||
mutable std::unordered_map<std::string, Screen *> m_screen_name_cache;
|
||||
};
|
||||
|
||||
12
src/Mesh.cpp
12
src/Mesh.cpp
@@ -1,16 +1,16 @@
|
||||
#include "Mesh.h"
|
||||
|
||||
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<uint32_t> indices, std::vector<Texture *> textures) :
|
||||
numElements(indices.size()),
|
||||
textures(textures),
|
||||
vertexArray(static_cast<void *>(vertices.data()), static_cast<void *>(indices.data()), vertices.size(), indices.size())
|
||||
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<uint32_t> indices, std::vector<Texture *> textures)
|
||||
: numElements(indices.size()), textures(textures),
|
||||
vertexArray(static_cast<void *>(vertices.data()), static_cast<void *>(indices.data()), vertices.size(),
|
||||
indices.size())
|
||||
{
|
||||
// Empty...
|
||||
}
|
||||
|
||||
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);
|
||||
// Bind all textures in order to its texture unit
|
||||
for (auto it = textures.begin(); it != textures.end(); it++) {
|
||||
@@ -41,7 +41,7 @@ void Mesh::drawWithoutTextures()
|
||||
vertexArray.unbind();
|
||||
}
|
||||
|
||||
VertexArray* Mesh::getVertexArray()
|
||||
VertexArray *Mesh::getVertexArray()
|
||||
{
|
||||
return &vertexArray;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include "ShaderProgram.h"
|
||||
#include "VertexArray.h"
|
||||
#include "Texture.h"
|
||||
#include "VertexArray.h"
|
||||
#include "defines.h"
|
||||
|
||||
class Mesh
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#include "Model.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
uint32_t Model::id_counter = 0;
|
||||
|
||||
Model::Model(const std::string &modelName, const std::string &modelPath) :
|
||||
unique_name(modelName)
|
||||
Model::Model(const std::string &modelName, const std::string &modelPath) : unique_name(modelName)
|
||||
{
|
||||
directory = modelPath.substr(0, modelPath.find_last_of('/'));
|
||||
|
||||
@@ -58,12 +57,12 @@ void Model::loadModel(const std::string &pathToModel)
|
||||
}
|
||||
|
||||
uint32_t numTextures;
|
||||
input.read((char *) &numTextures, sizeof(uint32_t));
|
||||
input.read((char *)&numTextures, sizeof(uint32_t));
|
||||
|
||||
std::vector<uint32_t> textureTypes;
|
||||
for (unsigned int i = 0; i < numTextures; i++) {
|
||||
uint32_t currentTextureType;
|
||||
input.read((char *) ¤tTextureType, sizeof(uint32_t));
|
||||
input.read((char *)¤tTextureType, sizeof(uint32_t));
|
||||
textureTypes.push_back(currentTextureType);
|
||||
}
|
||||
|
||||
@@ -72,7 +71,7 @@ void Model::loadModel(const std::string &pathToModel)
|
||||
std::string currentTextureSource;
|
||||
for (unsigned int i = 0; i < 128; i++) {
|
||||
uint8_t currentChar;
|
||||
input.read((char *) ¤tChar, sizeof(uint8_t));
|
||||
input.read((char *)¤tChar, sizeof(uint8_t));
|
||||
|
||||
if (currentChar) {
|
||||
currentTextureSource.push_back(currentChar);
|
||||
@@ -81,7 +80,6 @@ void Model::loadModel(const std::string &pathToModel)
|
||||
textureSources.push_back(currentTextureSource);
|
||||
}
|
||||
|
||||
|
||||
for (unsigned int i = 0; i < numTextures; i++) {
|
||||
TexturePrototype texture_prototype;
|
||||
std::string texturePath = directory + '/' + textureSources[i].c_str();
|
||||
@@ -110,7 +108,7 @@ void Model::loadModel(const std::string &pathToModel)
|
||||
|
||||
// Here starts the first mesh
|
||||
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++) {
|
||||
|
||||
@@ -118,9 +116,9 @@ void Model::loadModel(const std::string &pathToModel)
|
||||
|
||||
uint32_t numMeshVertices, numMeshIndices, numMeshTextureIds;
|
||||
|
||||
input.read((char *) &numMeshVertices, sizeof(uint32_t));
|
||||
input.read((char *) &numMeshIndices, sizeof(uint32_t));
|
||||
input.read((char *) &numMeshTextureIds, sizeof(uint32_t));
|
||||
input.read((char *)&numMeshVertices, sizeof(uint32_t));
|
||||
input.read((char *)&numMeshIndices, sizeof(uint32_t));
|
||||
input.read((char *)&numMeshTextureIds, sizeof(uint32_t));
|
||||
|
||||
uint32_t vertexBlockSize = numMeshVertices * sizeof(Vertex);
|
||||
uint32_t indexBlockSize = numMeshIndices * sizeof(uint32_t);
|
||||
@@ -129,17 +127,17 @@ void Model::loadModel(const std::string &pathToModel)
|
||||
|
||||
std::vector<Vertex> meshVertices;
|
||||
meshVertices.resize(numMeshVertices);
|
||||
input.read((char *) meshVertices.data(), vertexBlockSize);
|
||||
input.read((char *)meshVertices.data(), vertexBlockSize);
|
||||
mesh_prototype.meshVertices = std::move(meshVertices);
|
||||
|
||||
std::vector<uint32_t> meshIndices;
|
||||
meshIndices.resize(numMeshIndices);
|
||||
input.read((char *) meshIndices.data(), indexBlockSize);
|
||||
input.read((char *)meshIndices.data(), indexBlockSize);
|
||||
mesh_prototype.meshIndices = std::move(meshIndices);
|
||||
|
||||
for (unsigned int i = 0; i < numMeshTextureIds; i++) {
|
||||
uint32_t currentTextureId;
|
||||
input.read((char *) ¤tTextureId, sizeof(uint32_t));
|
||||
input.read((char *)¤tTextureId, sizeof(uint32_t));
|
||||
mesh_prototype.textureIds.push_back(currentTextureId);
|
||||
}
|
||||
|
||||
@@ -159,13 +157,13 @@ void Model::prepareModel()
|
||||
model_prepared = true;
|
||||
|
||||
// Create textures on GPU
|
||||
for (auto& it : modelTexturePrototypes) {
|
||||
for (auto &it : modelTexturePrototypes) {
|
||||
Texture *newTex = new Texture(it.texturePath.c_str(), it.textureType);
|
||||
loadedTextures.push_back(newTex);
|
||||
}
|
||||
|
||||
// Create meshes on GPU
|
||||
for (const auto& it : modelMeshPrototypes) {
|
||||
for (const auto &it : modelMeshPrototypes) {
|
||||
std::vector<Texture *> meshTextures;
|
||||
for (const auto it2 : it.textureIds) {
|
||||
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];
|
||||
}
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
|
||||
#include "Mesh.h"
|
||||
|
||||
struct TexturePrototype {
|
||||
struct TexturePrototype
|
||||
{
|
||||
uint32_t textureType;
|
||||
std::string texturePath;
|
||||
};
|
||||
|
||||
struct MeshPrototype {
|
||||
struct MeshPrototype
|
||||
{
|
||||
std::vector<uint32_t> textureIds;
|
||||
std::vector<Vertex> meshVertices;
|
||||
std::vector<uint32_t> meshIndices;
|
||||
@@ -19,7 +21,7 @@ struct MeshPrototype {
|
||||
class Model
|
||||
{
|
||||
public:
|
||||
Model(const std::string& modelName, const std::string& pathToModel);
|
||||
Model(const std::string &modelName, const std::string &pathToModel);
|
||||
~Model();
|
||||
|
||||
void prepareModel();
|
||||
@@ -47,5 +49,4 @@ private:
|
||||
static uint32_t id_counter;
|
||||
uint32_t id;
|
||||
std::string unique_name;
|
||||
|
||||
};
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
uint32_t Screen::id_counter = 0;
|
||||
|
||||
Screen::Screen(const std::string &name, std::vector<Widget*> widgets, Framebuffer *framebuffer, ShaderProgram *shaderProgram) :
|
||||
unique_name(name),
|
||||
framebuffer(framebuffer),
|
||||
shaderProgram(shaderProgram),
|
||||
widgets(widgets)
|
||||
Screen::Screen(const std::string &name, std::vector<Widget *> widgets, Framebuffer *framebuffer,
|
||||
ShaderProgram *shaderProgram)
|
||||
: unique_name(name), framebuffer(framebuffer), shaderProgram(shaderProgram), widgets(widgets)
|
||||
{
|
||||
id = id_counter++;
|
||||
}
|
||||
@@ -15,31 +13,31 @@ Screen::Screen(const std::string &name, std::vector<Widget*> widgets, Framebuffe
|
||||
Screen::~Screen()
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
for(auto it = textures.begin(); it != textures.end(); it++) {
|
||||
for (auto it = textures.begin(); it != textures.end(); it++) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& Screen::getUniqueName() const
|
||||
const std::string &Screen::getUniqueName() const
|
||||
{
|
||||
return unique_name;
|
||||
}
|
||||
|
||||
std::vector<Widget*> Screen::getWidgets() const
|
||||
std::vector<Widget *> Screen::getWidgets() const
|
||||
{
|
||||
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())
|
||||
return m_widget_name_cache[name];
|
||||
|
||||
for (auto it : widgets) {
|
||||
if(it->getUniqueName() == name) {
|
||||
if (it->getUniqueName() == name) {
|
||||
m_widget_name_cache[name] = it;
|
||||
return it;
|
||||
}
|
||||
@@ -56,8 +54,8 @@ void Screen::draw() const
|
||||
{
|
||||
framebuffer->setExposureCorrection(false);
|
||||
framebuffer->bind();
|
||||
|
||||
for(auto it = widgets.begin(); it != widgets.end(); it++) {
|
||||
|
||||
for (auto it = widgets.begin(); it != widgets.end(); it++) {
|
||||
(*it)->draw(shaderProgram);
|
||||
}
|
||||
|
||||
@@ -65,4 +63,3 @@ void Screen::draw() const
|
||||
framebuffer->render();
|
||||
framebuffer->setExposureCorrection(true);
|
||||
}
|
||||
|
||||
|
||||
23
src/Screen.h
23
src/Screen.h
@@ -2,8 +2,8 @@
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "ShaderProgram.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Widget.h"
|
||||
|
||||
class Menu;
|
||||
@@ -11,16 +11,17 @@ class Menu;
|
||||
class Screen
|
||||
{
|
||||
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();
|
||||
|
||||
|
||||
void addWidget(Widget *widget);
|
||||
void draw() const;
|
||||
|
||||
const std::string& getUniqueName() const;
|
||||
std::vector<Widget*> getWidgets() const;
|
||||
Widget *getWidgetByName(const std::string& name) const;
|
||||
|
||||
const std::string &getUniqueName() const;
|
||||
std::vector<Widget *> getWidgets() const;
|
||||
Widget *getWidgetByName(const std::string &name) const;
|
||||
|
||||
private:
|
||||
uint32_t id;
|
||||
static uint32_t id_counter;
|
||||
@@ -28,9 +29,9 @@ private:
|
||||
|
||||
Framebuffer *framebuffer;
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "ShaderProgram.h"
|
||||
|
||||
ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath, const std::string &fragmentShaderPath) :
|
||||
unique_name(name)
|
||||
ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath,
|
||||
const std::string &fragmentShaderPath)
|
||||
: unique_name(name)
|
||||
{
|
||||
std::string vertexShaderSource = parse(vertexShaderPath.c_str());
|
||||
std::string fragmentShaderSource = parse(fragmentShaderPath.c_str());
|
||||
@@ -36,8 +37,9 @@ ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexS
|
||||
#endif
|
||||
}
|
||||
|
||||
ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath, const std::string &geometryShaderPath, const std::string &fragmentShaderPath) :
|
||||
unique_name(name)
|
||||
ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath,
|
||||
const std::string &geometryShaderPath, const std::string &fragmentShaderPath)
|
||||
: unique_name(name)
|
||||
{
|
||||
std::string vertexShaderSource = parse(vertexShaderPath.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;
|
||||
glGetProgramiv(shaderProgramId, GL_LINK_STATUS, &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
|
||||
@@ -86,7 +89,7 @@ void ShaderProgram::unbind()
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
std::string ShaderProgram::parse(const std::string& filename)
|
||||
std::string ShaderProgram::parse(const std::string &filename)
|
||||
{
|
||||
std::fstream shaderfile;
|
||||
shaderfile.open(filename, std::ios::in);
|
||||
@@ -101,7 +104,7 @@ std::string ShaderProgram::parse(const std::string& filename)
|
||||
return contents;
|
||||
}
|
||||
|
||||
GLuint ShaderProgram::compile(const std::string& shaderSource, GLenum type)
|
||||
GLuint ShaderProgram::compile(const std::string &shaderSource, GLenum type)
|
||||
{
|
||||
GLuint shaderId = glCreateShader(type);
|
||||
const char *src = shaderSource.c_str();
|
||||
@@ -122,7 +125,8 @@ GLuint ShaderProgram::compile(const std::string& shaderSource, GLenum type)
|
||||
return shaderId;
|
||||
}
|
||||
|
||||
GLint ShaderProgram::retrieveUniformLocation(const std::string& name) const {
|
||||
GLint ShaderProgram::retrieveUniformLocation(const std::string &name) const
|
||||
{
|
||||
if (uniformLocationCache.find(name) != uniformLocationCache.end())
|
||||
return uniformLocationCache[name];
|
||||
|
||||
@@ -132,37 +136,37 @@ GLint ShaderProgram::retrieveUniformLocation(const std::string& name) const {
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
|
||||
@@ -2,35 +2,36 @@
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class ShaderProgram
|
||||
{
|
||||
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 &geometryShaderPath, const std::string &fragmentShaderPath);
|
||||
ShaderProgram(const std::string &name, const std::string &vertexShaderPath, const std::string &geometryShaderPath,
|
||||
const std::string &fragmentShaderPath);
|
||||
~ShaderProgram();
|
||||
|
||||
void bind();
|
||||
void unbind();
|
||||
|
||||
GLint retrieveUniformLocation(const std::string& name) const;
|
||||
GLint retrieveUniformLocation(const std::string &name) const;
|
||||
// May be rewritten...
|
||||
void setUniform(const std::string& name, bool 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, glm::vec3 vector) 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, bool 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, glm::vec3 vector) const;
|
||||
void setUniform(const std::string &name, glm::mat3 matrix) const;
|
||||
void setUniform(const std::string &name, glm::mat4 matrix) const;
|
||||
|
||||
public:
|
||||
GLuint getShaderProgramId();
|
||||
std::string getUniqueName();
|
||||
|
||||
private:
|
||||
std::string parse(const std::string& filename);
|
||||
GLuint compile(const std::string& shaderSource, GLenum type);
|
||||
std::string parse(const std::string &filename);
|
||||
GLuint compile(const std::string &shaderSource, GLenum type);
|
||||
|
||||
private:
|
||||
GLuint shaderProgramId;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "Texture.h"
|
||||
|
||||
#include <stb/stb_image.h>
|
||||
#include <iostream>
|
||||
#include <stb/stb_image.h>
|
||||
|
||||
Texture::Texture(const std::string& texturePath, uint8_t textureType) :
|
||||
texturePath(texturePath), textureType(textureType)
|
||||
Texture::Texture(const std::string &texturePath, uint8_t textureType)
|
||||
: texturePath(texturePath), textureType(textureType)
|
||||
{
|
||||
stbi_set_flip_vertically_on_load(1);
|
||||
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_T, GL_REPEAT);
|
||||
|
||||
|
||||
if (!textureBuffer) {
|
||||
std::cout << "[Warning] Texture " << texturePath << " not found!" << std::endl;
|
||||
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);
|
||||
|
||||
stbi_image_free(textureBuffer);
|
||||
@@ -124,36 +124,34 @@ CubeMap::CubeMap(const char *texturePseudoPath)
|
||||
int32_t numComponents;
|
||||
auto *textureBuffer = stbi_load(texturePaths[i].c_str(), &textureWidth, &textureHeight, &numComponents, 0);
|
||||
|
||||
GLenum internalFormat;
|
||||
GLenum dataFormat;
|
||||
if (numComponents == 1) {
|
||||
internalFormat = GL_RED;
|
||||
dataFormat = GL_RED;
|
||||
} else if (numComponents == 3) {
|
||||
internalFormat = GL_SRGB8;
|
||||
dataFormat = GL_RGB;
|
||||
} else if (numComponents == 4) {
|
||||
internalFormat = GL_SRGB8_ALPHA8;
|
||||
dataFormat = GL_RGBA;
|
||||
}
|
||||
GLenum internalFormat;
|
||||
GLenum dataFormat;
|
||||
if (numComponents == 1) {
|
||||
internalFormat = GL_RED;
|
||||
dataFormat = GL_RED;
|
||||
} else if (numComponents == 3) {
|
||||
internalFormat = GL_SRGB8;
|
||||
dataFormat = GL_RGB;
|
||||
} else if (numComponents == 4) {
|
||||
internalFormat = GL_SRGB8_ALPHA8;
|
||||
dataFormat = GL_RGBA;
|
||||
}
|
||||
|
||||
if (!textureBuffer) {
|
||||
std::cout << "[Warning] CubeMap Texture " << texturePaths[i].c_str() << " not found!" << std::endl;
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
}
|
||||
|
||||
CubeMap::CubeMap(int RESOLUTION) :
|
||||
textureWidth(RESOLUTION),
|
||||
textureHeight(RESOLUTION)
|
||||
CubeMap::CubeMap(int RESOLUTION) : textureWidth(RESOLUTION), textureHeight(RESOLUTION)
|
||||
{
|
||||
|
||||
glGenTextures(1, &textureId);
|
||||
@@ -167,7 +165,8 @@ CubeMap::CubeMap(int RESOLUTION) :
|
||||
|
||||
const unsigned int CUBEMAP_NUM_FACES = 6;
|
||||
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);
|
||||
@@ -195,12 +194,12 @@ void CubeMap::unbind()
|
||||
void CubeMap::fillTexturePathVector(const char *texturePseudoPath)
|
||||
{
|
||||
for (unsigned int i = 0; i < CUBEMAP_FACES_NUM_ITEMS; i++) {
|
||||
texturePaths[cm_front] = std::string(texturePseudoPath) + "front.png";
|
||||
texturePaths[cm_back] = std::string(texturePseudoPath) + "back.png";
|
||||
texturePaths[cm_top] = std::string(texturePseudoPath) + "top.png";
|
||||
texturePaths[cm_front] = std::string(texturePseudoPath) + "front.png";
|
||||
texturePaths[cm_back] = std::string(texturePseudoPath) + "back.png";
|
||||
texturePaths[cm_top] = std::string(texturePseudoPath) + "top.png";
|
||||
texturePaths[cm_bottom] = std::string(texturePseudoPath) + "bottom.png";
|
||||
texturePaths[cm_left] = std::string(texturePseudoPath) + "left.png";
|
||||
texturePaths[cm_right] = std::string(texturePseudoPath) + "right.png";
|
||||
texturePaths[cm_left] = std::string(texturePseudoPath) + "left.png";
|
||||
texturePaths[cm_right] = std::string(texturePseudoPath) + "right.png";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,21 @@
|
||||
#include <vector>
|
||||
|
||||
// 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
|
||||
{
|
||||
public:
|
||||
Texture(const std::string& texturePath, uint8_t textureType);
|
||||
Texture(const std::string &texturePath, uint8_t textureType);
|
||||
~Texture();
|
||||
|
||||
void bind(uint8_t textureUnit, ShaderProgram *shaderProgram, uint8_t textureTypeNum);
|
||||
|
||||
@@ -19,23 +19,23 @@ VertexArray::VertexArray(void *vertexData, void *indexData, uint32_t numVertices
|
||||
|
||||
// Position
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
glBindVertexArray(0);
|
||||
@@ -56,18 +56,19 @@ void VertexArray::unbind()
|
||||
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;
|
||||
uint32_t i = 0;
|
||||
uint32_t k = 0;
|
||||
for(; i < numVertices; i+=3) {
|
||||
for (; i < numVertices; i += 3) {
|
||||
Vertex currentVertex = {};
|
||||
currentVertex.position.x = vertices[i];
|
||||
currentVertex.position.y = vertices[i+1];
|
||||
currentVertex.position.z = vertices[i+2];
|
||||
currentVertex.position.y = vertices[i + 1];
|
||||
currentVertex.position.z = vertices[i + 2];
|
||||
currentVertex.textureCoords.x = textureCoordinates[k];
|
||||
currentVertex.textureCoords.y = textureCoordinates[k+1];
|
||||
k+=2;
|
||||
currentVertex.textureCoords.y = textureCoordinates[k + 1];
|
||||
k += 2;
|
||||
vertexVec.push_back(currentVertex);
|
||||
}
|
||||
return vertexVec;
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
|
||||
void bind();
|
||||
void unbind();
|
||||
|
||||
|
||||
static std::vector<Vertex> createVertices(double *vertices, uint32_t numVertices, float *textureCoordinates);
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,36 +1,23 @@
|
||||
#include "Widget.h"
|
||||
#include "VertexArray.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) :
|
||||
x(p_x),
|
||||
y(p_y),
|
||||
w(p_w),
|
||||
h(p_h),
|
||||
unique_name(name),
|
||||
callbackId(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), y(p_y), w(p_w), h(p_h), unique_name(name), callbackId(callbackId)
|
||||
{
|
||||
widgetTextures.push_back(texture);
|
||||
|
||||
|
||||
double widgetVerticesData[12] = {
|
||||
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) - 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)-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)-1.0f, 0.0f, // Bottom left
|
||||
2 * (x + w) - 1.0f, 2 * (y + h) - 1.0f, 0.0f // Top right
|
||||
};
|
||||
|
||||
unsigned int widgetIndicesData[6] = {
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
unsigned int widgetIndicesData[6] = {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};
|
||||
|
||||
widgetVertices = VertexArray::createVertices(widgetVerticesData, 12, widgetTextureCoordinates);
|
||||
widgetIndices.assign(widgetIndicesData, widgetIndicesData + 6);
|
||||
widgetMesh = new Mesh(widgetVertices, widgetIndices, widgetTextures);
|
||||
@@ -69,7 +56,7 @@ bool Widget::isHovered(Window *window)
|
||||
double yrel = -ypos / height + 1;
|
||||
|
||||
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;
|
||||
|
||||
return isHovered;
|
||||
|
||||
12
src/Widget.h
12
src/Widget.h
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "Texture.h"
|
||||
#include "Mesh.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "Mesh.h"
|
||||
#include "Texture.h"
|
||||
#include "Window.h"
|
||||
#include "eventActions.h"
|
||||
|
||||
@@ -13,7 +13,7 @@ class Widget
|
||||
public:
|
||||
Widget(std::string &name, Texture *texture, float x, float y, float w, float h, uint16_t callbackId);
|
||||
~Widget();
|
||||
|
||||
|
||||
void draw(ShaderProgram *shaderProgram);
|
||||
|
||||
std::string getUniqueName();
|
||||
@@ -27,10 +27,10 @@ private:
|
||||
std::string unique_name;
|
||||
|
||||
uint16_t callbackId;
|
||||
|
||||
|
||||
std::vector<Vertex> widgetVertices;
|
||||
std::vector<uint32_t> widgetIndices;
|
||||
std::vector<Texture*> widgetTextures;
|
||||
|
||||
std::vector<Texture *> widgetTextures;
|
||||
|
||||
Mesh *widgetMesh;
|
||||
};
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <iostream>
|
||||
#include <glad/glad.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "Window.h"
|
||||
#include "eventActions.h"
|
||||
#include "defines.h"
|
||||
#include "Helper.h"
|
||||
#include "Window.h"
|
||||
#include "defines.h"
|
||||
#include "eventActions.h"
|
||||
|
||||
Window::Window()
|
||||
{
|
||||
@@ -76,7 +76,7 @@ Window::Window()
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
// Tell GLFW which function to call when window is resized
|
||||
//glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
// glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
@@ -102,7 +102,6 @@ void Window::updateWindowDimensions()
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
|
||||
void Window::setCatchedCursor(bool value)
|
||||
{
|
||||
if (value) {
|
||||
@@ -148,7 +147,7 @@ void Window::framebuffer_size_callback(GLFWwindow *window, int width, int height
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
GLFWwindow* Window::getGLFWwindow()
|
||||
GLFWwindow *Window::getGLFWwindow()
|
||||
{
|
||||
return window;
|
||||
}
|
||||
@@ -165,7 +164,7 @@ int Window::getWindowHeight()
|
||||
|
||||
float Window::getWindowAspectRatio()
|
||||
{
|
||||
return (float) width / (float) height;
|
||||
return (float)width / (float)height;
|
||||
}
|
||||
|
||||
bool Window::getMouseIsCatched()
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "World.h"
|
||||
#include "JsonParser.h"
|
||||
#include "Controller.h"
|
||||
#include "JsonParser.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
World::World(std::vector<ShaderProgram*> shaderPrograms) :
|
||||
shaderProgram(Controller::getShaderProgramByName(shaderPrograms, "defaultProgram")),
|
||||
depthMapDirectionalFBO(DEPTHMAP_NORMAL, SHADOW_RES)
|
||||
World::World(std::vector<ShaderProgram *> shaderPrograms)
|
||||
: shaderProgram(Controller::getShaderProgramByName(shaderPrograms, "defaultProgram")),
|
||||
depthMapDirectionalFBO(DEPTHMAP_NORMAL, SHADOW_RES)
|
||||
{
|
||||
// Create 4 depthMaps
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@@ -22,12 +22,13 @@ World::World(std::vector<ShaderProgram*> shaderPrograms) :
|
||||
JsonParser modelParser("data/models.json");
|
||||
models = modelParser.getModels();
|
||||
|
||||
for (const auto& it : models) {
|
||||
for (const auto &it : models) {
|
||||
it->prepareModel();
|
||||
}
|
||||
|
||||
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");
|
||||
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)
|
||||
{
|
||||
std::vector<PointLight*> pointLights = getPointLights();
|
||||
std::vector<PointLight *> pointLights = getPointLights();
|
||||
pointLights[lightId]->setActive(active);
|
||||
pointLights[lightId]->setPosition(position);
|
||||
pointLights[lightId]->setIntensity(intensity);
|
||||
@@ -117,7 +118,8 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// --- 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;
|
||||
|
||||
// Draw scene from light perspective
|
||||
@@ -142,7 +144,7 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
|
||||
shaderProgram->unbind();
|
||||
|
||||
// --- Point shadows ---
|
||||
std::vector<PointLight*> pointLights = getPointLights();
|
||||
std::vector<PointLight *> pointLights = getPointLights();
|
||||
|
||||
// 4 depthMaps for 4 point lights
|
||||
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
|
||||
std::vector<glm::mat4> viewProjMatrices;
|
||||
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), 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(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)));
|
||||
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),
|
||||
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(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();
|
||||
|
||||
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);
|
||||
@@ -194,10 +203,10 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
|
||||
glCullFace(GL_FRONT);
|
||||
}
|
||||
|
||||
Model* World::getModelByName(std::string name)
|
||||
Model *World::getModelByName(std::string name)
|
||||
{
|
||||
for (auto it = models.begin(); it != models.end(); it++) {
|
||||
if((*it)->getUniqueName() == name) {
|
||||
if ((*it)->getUniqueName() == name) {
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
@@ -205,10 +214,10 @@ Model* World::getModelByName(std::string name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Entity* World::getEntityByName(std::string name)
|
||||
Entity *World::getEntityByName(std::string name)
|
||||
{
|
||||
for (auto it = entities.begin(); it != entities.end(); it++) {
|
||||
if((*it)->getUniqueName() == name) {
|
||||
if ((*it)->getUniqueName() == name) {
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
@@ -216,10 +225,10 @@ Entity* World::getEntityByName(std::string name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Entity* World::getEntityById(uint32_t id)
|
||||
Entity *World::getEntityById(uint32_t id)
|
||||
{
|
||||
for (auto it = entities.begin(); it != entities.end(); it++) {
|
||||
if((*it)->getId() == id) {
|
||||
if ((*it)->getId() == id) {
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
@@ -227,12 +236,12 @@ Entity* World::getEntityById(uint32_t id)
|
||||
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++) {
|
||||
PointLight *temp_pointLight = dynamic_cast<PointLight*>(*it);
|
||||
PointLight *temp_pointLight = dynamic_cast<PointLight *>(*it);
|
||||
if (temp_pointLight) {
|
||||
temp_pointLights.push_back(temp_pointLight);
|
||||
}
|
||||
@@ -241,25 +250,25 @@ std::vector<PointLight*> World::getPointLights()
|
||||
return temp_pointLights;
|
||||
}
|
||||
|
||||
DirectionalLight * World::getDirectionalLight()
|
||||
DirectionalLight *World::getDirectionalLight()
|
||||
{
|
||||
DirectionalLight *temp_directionalLight = nullptr;
|
||||
|
||||
for (auto it = lights.begin(); it != lights.end(); it++) {
|
||||
temp_directionalLight = dynamic_cast<DirectionalLight*>(*it);
|
||||
if(temp_directionalLight)
|
||||
temp_directionalLight = dynamic_cast<DirectionalLight *>(*it);
|
||||
if (temp_directionalLight)
|
||||
break;
|
||||
}
|
||||
|
||||
return temp_directionalLight;
|
||||
}
|
||||
|
||||
std::vector<Entity*> World::getEntities()
|
||||
std::vector<Entity *> World::getEntities()
|
||||
{
|
||||
return entities;
|
||||
}
|
||||
|
||||
Skybox* World::getSkybox()
|
||||
Skybox *World::getSkybox()
|
||||
{
|
||||
return skybox;
|
||||
}
|
||||
|
||||
30
src/World.h
30
src/World.h
@@ -2,16 +2,16 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Light.h"
|
||||
#include "Camera.h"
|
||||
#include "Entity.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "Light.h"
|
||||
#include "ShaderProgram.h"
|
||||
|
||||
class World
|
||||
{
|
||||
public:
|
||||
World(std::vector<ShaderProgram*> shaderPrograms);
|
||||
World(std::vector<ShaderProgram *> shaderPrograms);
|
||||
~World();
|
||||
|
||||
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 updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color);
|
||||
|
||||
std::vector<Entity*> getEntities();
|
||||
std::vector<PointLight*> getPointLights();
|
||||
DirectionalLight * getDirectionalLight();
|
||||
std::vector<Entity *> getEntities();
|
||||
std::vector<PointLight *> getPointLights();
|
||||
DirectionalLight *getDirectionalLight();
|
||||
Skybox *getSkybox();
|
||||
Entity* getEntityByName(std::string name);
|
||||
Entity* getEntityById(uint32_t id);
|
||||
Model* getModelByName(std::string name);
|
||||
Entity *getEntityByName(std::string name);
|
||||
Entity *getEntityById(uint32_t id);
|
||||
Model *getModelByName(std::string name);
|
||||
|
||||
void draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition);
|
||||
void calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProgram *pointShaderProgram);
|
||||
@@ -35,12 +35,12 @@ public:
|
||||
private:
|
||||
ShaderProgram *shaderProgram;
|
||||
|
||||
std::vector<Model*> models;
|
||||
std::vector<Entity*> entities;
|
||||
std::vector<Model *> models;
|
||||
std::vector<Entity *> entities;
|
||||
Skybox *skybox;
|
||||
|
||||
// Lights
|
||||
std::vector<Light*> lights;
|
||||
std::vector<Light *> lights;
|
||||
|
||||
// Shadows
|
||||
const int SHADOW_RES = 4096 / 4;
|
||||
@@ -49,9 +49,11 @@ private:
|
||||
// Shadow projection matrices
|
||||
const float near_plane_directional = 1.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 near_plane_point = 1.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);
|
||||
};
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
#define INIT_WINDOW_WIDTH 1280
|
||||
#define INIT_WINDOW_HEIGHT 720
|
||||
|
||||
enum textureType {
|
||||
enum textureType
|
||||
{
|
||||
texture_diffuse,
|
||||
texture_specular,
|
||||
texture_normal,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
enum cameraActions {
|
||||
enum cameraActions
|
||||
{
|
||||
cameraUp,
|
||||
cameraDown,
|
||||
cameraForward,
|
||||
@@ -10,20 +11,23 @@ enum cameraActions {
|
||||
CAMERA_ACTION_NUM_ITEMS
|
||||
};
|
||||
|
||||
enum cameraMouseActions {
|
||||
enum cameraMouseActions
|
||||
{
|
||||
cameraMouseDeltaX,
|
||||
cameraMouseDeltaY,
|
||||
CAMERA_MOUSE_ACTION_NUM_ITEMS
|
||||
};
|
||||
|
||||
enum windowActions {
|
||||
enum windowActions
|
||||
{
|
||||
wireFrameToggle,
|
||||
mouseCatchToggle,
|
||||
windowShouldClose,
|
||||
WINDOW_ACTION_NUM_ITEMS
|
||||
};
|
||||
|
||||
enum mouseButtonActions {
|
||||
enum mouseButtonActions
|
||||
{
|
||||
leftClicked,
|
||||
rightClicked,
|
||||
middleClicked,
|
||||
|
||||
10
src/main.cpp
10
src/main.cpp
@@ -1,6 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/glad.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "Controller.h"
|
||||
|
||||
@@ -17,13 +17,13 @@ int main(int argc, char **argv)
|
||||
// Create controller
|
||||
Controller *mainController = new Controller();
|
||||
|
||||
const char* fps_env = std::getenv("MAXFPS");
|
||||
if(fps_env) {
|
||||
const char *fps_env = std::getenv("MAXFPS");
|
||||
if (fps_env) {
|
||||
uint16_t maxfps = std::stoul(fps_env);
|
||||
mainController->setMaxFps(maxfps);
|
||||
std::cout << "[Warning] Default max FPS overridden with " << maxfps << " by environment." << std::endl;
|
||||
}
|
||||
|
||||
|
||||
mainController->run();
|
||||
|
||||
delete mainController;
|
||||
|
||||
Reference in New Issue
Block a user