diff --git a/CMakeLists.txt b/CMakeLists.txt index e6423e5..52ae40f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ set(OpenGL_GL_PREFERENCE "GLVND") find_package(GLFW3 REQUIRED) find_package(OpenGL REQUIRED) +find_package(Freetype REQUIRED) # Specify the C++ standard set(CMAKE_CXX_STANDARD 11) diff --git a/imgui.ini b/imgui.ini index d71e993..4aefd70 100644 --- a/imgui.ini +++ b/imgui.ini @@ -9,7 +9,7 @@ Size=894,195 Collapsed=0 [Window][Debug Utils] -Pos=13,7 +Pos=10,7 Size=871,365 Collapsed=0 diff --git a/res/shaders/postprocessing.frag b/res/shaders/postprocessing.frag index 82fbdb7..aa1d6ea 100644 --- a/res/shaders/postprocessing.frag +++ b/res/shaders/postprocessing.frag @@ -7,6 +7,7 @@ layout(location = 0) out vec4 f_color; in vec2 v_tex_coords; uniform float u_exposure; +uniform bool u_exposureCorrection; uniform sampler2D u_texture; @@ -15,7 +16,8 @@ void main() { vec3 fragmentColor = vec3(texture2D(u_texture, v_tex_coords)); // Exposure tone mapping - fragmentColor = vec3(1.0) - exp(-fragmentColor * u_exposure); + if(u_exposureCorrection) + fragmentColor = vec3(1.0) - exp(-fragmentColor * u_exposure); // Gamma correction fragmentColor = pow(fragmentColor, vec3(1.0/GAMMA)); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a66d9bf..09cf9db 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,6 +13,8 @@ add_executable(Fall-Fever Light.cpp World.cpp Framebuffer.cpp + Widget.cpp + Screen.cpp ) target_link_libraries( @@ -22,6 +24,7 @@ target_link_libraries( stb ${GLFW3_LIBRARY} ${OPENGL_LIBRARIES} + ${FREETYPE_LIBRARIES} imgui ) diff --git a/src/Controller.cpp b/src/Controller.cpp index 2133571..1f79972 100644 --- a/src/Controller.cpp +++ b/src/Controller.cpp @@ -25,6 +25,8 @@ #include "Model.h" #include "Entity.h" #include "World.h" +#include "Widget.h" +#include "Screen.h" Controller::Controller() { @@ -95,32 +97,21 @@ void Controller::run() // Show loading screen... glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Texture loadingScreenTex("res/textures/loading.png", textureType::texture_diffuse); - std::vector loadingScreenVertices = VertexArray::createVertices(loadingScreenVerticesData, 12, loadingScreenTextureCoordinates); - std::vector loadingScreenIndices; - std::vector loadingScreenTextures; - loadingScreenTextures.push_back(&loadingScreenTex); - loadingScreenIndices.assign(loadingScreenIndicesData, loadingScreenIndicesData + 6); - Mesh loadingScreenMesh(loadingScreenVertices, loadingScreenIndices, loadingScreenTextures); - pp_framebuffer->bind(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - menuProgram.bind(); - loadingScreenMesh.draw(&menuProgram); - menuProgram.unbind(); - pp_framebuffer->unbind(); - pp_framebuffer->render(); + Widget loadingScreenWidget(&loadingScreenTex, 0.f, 0.f, 1.f, 1.f); + Screen loadingScreen(pp_framebuffer, &menuProgram); + loadingScreen.addWidget(&loadingScreenWidget); + loadingScreen.draw(); glfwSwapBuffers(gameWindow->getGLFWwindow()); - //Model model_backpack("res/models/backpack.ffo"); + Model model_backpack("res/models/backpack.ffo"); Model model_cube("res/models/cube.ffo"); - Model model_dragon("res/models/dragon.ffo"); + //Model model_dragon("res/models/dragon.ffo"); Model model_ground("res/models/wood_floor.ffo"); - Entity dragon(&model_dragon, &shaderProgram); + Entity backpack(&model_backpack, &shaderProgram); Entity ground(&model_ground, &shaderProgram); Entity lightSource(&model_cube, &lightProgram); - dragon.setRotation(glm::vec3(0.0f)); - dragon.setScale(0.2f); lightSource.setScale(0.1f); lightSource.setRotation(glm::vec3(0.f)); lightSource.setPosition(glm::vec3(-2.f, 1.5f, 2.f)); @@ -129,7 +120,7 @@ void Controller::run() Skybox skybox(&model_cube, &skyboxProgram, "res/textures/skybox/"); World world(&shaderProgram); - world.addEntity(dragon); + world.addEntity(backpack); world.addEntity(lightSource); world.addEntity(ground); @@ -269,9 +260,9 @@ void Controller::renderImGui(std::vector *entites, PointLight *pointLigh ImGui::Text("Object"); static float rotation = 0.0; ImGui::SliderFloat("Rotation", &rotation, 0, 2 * M_PI); - static float translation[] = {0.0f, 0.0f, 0.0f}; + static float translation[] = {0.0f, 1.0f, 0.0f}; ImGui::SliderFloat3("Position", translation, -4.0, 4.0); - static float scale = 0.2f; + static float scale = 0.6f; ImGui::SliderFloat("Scale", &scale, 0.02, 2.0); ImGui::Checkbox("Rotate Object", rotateEntity); diff --git a/src/Controller.h b/src/Controller.h index c34ed6a..c99673b 100644 --- a/src/Controller.h +++ b/src/Controller.h @@ -42,21 +42,4 @@ private: bool wireFrameMode = 0; float exposure = 1.0f; - - float loadingScreenVerticesData[12] = { - 1.0f, -1.0f, 0.0f, - -1.0f, 1.0f, 0.0f, - -1.0f, -1.0f, 0.0f, - 1.0f, 1.0f, 0.0f - }; - unsigned int loadingScreenIndicesData[6] = { - 0, 1, 2, - 0, 3, 1 - }; - float loadingScreenTextureCoordinates[8] = { - 1.0f, 0.0f, - 0.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 1.0f - }; }; diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 422b1fc..567f6f2 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -73,6 +73,13 @@ void Framebuffer::render(GLuint customTextureId) shaderProgram->unbind(); } +void Framebuffer::setExposureCorrection(bool exposureCorrection) +{ + shaderProgram->bind(); + shaderProgram->setUniform("u_exposureCorrection", exposureCorrection); + shaderProgram->unbind(); +} + DepthMap::DepthMap(int TYPE, int RESOLUTION) : cubeMap(RESOLUTION) { diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 7ae29a8..3ea544b 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -19,6 +19,7 @@ public: { return textures[0]; } + void setExposureCorrection(bool exposureCorrection); private: GLuint FBO; diff --git a/src/Screen.cpp b/src/Screen.cpp new file mode 100644 index 0000000..796656f --- /dev/null +++ b/src/Screen.cpp @@ -0,0 +1,33 @@ +#include "Screen.h" + +Screen::Screen(Framebuffer *framebuffer, ShaderProgram *shaderProgram) : + framebuffer(framebuffer), shaderProgram(shaderProgram) +{ + +} + +Screen::~Screen() +{ + +} + +void Screen::addWidget(Widget* widget) +{ + widgets.push_back(widget); +} + +void Screen::draw() +{ + framebuffer->setExposureCorrection(false); + framebuffer->bind(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + for(auto it = widgets.begin(); it != widgets.end(); it++) { + (*it)->draw(shaderProgram); + } + + framebuffer->unbind(); + framebuffer->render(); + framebuffer->setExposureCorrection(true); +} + diff --git a/src/Screen.h b/src/Screen.h new file mode 100644 index 0000000..e4e9c83 --- /dev/null +++ b/src/Screen.h @@ -0,0 +1,21 @@ +#pragma once + +#include "ShaderProgram.h" +#include "Framebuffer.h" +#include "Widget.h" + +class Screen +{ +public: + Screen(Framebuffer *framebuffer, ShaderProgram *shaderProgram); + ~Screen(); + + void addWidget(Widget *widget); + void draw(); + +private: + Framebuffer *framebuffer; + ShaderProgram *shaderProgram; + + std::vector widgets; +}; diff --git a/src/VertexArray.cpp b/src/VertexArray.cpp index 05032df..bfa9368 100644 --- a/src/VertexArray.cpp +++ b/src/VertexArray.cpp @@ -48,7 +48,7 @@ void VertexArray::unbind() glBindVertexArray(0); } -std::vector VertexArray::createVertices(float *vertices, uint32_t numVertices, float *textureCoordinates) { +std::vector VertexArray::createVertices(double *vertices, uint32_t numVertices, float *textureCoordinates) { std::vector vertexVec; uint32_t i = 0; uint32_t k = 0; diff --git a/src/VertexArray.h b/src/VertexArray.h index a04a54a..5a1fc54 100644 --- a/src/VertexArray.h +++ b/src/VertexArray.h @@ -13,7 +13,7 @@ public: void bind(); void unbind(); - static std::vector createVertices(float *vertices, uint32_t numVertices, float *textureCoordinates); + static std::vector createVertices(double *vertices, uint32_t numVertices, float *textureCoordinates); private: GLuint VAO; diff --git a/src/Widget.cpp b/src/Widget.cpp new file mode 100644 index 0000000..784746f --- /dev/null +++ b/src/Widget.cpp @@ -0,0 +1,46 @@ +#include "Widget.h" +#include "VertexArray.h" + +Widget::Widget(Texture *texture, float x, float y, float w, float h) : + x(x), y(y), w(w), h(h) +{ + widgetTextures.push_back(texture); + + const double ofst = 0.005; + + double widgetVerticesData[12] = { + x + w + ofst, -1.0f + 2*y - ofst, 0.0f, // Bottom right + -1.0f + 2*x - ofst, y + h + ofst, 0.0f, // Top left + -1.0f + 2*x-ofst, -1.0f + 2*y - ofst, 0.0f, // Bottom left + x + w + ofst, y + h + ofst, 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 + }; + + widgetVertices = VertexArray::createVertices(widgetVerticesData, 12, widgetTextureCoordinates); + widgetIndices.assign(widgetIndicesData, widgetIndicesData + 6); + widgetMesh = new Mesh(widgetVertices, widgetIndices, widgetTextures); +} + +Widget::~Widget() +{ + delete widgetMesh; +} + +void Widget::draw(ShaderProgram *shaderProgram) +{ + shaderProgram->bind(); + widgetMesh->draw(shaderProgram); + shaderProgram->unbind(); +} + diff --git a/src/Widget.h b/src/Widget.h new file mode 100644 index 0000000..2018359 --- /dev/null +++ b/src/Widget.h @@ -0,0 +1,23 @@ +#pragma once + +#include "Texture.h" +#include "Mesh.h" +#include "Framebuffer.h" + +class Widget +{ +public: + Widget(Texture *texture, float x, float y, float w, float h); + ~Widget(); + + void draw(ShaderProgram *shaderProgram); + +private: + double x, y, w, h; + + std::vector widgetVertices; + std::vector widgetIndices; + std::vector widgetTextures; + + Mesh *widgetMesh; +};