From bfd5d414373923efa8d2dac9dfbcc3685c6b802c Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Sat, 16 Jan 2021 23:36:34 +0100 Subject: [PATCH] Implement first menu (still not active) --- data/screens.json | 26 +++++++++++++------------- imgui.ini | 2 +- src/Controller.cpp | 28 ++++++++++++++++++---------- src/Menu.cpp | 7 +++++++ src/Menu.h | 2 ++ src/Widget.cpp | 10 ++++------ src/helper.h | 2 ++ 7 files changed, 47 insertions(+), 30 deletions(-) diff --git a/data/screens.json b/data/screens.json index 302fbe9..5effff6 100644 --- a/data/screens.json +++ b/data/screens.json @@ -1,7 +1,7 @@ { "loadingScreen": [ { - "unique_name": "widget0", + "unique_name": "background", "position": [0.0, 0.0], "dimensions": [1.0, 1.0], "texture": "data/res/textures/loading.png" @@ -9,22 +9,22 @@ ], "mainMenuScreen": [ { - "unique_name": "widget1", - "position": [0.5, 0.5], - "dimensions": [0.25, 0.25], - "texture": "data/res/textures/container.png" + "unique_name": "exit", + "position": [0.4, 0.2], + "dimensions": [0.25, 0.10], + "texture": "data/res/textures/exit.png" }, { - "unique_name": "widget2", - "position": [0.75, 0.0], - "dimensions": [0.25, 0.25], - "texture": "data/res/textures/tex2.png" + "unique_name": "play", + "position": [0.4, 0.5], + "dimensions": [0.25, 0.1], + "texture": "data/res/textures/play.png" }, { - "unique_name": "widget3", - "position": [0.05, 0.05], - "dimensions": [0.35, 0.35], - "texture": "data/res/textures/loading.png" + "unique_name": "background", + "position": [0.0, 0.0], + "dimensions": [1.0, 1.0], + "texture": "data/res/textures/mainMenu.png" } ] } diff --git a/imgui.ini b/imgui.ini index 4d2411f..08adda9 100644 --- a/imgui.ini +++ b/imgui.ini @@ -9,7 +9,7 @@ Size=894,195 Collapsed=0 [Window][Debug Utils] -Pos=13,9 +Pos=14,9 Size=791,379 Collapsed=0 diff --git a/src/Controller.cpp b/src/Controller.cpp index 4a3e41d..235a866 100644 --- a/src/Controller.cpp +++ b/src/Controller.cpp @@ -42,6 +42,9 @@ Controller::Controller() menu->showScreenByName("loadingScreen"); glfwSwapBuffers(gameWindow->getGLFWwindow()); + // Show main menu when loading is finished... + menu->showScreenByName("mainMenuScreen"); + world = new World(shaderPrograms); #ifdef _DEBUG @@ -128,23 +131,28 @@ void Controller::run() world->calculateShadows(getShaderProgramByName("directionalShadowDepthProgram"), getShaderProgramByName("pointShadowDepthProgram")); } - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - menu->showScreenByName("mainMenuScreen"); - pp_framebuffer->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - camera->lookForward(); - camera->updateVPM(); + auto activeScreen = menu->getActiveScreen(); + if(activeScreen) { + activeScreen->draw(); + } else { + pp_framebuffer->bind(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - world->getSkybox()->draw(camera->getView(), camera->getProj()); - world->draw(camera->getViewProj(), camera->getPosition()); + camera->lookForward(); + camera->updateVPM(); - pp_framebuffer->unbind(); - pp_framebuffer->render(); + world->getSkybox()->draw(camera->getView(), camera->getProj()); + world->draw(camera->getViewProj(), camera->getPosition()); + + pp_framebuffer->unbind(); + pp_framebuffer->render(); #ifdef _DEBUG - renderImGui(world, world->getPointLights()[0], &lightColor, &rotateEntity, &rotateLightSource, getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows); + renderImGui(world, world->getPointLights()[0], &lightColor, &rotateEntity, &rotateLightSource, getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows); #endif + } glfwSwapBuffers(gameWindow->getGLFWwindow()); // Update window size diff --git a/src/Menu.cpp b/src/Menu.cpp index 8abfb4e..7ee9bf2 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -1,6 +1,8 @@ #include "Menu.h" #include "JsonParser.h" #include "eventActions.h" +#include "helper.h" + #include Menu::Menu(Framebuffer *p_framebuffer, ShaderProgram *p_shaderProgram) : framebuffer(p_framebuffer), shaderProgram(p_shaderProgram) @@ -27,6 +29,11 @@ Screen *Menu::getScreenByName(const char* unique_name) return nullptr; } +Screen *Menu::getActiveScreen() +{ + return activeScreen; +} + void Menu::showScreenByName(const char *unique_name) { auto it = screens.begin(); diff --git a/src/Menu.h b/src/Menu.h index ebfd721..9487c24 100644 --- a/src/Menu.h +++ b/src/Menu.h @@ -15,6 +15,8 @@ public: Screen *getScreenByName(const char *unique_name); void showScreenByName(const char *unique_name); + Screen *getActiveScreen(); + void resetActiveScreen(); void handleMouseButtonActionRegister(bool *mouseButtonActionRegister, Window* window); diff --git a/src/Widget.cpp b/src/Widget.cpp index a8c29f8..bc6e32a 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -10,13 +10,11 @@ Widget::Widget(std::string &name, Texture *texture, float p_x, float p_y, float { widgetTextures.push_back(texture); - const double ofst = 0.005; - double widgetVerticesData[12] = { - 2 * (x + w) - 1.0f + ofst, 2 * (y) - 1.0f - ofst, 0.0f, // Bottom right - 2 * (x) - 1.0f - ofst, 2 * (y + h) - 1.0f + ofst, 0.0f, // Top left - 2 * (x) - 1.0f - ofst, 2 * (y) - 1.0f - ofst, 0.0f, // Bottom left - 2 * (x + w) - 1.0f + ofst, 2 * (y + h) - 1.0f + ofst, 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] = { diff --git a/src/helper.h b/src/helper.h index 3a2509e..c95c26d 100644 --- a/src/helper.h +++ b/src/helper.h @@ -1,8 +1,10 @@ #pragma once #include +#include #include #include +#include #ifdef __linux__ #include