Remove JSON stuff and Widgets and Menus
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -4,3 +4,6 @@
|
||||
[submodule "lib/spdlog"]
|
||||
path = lib/spdlog
|
||||
url = git@github.com:gabime/spdlog.git
|
||||
[submodule "lib/entt"]
|
||||
path = lib/entt
|
||||
url = https://github.com/skypjack/entt.git
|
||||
|
||||
108
data/scene.json
108
data/scene.json
@@ -1,108 +0,0 @@
|
||||
{
|
||||
"models": [
|
||||
{
|
||||
"unique_name": "fallback",
|
||||
"path": "data/res/models/fallback.ffo"
|
||||
},
|
||||
{
|
||||
"unique_name": "backpack",
|
||||
"path": "data/res/models/backpack.ffo"
|
||||
},
|
||||
{
|
||||
"unique_name": "ground",
|
||||
"path": "data/res/models/wood_floor.ffo"
|
||||
},
|
||||
{
|
||||
"unique_name": "cube",
|
||||
"path": "data/res/models/cube.ffo"
|
||||
},
|
||||
{
|
||||
"unique_name": "container",
|
||||
"path": "data/res/models/container.ffo"
|
||||
}
|
||||
],
|
||||
"entities": [
|
||||
{
|
||||
"unique_name": "backpack",
|
||||
"model": "backpack",
|
||||
"shaderProgram": "defaultProgram",
|
||||
"position": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"rotation": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"scale": 0.6
|
||||
},
|
||||
{
|
||||
"unique_name": "container",
|
||||
"parent": "backpack",
|
||||
"model": "container",
|
||||
"shaderProgram": "defaultProgram",
|
||||
"position": [
|
||||
10.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"rotation": [
|
||||
45.0,
|
||||
45.0,
|
||||
45.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"unique_name": "ground",
|
||||
"model": "ground",
|
||||
"shaderProgram": "defaultProgram"
|
||||
},
|
||||
{
|
||||
"unique_name": "light",
|
||||
"model": "cube",
|
||||
"shaderProgram": "lightProgram"
|
||||
}
|
||||
],
|
||||
"directionalLight": {
|
||||
"unique_name": "directionalLight",
|
||||
"intensity": 0.25,
|
||||
"direction": [
|
||||
-0.2,
|
||||
-1.0,
|
||||
-0.3
|
||||
],
|
||||
"color": [
|
||||
1.0,
|
||||
1.0,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
"pointLights": [
|
||||
{
|
||||
"unique_name": "pointLight0",
|
||||
"parent": "light",
|
||||
"intensity": 7.5,
|
||||
"position": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"color": [
|
||||
1.0,
|
||||
1.0,
|
||||
1.0
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
{
|
||||
"unique_name": "fallback_normal",
|
||||
"path": "data/res/models/tex/fallback_normal.png"
|
||||
}
|
||||
],
|
||||
"skybox": {
|
||||
"texturePath": "data/res/textures/skybox/"
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
{
|
||||
"loadingScreen": [
|
||||
{
|
||||
"unique_name": "background",
|
||||
"position": [
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"dimensions": [
|
||||
1.0,
|
||||
1.0
|
||||
],
|
||||
"texture": "data/res/textures/loading.png"
|
||||
}
|
||||
],
|
||||
"mainMenuScreen": [
|
||||
{
|
||||
"unique_name": "play",
|
||||
"position": [
|
||||
0.4,
|
||||
0.5
|
||||
],
|
||||
"dimensions": [
|
||||
0.25,
|
||||
0.1
|
||||
],
|
||||
"texture": "data/res/textures/play.png",
|
||||
"callbackId": 1
|
||||
},
|
||||
{
|
||||
"unique_name": "exit",
|
||||
"position": [
|
||||
0.4,
|
||||
0.2
|
||||
],
|
||||
"dimensions": [
|
||||
0.25,
|
||||
0.10
|
||||
],
|
||||
"texture": "data/res/textures/exit.png",
|
||||
"callbackId": 2
|
||||
},
|
||||
{
|
||||
"unique_name": "background",
|
||||
"position": [
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"dimensions": [
|
||||
1.0,
|
||||
1.0
|
||||
],
|
||||
"texture": "data/res/textures/mainMenu.png",
|
||||
"callbackId": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
{
|
||||
"shaderPrograms": [
|
||||
{
|
||||
"unique_name": "defaultProgram",
|
||||
"vertexPath": "data/shaders/basic.vert",
|
||||
"fragmentPath": "data/shaders/basic.frag"
|
||||
},
|
||||
{
|
||||
"unique_name": "lightProgram",
|
||||
"vertexPath": "data/shaders/light.vert",
|
||||
"fragmentPath": "data/shaders/light.frag"
|
||||
},
|
||||
{
|
||||
"unique_name": "skyboxProgram",
|
||||
"vertexPath": "data/shaders/skybox.vert",
|
||||
"fragmentPath": "data/shaders/skybox.frag"
|
||||
},
|
||||
{
|
||||
"unique_name": "postProcessingProgram",
|
||||
"vertexPath": "data/shaders/postprocessing.vert",
|
||||
"fragmentPath": "data/shaders/postprocessing.frag"
|
||||
},
|
||||
{
|
||||
"unique_name": "menuProgram",
|
||||
"vertexPath": "data/shaders/menu.vert",
|
||||
"fragmentPath": "data/shaders/menu.frag",
|
||||
"geometryPath": "data/shaders/menu.geom"
|
||||
},
|
||||
{
|
||||
"unique_name": "directionalShadowDepthProgram",
|
||||
"vertexPath": "data/shaders/directionalShadowDepth.vert",
|
||||
"fragmentPath": "data/shaders/directionalShadowDepth.frag"
|
||||
},
|
||||
{
|
||||
"unique_name": "pointShadowDepthProgram",
|
||||
"vertexPath": "data/shaders/pointShadowDepth.vert",
|
||||
"fragmentPath": "data/shaders/pointShadowDepth.frag",
|
||||
"geometryPath": "data/shaders/pointShadowDepth.geom"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) out vec4 f_color;
|
||||
|
||||
in vec2 v_texCoord;
|
||||
|
||||
struct Material
|
||||
{
|
||||
sampler2D texture_diffuse0;
|
||||
};
|
||||
uniform Material u_material;
|
||||
|
||||
void main()
|
||||
{
|
||||
f_color = texture(u_material.texture_diffuse0, v_texCoord);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
#version 330 core
|
||||
|
||||
layout(points) in;
|
||||
layout(triangle_strip, max_vertices = 4) out;
|
||||
|
||||
struct WidgetData
|
||||
{
|
||||
vec2 position;
|
||||
vec2 dimensions;
|
||||
};
|
||||
uniform WidgetData u_widgetData;
|
||||
|
||||
out vec2 v_texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
float glWidth = u_widgetData.dimensions.x * 2.0f;
|
||||
float glHeight = u_widgetData.dimensions.y * 2.0f;
|
||||
|
||||
vec4 offset = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
gl_Position = gl_in[0].gl_Position + offset;
|
||||
v_texCoord = vec2(0.0, 0.0);
|
||||
EmitVertex();
|
||||
|
||||
offset = vec4(glWidth, 0.0, 0.0, 0.0);
|
||||
gl_Position = gl_in[0].gl_Position + offset;
|
||||
v_texCoord = vec2(1.0, 0.0);
|
||||
EmitVertex();
|
||||
|
||||
offset = vec4(0.0, glHeight, 0.0, 0.0);
|
||||
gl_Position = gl_in[0].gl_Position + offset;
|
||||
v_texCoord = vec2(0.0, 1.0);
|
||||
EmitVertex();
|
||||
|
||||
offset = vec4(glWidth, glHeight, 0.0, 0.0);
|
||||
gl_Position = gl_in[0].gl_Position + offset;
|
||||
v_texCoord = vec2(1.0, 1.0);
|
||||
EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#version 330 core
|
||||
|
||||
struct WidgetData
|
||||
{
|
||||
vec2 position;
|
||||
vec2 dimensions;
|
||||
};
|
||||
uniform WidgetData u_widgetData;
|
||||
|
||||
void main()
|
||||
{
|
||||
float glPosX = u_widgetData.position.x * 2.0f - 1.0f;
|
||||
float glPosY = u_widgetData.position.y * 2.0f - 1.0f;
|
||||
|
||||
gl_Position = vec4(glPosX, glPosY, 0, 1);
|
||||
}
|
||||
1
lib/entt
vendored
Submodule
1
lib/entt
vendored
Submodule
Submodule lib/entt added at de0e5862dd
@@ -11,21 +11,17 @@ add_executable(Fall-Fever
|
||||
Light.cpp
|
||||
Scene.cpp
|
||||
FrameBuffer.cpp
|
||||
Widget.cpp
|
||||
Screen.cpp
|
||||
Menu.cpp
|
||||
JsonParser.cpp
|
||||
Helper.cpp
|
||||
imgui/EntityWindow.cpp
|
||||
imgui/GeneralInfoWindow.cpp
|
||||
imgui/Handler.cpp
|
||||
imgui/Window.cpp
|
||||
util/Log.cpp
|
||||
resources/Resource.cpp
|
||||
resources/ResourceHandler.cpp
|
||||
resources/Texture.cpp
|
||||
resources/Model.cpp
|
||||
resources/CubeMap.cpp
|
||||
util/Log.cpp
|
||||
# imgui/EntityWindow.cpp
|
||||
# imgui/GeneralInfoWindow.cpp
|
||||
# imgui/Handler.cpp
|
||||
# imgui/Window.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
|
||||
@@ -1,45 +1,41 @@
|
||||
#include <vector>
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include "imgui/EntityWindow.h"
|
||||
#include "imgui/GeneralInfoWindow.h"
|
||||
#include "imgui/Handler.h"
|
||||
#endif
|
||||
|
||||
#include "Camera.h"
|
||||
#include "Controller.h"
|
||||
#include "Camera.h"
|
||||
#include "Entity.h"
|
||||
#include "EventHandler.h"
|
||||
#include "Helper.h"
|
||||
#include "JsonParser.h"
|
||||
#include "Light.h"
|
||||
#include "Menu.h"
|
||||
#include "Scene.h"
|
||||
#include "Screen.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "VertexArray.h"
|
||||
#include "Widget.h"
|
||||
#include "Window.h"
|
||||
#include "resources/Model.h"
|
||||
#include "resources/ResourceHandler.h"
|
||||
#include "resources/Texture.h"
|
||||
#include "util/Log.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <array>
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
Controller::Controller() : m_gameWindow(std::unique_ptr<Window>(new Window))
|
||||
{
|
||||
m_gameEventHandler = new EventHandler(m_gameWindow->getGLFWwindow());
|
||||
|
||||
m_camera = new Camera(90.0f, m_gameWindow->getWindowAspectRatio());
|
||||
|
||||
JsonParser shaderParser("data/shaderPrograms.json");
|
||||
auto shaderProgramPrototypes = shaderParser.getShaderProgramPrototypes();
|
||||
std::array shaderProgramPrototypes{
|
||||
ShaderProgram::Prototype{"defaultProgram", "data/shaders/basic.vert", "data/shaders/basic.frag", ""},
|
||||
ShaderProgram::Prototype{"lightProgram", "data/shaders/light.vert", "data/shaders/light.frag", ""},
|
||||
ShaderProgram::Prototype{"skyboxProgram", "data/shaders/skybox.vert", "data/shaders/skybox.frag", ""},
|
||||
ShaderProgram::Prototype{"postProcessingProgram", "data/shaders/postprocessing.vert",
|
||||
"data/shaders/postprocessing.frag", ""},
|
||||
ShaderProgram::Prototype{"directionalShadowDepthProgram", "data/shaders/directionalShadowDepth.vert",
|
||||
"data/shaders/directionalShadowDepth.frag", ""},
|
||||
ShaderProgram::Prototype{"pointShadowDepthProgram", "data/shaders/pointShadowDepth.vert",
|
||||
"data/shaders/pointShadowDepth.frag", "data/shaders/pointShadowDepth.geom"},
|
||||
};
|
||||
|
||||
for (auto &prototype : shaderProgramPrototypes) {
|
||||
m_shaderPrograms.push_back(new ShaderProgram(prototype));
|
||||
@@ -49,21 +45,7 @@ Controller::Controller() : m_gameWindow(std::unique_ptr<Window>(new Window))
|
||||
m_postProcessFrameBuffer = new FrameBuffer(m_gameWindow->getWindowWidth(), m_gameWindow->getWindowHeight(),
|
||||
getShaderProgramByName("postProcessingProgram"));
|
||||
|
||||
m_menu = new Menu(m_postProcessFrameBuffer, getShaderProgramByName("menuProgram"));
|
||||
|
||||
// Show loading screen...
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_menu->showScreenByName("loadingScreen");
|
||||
glfwSwapBuffers(m_gameWindow->getGLFWwindow());
|
||||
|
||||
// Show main menu when loading is finished...
|
||||
m_menu->showScreenByName("mainMenuScreen");
|
||||
|
||||
m_scene = new Scene(m_shaderPrograms);
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_imguiHandler = std::unique_ptr<Imgui::Handler>(new Imgui::Handler(m_gameWindow->getGLFWwindow()));
|
||||
#endif
|
||||
}
|
||||
|
||||
Controller::~Controller()
|
||||
@@ -74,17 +56,10 @@ Controller::~Controller()
|
||||
|
||||
delete m_scene;
|
||||
delete m_camera;
|
||||
delete m_menu;
|
||||
delete m_postProcessFrameBuffer;
|
||||
delete m_gameEventHandler;
|
||||
}
|
||||
|
||||
Controller &Controller::instance()
|
||||
{
|
||||
static Controller s_instance;
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void Controller::run()
|
||||
{
|
||||
updateExposure(getShaderProgramByName("postProcessingProgram"));
|
||||
@@ -96,19 +71,9 @@ void Controller::run()
|
||||
|
||||
m_camera->translate(glm::vec3(0.0f, 1.5f, 5.0f));
|
||||
|
||||
// imgui stuff
|
||||
bool rotateLightSource = false, rotateEntity = false, drawShadows = false;
|
||||
glm::vec3 lightColor = glm::vec3(1.f);
|
||||
float intensity = 7.5f;
|
||||
#ifdef _DEBUG
|
||||
std::shared_ptr<Imgui::Window> generalWindow = std::make_shared<Imgui::GeneralInfoWindow>(
|
||||
this, m_scene, getShaderProgramByName("postProcessingProgram"), &rotateEntity, &drawShadows, &rotateLightSource,
|
||||
&lightColor, &m_exposure, &intensity);
|
||||
m_imguiHandler->addImguiWindow(generalWindow);
|
||||
|
||||
// std::shared_ptr<Imgui::Window> entityWindow = std::make_shared<Imgui::EntityWindow>(m_scene->getEntities());
|
||||
// m_imguiHandler->addImguiWindow(entityWindow);
|
||||
#endif
|
||||
bool drawShadows = false;
|
||||
float intensity = 7.5;
|
||||
glm::vec3 lightColor{1., 1., 1.};
|
||||
|
||||
// This is the game loop
|
||||
while (!glfwWindowShouldClose(m_gameWindow->getGLFWwindow())) {
|
||||
@@ -117,20 +82,10 @@ void Controller::run()
|
||||
limit_framerate();
|
||||
|
||||
// --- Update game ---
|
||||
|
||||
if (rotateLightSource) {
|
||||
float radius = 4.0;
|
||||
glm::vec3 newPos = glm::vec3(-cos(glfwGetTime() * 0.5), 0.5f, sin(glfwGetTime() * 0.5)) * radius;
|
||||
m_scene->getEntityByName("light")->setPosition(newPos);
|
||||
}
|
||||
if (rotateEntity) {
|
||||
m_scene->getEntityById(0)->rotate(glm::vec3(0.0f, 1.0f, 0.0f), -0.2f * m_deltaTime);
|
||||
}
|
||||
|
||||
m_scene->updatePointLight(0, true, m_scene->getEntityByName("light")->getPosition(), lightColor, intensity);
|
||||
m_scene->updateDirectionalLight(true, m_scene->getDirectionalLight()->getDirection(), lightColor);
|
||||
getShaderProgramByName("lightProgram")->bind();
|
||||
getShaderProgramByName("lightProgram")->setUniform("v_lightColor", lightColor * 100.0f);
|
||||
getShaderProgramByName("lightProgram")->setUniform("v_lightColor", glm::vec3{1., 1., 1.} * 100.0f);
|
||||
getShaderProgramByName("lightProgram")->unbind();
|
||||
|
||||
// --- Render and buffer swap ---
|
||||
@@ -148,26 +103,18 @@ void Controller::run()
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
auto activeScreen = m_menu->getActiveScreen();
|
||||
if (activeScreen) {
|
||||
activeScreen->draw();
|
||||
} else {
|
||||
m_postProcessFrameBuffer->bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_postProcessFrameBuffer->bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
m_camera->lookForward();
|
||||
m_camera->updateVPM();
|
||||
m_camera->lookForward();
|
||||
m_camera->updateVPM();
|
||||
|
||||
m_scene->getSkybox()->draw(m_camera->getView(), m_camera->getProj());
|
||||
m_scene->draw(m_camera->getViewProj(), m_camera->getPosition());
|
||||
m_scene->getSkybox()->draw(m_camera->getView(), m_camera->getProj());
|
||||
m_scene->draw(m_camera->getViewProj(), m_camera->getPosition());
|
||||
|
||||
m_postProcessFrameBuffer->unbind();
|
||||
m_postProcessFrameBuffer->drawOnEntireScreen();
|
||||
m_postProcessFrameBuffer->unbind();
|
||||
m_postProcessFrameBuffer->drawOnEntireScreen();
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_imguiHandler->renderWindows();
|
||||
#endif
|
||||
}
|
||||
glfwSwapBuffers(m_gameWindow->getGLFWwindow());
|
||||
|
||||
// Update window size
|
||||
@@ -184,12 +131,7 @@ void Controller::run()
|
||||
m_camera->updateDirectionFromMouseInput(m_gameEventHandler->getCameraMouseActionMap());
|
||||
}
|
||||
|
||||
m_menu->writeWindowActions(m_gameEventHandler->getWindowActionMap());
|
||||
m_gameWindow->handleWindowActionMap(m_gameEventHandler->getWindowActionMap());
|
||||
|
||||
// Handle widget pressed event only when a screen is currently active
|
||||
if (m_menu->getActiveScreen())
|
||||
m_menu->handleMouseButtonActionMap(m_gameEventHandler->getMouseButtonActionMap(), m_gameWindow.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,22 +19,20 @@ class Handler;
|
||||
class Controller
|
||||
{
|
||||
public:
|
||||
Controller();
|
||||
~Controller();
|
||||
|
||||
static Controller &instance();
|
||||
|
||||
void run();
|
||||
|
||||
void setMaxFps(uint16_t fps);
|
||||
|
||||
// TODO remove...
|
||||
ShaderProgram *getShaderProgramByName(const std::string &name);
|
||||
static ShaderProgram *getShaderProgramByName(const std::string &name, std::vector<ShaderProgram *> shaderPrograms);
|
||||
|
||||
void updateExposure(ShaderProgram *shaderProgram);
|
||||
|
||||
private:
|
||||
Controller();
|
||||
|
||||
void limit_framerate();
|
||||
|
||||
void updateWindowDimensions();
|
||||
@@ -48,14 +46,9 @@ private:
|
||||
Scene *m_scene;
|
||||
|
||||
Camera *m_camera;
|
||||
Menu *m_menu;
|
||||
|
||||
std::vector<ShaderProgram *> m_shaderPrograms;
|
||||
|
||||
#ifdef _DEBUG
|
||||
std::unique_ptr<Imgui::Handler> m_imguiHandler;
|
||||
#endif
|
||||
|
||||
FrameBuffer *m_postProcessFrameBuffer;
|
||||
|
||||
uint16_t m_MAX_FPS = 60;
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Entity.h"
|
||||
#include "Light.h"
|
||||
#include "Screen.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Widget.h"
|
||||
#include "resources/Model.h"
|
||||
|
||||
class Screen;
|
||||
class ShaderProgram;
|
||||
class FrameBuffer;
|
||||
|
||||
class JsonParser
|
||||
{
|
||||
public:
|
||||
JsonParser(const std::string &jsonFilepath);
|
||||
~JsonParser();
|
||||
|
||||
std::vector<ModelDescriptor> getModelDescriptors() const;
|
||||
std::vector<ModelEntity::Prototype> getEntityPrototypes() const;
|
||||
std::vector<std::unique_ptr<Light::Prototype>> getLightPrototypes() const;
|
||||
std::vector<Screen::Prototype> getScreenPrototypes() const;
|
||||
Skybox::Prototype getSkyboxPrototype() const;
|
||||
|
||||
std::vector<ShaderProgram::Prototype> getShaderProgramPrototypes();
|
||||
|
||||
private:
|
||||
std::vector<Widget::Prototype> getWidgetPrototypesFromScreen(const Json::Value &screenJson) const;
|
||||
|
||||
Json::Value m_root;
|
||||
Json::CharReaderBuilder m_rbuilder;
|
||||
};
|
||||
93
src/Menu.cpp
93
src/Menu.cpp
@@ -1,93 +0,0 @@
|
||||
#include "Menu.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "Helper.h"
|
||||
#include "JsonParser.h"
|
||||
#include "Screen.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Widget.h"
|
||||
#include "Window.h"
|
||||
#include "definitions/eventActions.h"
|
||||
#include "util/Log.h"
|
||||
|
||||
Menu::Menu(FrameBuffer *p_framebuffer, ShaderProgram *p_shaderProgram)
|
||||
: m_frameBuffer(p_framebuffer), m_shaderProgram(p_shaderProgram)
|
||||
{
|
||||
JsonParser screenParser("data/screens.json");
|
||||
std::vector<Screen::Prototype> screenPrototypes = screenParser.getScreenPrototypes();
|
||||
|
||||
for (auto &prototype : screenPrototypes) {
|
||||
auto currentScreen = new Screen(prototype, p_framebuffer, p_shaderProgram);
|
||||
m_screens.push_back(currentScreen);
|
||||
}
|
||||
}
|
||||
|
||||
Menu::~Menu()
|
||||
{
|
||||
// Iterate over screens delete all items
|
||||
for (auto it = m_screens.begin(); it != m_screens.end(); it++) {
|
||||
delete (*it);
|
||||
}
|
||||
}
|
||||
|
||||
Screen *Menu::getScreenByName(const std::string &name) const
|
||||
{
|
||||
if (m_screenNameCache.find(name) != m_screenNameCache.end())
|
||||
return m_screenNameCache[name];
|
||||
|
||||
for (auto it : m_screens) {
|
||||
if (it->getUniqueName() == name) {
|
||||
m_screenNameCache[name] = it;
|
||||
return it;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Screen *Menu::getActiveScreen() const
|
||||
{
|
||||
return m_activeScreen;
|
||||
}
|
||||
|
||||
void Menu::showScreenByName(const std::string &name)
|
||||
{
|
||||
Screen *screen = getScreenByName(name);
|
||||
|
||||
if (!screen)
|
||||
return;
|
||||
|
||||
screen->draw();
|
||||
m_activeScreen = screen;
|
||||
}
|
||||
|
||||
void Menu::resetActiveScreen()
|
||||
{
|
||||
m_activeScreen = nullptr;
|
||||
}
|
||||
|
||||
void Menu::handleMouseButtonActionMap(const MouseButtonActionMap &mouseButtonActionMap, Window *window)
|
||||
{
|
||||
if (mouseButtonActionMap.at(MouseButtonAction::LeftClicked)) {
|
||||
auto widgets = m_activeScreen->getWidgets();
|
||||
for (auto it = widgets.begin(); it != widgets.end(); it++) {
|
||||
if ((*it)->isHovered(window)) {
|
||||
if ((*it)->getCallbackId() == 1)
|
||||
resetActiveScreen();
|
||||
if ((*it)->getCallbackId() == 2)
|
||||
m_shouldExit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::writeWindowActions(WindowActionMap &windowActionMap)
|
||||
{
|
||||
if (m_shouldExit)
|
||||
windowActionMap[WindowAction::WindowShouldClose] = true;
|
||||
}
|
||||
|
||||
void Menu::onPlayPressed()
|
||||
{}
|
||||
|
||||
void Menu::onExitPressed()
|
||||
{}
|
||||
47
src/Menu.h
47
src/Menu.h
@@ -1,47 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "definitions/eventActions.h"
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class ShaderProgram;
|
||||
class FrameBuffer;
|
||||
class Screen;
|
||||
class Window;
|
||||
|
||||
class Menu
|
||||
{
|
||||
public:
|
||||
Menu(FrameBuffer *p_framebuffer, ShaderProgram *p_shaderProgram);
|
||||
~Menu();
|
||||
|
||||
Screen *getScreenByName(const std::string &name) const;
|
||||
void showScreenByName(const std::string &name);
|
||||
|
||||
Screen *getActiveScreen() const;
|
||||
void writeWindowActions(WindowActionMap &windowActionMap);
|
||||
|
||||
void resetActiveScreen();
|
||||
|
||||
void handleMouseButtonActionMap(const MouseButtonActionMap &mouseButtonActionMap, Window *window);
|
||||
|
||||
void onPlayPressed();
|
||||
void onExitPressed();
|
||||
|
||||
private:
|
||||
FrameBuffer *m_frameBuffer;
|
||||
ShaderProgram *m_shaderProgram;
|
||||
|
||||
bool m_shouldExit = false;
|
||||
|
||||
std::vector<Screen *> m_screens;
|
||||
Screen *m_activeScreen;
|
||||
/*Screen *loadingScreen;
|
||||
Screen *mainMenuScreen;
|
||||
Screen *optionMenuScreen;
|
||||
Screen *pauseMenuScreen;*/
|
||||
|
||||
mutable std::unordered_map<std::string, Screen *> m_screenNameCache;
|
||||
};
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "Controller.h"
|
||||
#include "Entity.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "JsonParser.h"
|
||||
#include "Light.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "resources/Model.h"
|
||||
@@ -12,6 +11,7 @@
|
||||
#include "util/Log.h"
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
|
||||
@@ -29,9 +29,13 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
|
||||
m_shaderProgram->setUniform("u_material.shininess", 100.0f);
|
||||
m_shaderProgram->unbind();
|
||||
|
||||
JsonParser modelParser("data/scene.json");
|
||||
|
||||
std::vector<ModelDescriptor> modelDescriptors = modelParser.getModelDescriptors();
|
||||
std::array modelDescriptors{
|
||||
ModelDescriptor{"fallback", "data/res/models/fallback.ffo"},
|
||||
ModelDescriptor{"backpack", "data/res/models/backpack.ffo"},
|
||||
ModelDescriptor{"ground", "data/res/models/wood_floor.ffo"},
|
||||
ModelDescriptor{"cube", "data/res/models/cube.ffo"},
|
||||
ModelDescriptor{"container", "data/res/models/container.ffo"},
|
||||
};
|
||||
|
||||
{
|
||||
std::vector<std::future<void>> futures;
|
||||
@@ -53,7 +57,7 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
|
||||
}
|
||||
|
||||
// TODO: use geometry shader instead of model and load skybox before models.
|
||||
Skybox::Prototype skyboxPrototype = modelParser.getSkyboxPrototype();
|
||||
Skybox::Prototype skyboxPrototype{"data/res/textures/skybox/"};
|
||||
m_skybox =
|
||||
new Skybox(skyboxPrototype, std::static_pointer_cast<Model>(ResourceHandler::instance().resource("cube")).get(),
|
||||
Controller::getShaderProgramByName("skyboxProgram", shaderPrograms));
|
||||
@@ -61,7 +65,13 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
|
||||
Log::logger().info("Loaded skybox: {}", skyboxPrototype.texturePath);
|
||||
m_skybox->initializeOnGPU();
|
||||
|
||||
std::vector<ModelEntity::Prototype> entityPrototypes = modelParser.getEntityPrototypes();
|
||||
std::array entityPrototypes{
|
||||
ModelEntity::Prototype{"backpack", "", {0., 1., 0.}, {}, 0.6, "backpack", "defaultProgram"},
|
||||
ModelEntity::Prototype{
|
||||
"container", "backpack", {10., 1., 0.}, {45., 45., 45.}, 1., "container", "defaultProgram"},
|
||||
ModelEntity::Prototype{"ground", "", {}, {}, 1., "ground", "defaultProgram"},
|
||||
ModelEntity::Prototype{"light", "", {}, {}, 1., "cube", "lightProgram"},
|
||||
};
|
||||
|
||||
{
|
||||
for (auto &prototype : entityPrototypes) {
|
||||
@@ -100,8 +110,13 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
|
||||
}
|
||||
}
|
||||
|
||||
JsonParser lightParser("data/scene.json");
|
||||
auto lightPrototypes = lightParser.getLightPrototypes();
|
||||
// Order important
|
||||
std::array<std::unique_ptr<Light::Prototype>, 2> lightPrototypes{
|
||||
std::unique_ptr<DirectionalLight::Prototype>(
|
||||
new DirectionalLight::Prototype{"directionalLight", {-0.2, -1.0, -0.3}, {1., 1., 1.}, 0.25}),
|
||||
std::unique_ptr<PointLight::Prototype>(
|
||||
new PointLight::Prototype{"pointLight0", "light", {0., 1., 0.}, {1., 1., 1.}, 7.5}),
|
||||
};
|
||||
|
||||
std::vector<Light *> lights;
|
||||
{
|
||||
@@ -119,10 +134,13 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
|
||||
if (parent) {
|
||||
parent->addChild(currentLight);
|
||||
currentLight->setParent(parent);
|
||||
} else {
|
||||
Log::logger().warn("Could not find entity \"{}\"", pointPrototype->parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
lights.push_back(currentLight);
|
||||
Log::logger().info("Loaded light \"{}\"", prototype->name);
|
||||
}
|
||||
}
|
||||
m_lights = lights;
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
#include "Screen.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "Helper.h"
|
||||
#include "Menu.h"
|
||||
#include "ShaderProgram.h"
|
||||
// #include "Texture.h"
|
||||
#include "Widget.h"
|
||||
#include "resources/ResourceHandler.h"
|
||||
|
||||
uint32_t Screen::s_idCounter = 0;
|
||||
|
||||
Screen::Screen(Prototype prototype, FrameBuffer *framebuffer, ShaderProgram *shaderProgram)
|
||||
: m_id(s_idCounter++), m_uniqueName(prototype.name), m_frameBuffer(framebuffer), m_shaderProgram(shaderProgram)
|
||||
{
|
||||
for (auto &prototype : prototype.widgetPrototypes) {
|
||||
auto texturePrototype = prototype.texturePrototype;
|
||||
ResourceId textureId = ResourceHandler::instance().registerResource<Texture>(texturePrototype);
|
||||
|
||||
Widget *currentWidget = new Widget(prototype, textureId);
|
||||
m_widgets.push_back(currentWidget);
|
||||
}
|
||||
}
|
||||
|
||||
Screen::~Screen()
|
||||
{
|
||||
// Iterate over Widgets and Textures to delete all of them
|
||||
for (auto it = m_widgets.begin(); it != m_widgets.end(); it++) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
const std::string &Screen::getUniqueName() const
|
||||
{
|
||||
return m_uniqueName;
|
||||
}
|
||||
|
||||
std::vector<Widget *> Screen::getWidgets() const
|
||||
{
|
||||
return m_widgets;
|
||||
}
|
||||
|
||||
Widget *Screen::getWidgetByName(const std::string &name) const
|
||||
{
|
||||
if (m_widgetNameCache.find(name) != m_widgetNameCache.end())
|
||||
return m_widgetNameCache[name];
|
||||
|
||||
for (auto it : m_widgets) {
|
||||
if (it->getUniqueName() == name) {
|
||||
m_widgetNameCache[name] = it;
|
||||
return it;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Screen::addWidget(Widget *widget)
|
||||
{
|
||||
m_widgets.push_back(widget);
|
||||
}
|
||||
|
||||
void Screen::draw() const
|
||||
{
|
||||
m_frameBuffer->setExposureCorrection(false);
|
||||
m_frameBuffer->bind();
|
||||
|
||||
for (auto it = m_widgets.begin(); it != m_widgets.end(); it++) {
|
||||
(*it)->draw(m_shaderProgram);
|
||||
}
|
||||
|
||||
m_frameBuffer->unbind();
|
||||
m_frameBuffer->drawOnEntireScreen();
|
||||
m_frameBuffer->setExposureCorrection(true);
|
||||
}
|
||||
45
src/Screen.h
45
src/Screen.h
@@ -1,45 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
#include "resources/Texture.h"
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class Menu;
|
||||
class FrameBuffer;
|
||||
class ShaderProgram;
|
||||
|
||||
class Screen
|
||||
{
|
||||
public:
|
||||
struct Prototype
|
||||
{
|
||||
std::string name;
|
||||
std::vector<Widget::Prototype> widgetPrototypes;
|
||||
};
|
||||
|
||||
Screen(Prototype prototype, 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;
|
||||
|
||||
private:
|
||||
uint32_t m_id;
|
||||
static uint32_t s_idCounter;
|
||||
std::string m_uniqueName;
|
||||
|
||||
FrameBuffer *m_frameBuffer;
|
||||
ShaderProgram *m_shaderProgram;
|
||||
|
||||
std::vector<ResourceId> m_textures;
|
||||
std::vector<Widget *> m_widgets;
|
||||
|
||||
mutable std::unordered_map<std::string, Widget *> m_widgetNameCache;
|
||||
};
|
||||
@@ -1,145 +0,0 @@
|
||||
#include "ShaderProgram.h"
|
||||
#include "Texture.h"
|
||||
#include "util/Log.h"
|
||||
|
||||
CubeMap::CubeMap(const std::string &texturePseudoPath)
|
||||
{
|
||||
// Reserve space in vector so that elements can be accessed explicitly.
|
||||
m_texturePaths.resize(static_cast<int>(cubeMapFaces::CUBEMAP_FACES_NUM_ITEMS));
|
||||
m_textureBuffers.resize(static_cast<int>(cubeMapFaces::CUBEMAP_FACES_NUM_ITEMS));
|
||||
m_numComponents.resize(static_cast<int>(cubeMapFaces::CUBEMAP_FACES_NUM_ITEMS));
|
||||
|
||||
fillTexturePathVector(texturePseudoPath);
|
||||
|
||||
stbi_set_flip_vertically_on_load(0);
|
||||
|
||||
glGenTextures(1, &m_textureId);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_textureId);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
|
||||
int i = 0;
|
||||
for (auto &path : m_texturePaths) {
|
||||
|
||||
int32_t numComponents;
|
||||
auto textureBuffer = stbi_load(path.c_str(), &m_textureWidth, &m_textureHeight, &numComponents, 0);
|
||||
|
||||
if (!textureBuffer) {
|
||||
Log::logger().warn("CubeMap texture {} could not be loaded", path);
|
||||
return;
|
||||
}
|
||||
|
||||
m_textureBuffers[i] = textureBuffer;
|
||||
m_numComponents[i] = numComponents;
|
||||
i++;
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
}
|
||||
|
||||
CubeMap::CubeMap(int RESOLUTION) : m_textureWidth(RESOLUTION), m_textureHeight(RESOLUTION)
|
||||
{
|
||||
|
||||
glGenTextures(1, &m_textureId);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_textureId);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
}
|
||||
|
||||
CubeMap::~CubeMap()
|
||||
{
|
||||
// glDeleteTextures(1, &m_textureId);
|
||||
}
|
||||
|
||||
void CubeMap::initializeOnGPU()
|
||||
{
|
||||
if (m_isInitialized)
|
||||
return;
|
||||
|
||||
m_isInitialized = true;
|
||||
|
||||
glGenTextures(1, &m_textureId);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_textureId);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
|
||||
int i = 0;
|
||||
for (auto &textureBuffer : m_textureBuffers) {
|
||||
GLenum internalFormat;
|
||||
GLenum dataFormat;
|
||||
|
||||
switch (m_numComponents[i]) {
|
||||
case 1:
|
||||
internalFormat = GL_RED;
|
||||
dataFormat = GL_RED;
|
||||
break;
|
||||
case 3:
|
||||
internalFormat = GL_SRGB8;
|
||||
dataFormat = GL_RGB;
|
||||
break;
|
||||
case 4:
|
||||
internalFormat = GL_SRGB8_ALPHA8;
|
||||
dataFormat = GL_RGBA;
|
||||
break;
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, m_textureWidth, m_textureHeight, 0,
|
||||
dataFormat, GL_UNSIGNED_BYTE, textureBuffer);
|
||||
|
||||
stbi_image_free(textureBuffer);
|
||||
i++;
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
}
|
||||
|
||||
void CubeMap::bind(ShaderProgram *shaderProgram)
|
||||
{
|
||||
std::string uniformName = "u_skybox";
|
||||
|
||||
shaderProgram->setUniform(uniformName.c_str(), 0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_textureId);
|
||||
}
|
||||
|
||||
void CubeMap::unbind()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
}
|
||||
|
||||
void CubeMap::fillTexturePathVector(const std::string &texturePseudoPath)
|
||||
{
|
||||
for (unsigned int i = 0; i < static_cast<int>(cubeMapFaces::CUBEMAP_FACES_NUM_ITEMS); i++) {
|
||||
m_texturePaths[static_cast<int>(cubeMapFaces::cm_front)] = texturePseudoPath + "front.png";
|
||||
m_texturePaths[static_cast<int>(cubeMapFaces::cm_back)] = texturePseudoPath + "back.png";
|
||||
m_texturePaths[static_cast<int>(cubeMapFaces::cm_top)] = texturePseudoPath + "top.png";
|
||||
m_texturePaths[static_cast<int>(cubeMapFaces::cm_bottom)] = texturePseudoPath + "bottom.png";
|
||||
m_texturePaths[static_cast<int>(cubeMapFaces::cm_left)] = texturePseudoPath + "left.png";
|
||||
m_texturePaths[static_cast<int>(cubeMapFaces::cm_right)] = texturePseudoPath + "right.png";
|
||||
}
|
||||
}
|
||||
|
||||
GLuint CubeMap::getTextureId() const
|
||||
{
|
||||
return m_textureId;
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "definitions/models.h"
|
||||
#include "resources/Texture.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <glad/glad.h>
|
||||
#include <stb/stb_image.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class ShaderProgram;
|
||||
|
||||
// Order is important!
|
||||
enum class cubeMapFaces
|
||||
{
|
||||
cm_right,
|
||||
cm_left,
|
||||
cm_top,
|
||||
cm_bottom,
|
||||
cm_back,
|
||||
cm_front,
|
||||
CUBEMAP_FACES_NUM_ITEMS
|
||||
};
|
||||
|
||||
class CubeMap
|
||||
{
|
||||
public:
|
||||
CubeMap(const std::string &texturePseudoPath);
|
||||
CubeMap(int RESOLUTION);
|
||||
|
||||
void initializeOnGPU();
|
||||
|
||||
~CubeMap();
|
||||
|
||||
void bind(ShaderProgram *shaderProgram);
|
||||
void unbind();
|
||||
|
||||
GLuint getTextureId() const;
|
||||
|
||||
private:
|
||||
void fillTexturePathVector(const std::string &texturePseudoPath);
|
||||
|
||||
bool m_isInitialized = false;
|
||||
|
||||
std::vector<std::string> m_texturePaths;
|
||||
std::vector<stbi_uc *> m_textureBuffers;
|
||||
std::vector<int> m_numComponents;
|
||||
|
||||
GLuint m_textureId;
|
||||
|
||||
int32_t m_textureWidth;
|
||||
int32_t m_textureHeight;
|
||||
};
|
||||
@@ -1,73 +0,0 @@
|
||||
#include "Widget.h"
|
||||
#include "Menu.h"
|
||||
#include "Mesh.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "VertexArray.h"
|
||||
#include "Window.h"
|
||||
#include "resources/ResourceHandler.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
Widget::Widget(Prototype prototype, ResourceId texture)
|
||||
: m_position(prototype.position), m_dimensions(prototype.dimensions), m_uniqueName(prototype.name),
|
||||
m_callbackId(prototype.callBackId)
|
||||
{
|
||||
m_widgetTextures.push_back(texture);
|
||||
}
|
||||
|
||||
std::string Widget::getUniqueName()
|
||||
{
|
||||
return m_uniqueName;
|
||||
}
|
||||
|
||||
uint16_t Widget::getCallbackId()
|
||||
{
|
||||
return m_callbackId;
|
||||
}
|
||||
|
||||
void Widget::draw(ShaderProgram *shaderProgram)
|
||||
{
|
||||
shaderProgram->bind();
|
||||
shaderProgram->setUniform("u_widgetData.position", m_position);
|
||||
shaderProgram->setUniform("u_widgetData.dimensions", m_dimensions);
|
||||
|
||||
GLint wireframe;
|
||||
glGetIntegerv(GL_POLYGON_MODE, &wireframe);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
auto texture = std::static_pointer_cast<Texture>(ResourceHandler::instance().resource(m_widgetTextures[0]));
|
||||
glBindTexture(GL_TEXTURE_2D, texture->glId());
|
||||
|
||||
GLint location = glGetUniformLocation(shaderProgram->getShaderProgramId(), "u_texture");
|
||||
glUniform1i(location, 0);
|
||||
|
||||
// A VAO is necessary although no data is stored in it
|
||||
GLuint temp_vao;
|
||||
glGenVertexArrays(1, &temp_vao);
|
||||
glBindVertexArray(temp_vao);
|
||||
glDrawArrays(GL_POINTS, 0, 3);
|
||||
glBindVertexArray(0);
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, wireframe);
|
||||
|
||||
shaderProgram->unbind();
|
||||
}
|
||||
|
||||
bool Widget::isHovered(Window *window)
|
||||
{
|
||||
double xpos, ypos, width, height;
|
||||
glfwGetCursorPos(window->getGLFWwindow(), &xpos, &ypos);
|
||||
width = window->getWindowWidth();
|
||||
height = window->getWindowHeight();
|
||||
|
||||
double xrel = xpos / width;
|
||||
double yrel = -ypos / height + 1;
|
||||
|
||||
bool isHovered = false;
|
||||
if (xrel >= m_position.x && xrel <= m_position.x + m_dimensions.x && yrel >= m_position.y &&
|
||||
yrel <= m_position.y + m_dimensions.x)
|
||||
isHovered = true;
|
||||
|
||||
return isHovered;
|
||||
}
|
||||
45
src/Widget.h
45
src/Widget.h
@@ -1,45 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "definitions/models.h"
|
||||
#include "resources/Texture.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Menu;
|
||||
class ShaderProgram;
|
||||
class Window;
|
||||
class Mesh;
|
||||
|
||||
class Widget
|
||||
{
|
||||
public:
|
||||
struct Prototype
|
||||
{
|
||||
std::string name;
|
||||
glm::vec2 position;
|
||||
glm::vec2 dimensions;
|
||||
TextureDescriptor texturePrototype;
|
||||
uint16_t callBackId; // TODO: will be removed...
|
||||
};
|
||||
|
||||
Widget(Prototype prototype, ResourceId texture);
|
||||
|
||||
void draw(ShaderProgram *shaderProgram);
|
||||
|
||||
std::string getUniqueName();
|
||||
uint16_t getCallbackId();
|
||||
|
||||
bool isHovered(Window *window);
|
||||
|
||||
private:
|
||||
glm::vec2 m_position;
|
||||
glm::vec2 m_dimensions;
|
||||
|
||||
std::string m_uniqueName;
|
||||
|
||||
uint16_t m_callbackId;
|
||||
|
||||
std::vector<ResourceId> m_widgetTextures;
|
||||
};
|
||||
@@ -13,7 +13,7 @@ int main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
// Create controller
|
||||
Controller &controller = Controller::instance();
|
||||
Controller controller;
|
||||
|
||||
const char *fps_env = std::getenv("MAXFPS");
|
||||
if (fps_env) {
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
struct ModelDescriptor
|
||||
{
|
||||
std::string path;
|
||||
std::string name;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
class Model : public Resource, public NamedResource
|
||||
|
||||
@@ -7,7 +7,7 @@ Log Log::s_instance;
|
||||
Log::Log()
|
||||
{
|
||||
m_logger = spdlog::stdout_color_mt("Core");
|
||||
// m_logger->set_pattern("");
|
||||
m_logger->set_pattern("[%H:%M:%S.%e] [%n] [%^%l%$] %v");
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_logger->set_level(spdlog::level::debug);
|
||||
|
||||
Reference in New Issue
Block a user