Introduce Widget and Screen classes
This commit is contained in:
@@ -13,6 +13,7 @@ set(OpenGL_GL_PREFERENCE "GLVND")
|
|||||||
|
|
||||||
find_package(GLFW3 REQUIRED)
|
find_package(GLFW3 REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
find_package(Freetype REQUIRED)
|
||||||
|
|
||||||
# Specify the C++ standard
|
# Specify the C++ standard
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ Size=894,195
|
|||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Debug Utils]
|
[Window][Debug Utils]
|
||||||
Pos=13,7
|
Pos=10,7
|
||||||
Size=871,365
|
Size=871,365
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ layout(location = 0) out vec4 f_color;
|
|||||||
in vec2 v_tex_coords;
|
in vec2 v_tex_coords;
|
||||||
|
|
||||||
uniform float u_exposure;
|
uniform float u_exposure;
|
||||||
|
uniform bool u_exposureCorrection;
|
||||||
|
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
|
|
||||||
@@ -15,7 +16,8 @@ void main() {
|
|||||||
vec3 fragmentColor = vec3(texture2D(u_texture, v_tex_coords));
|
vec3 fragmentColor = vec3(texture2D(u_texture, v_tex_coords));
|
||||||
|
|
||||||
// Exposure tone mapping
|
// Exposure tone mapping
|
||||||
fragmentColor = vec3(1.0) - exp(-fragmentColor * u_exposure);
|
if(u_exposureCorrection)
|
||||||
|
fragmentColor = vec3(1.0) - exp(-fragmentColor * u_exposure);
|
||||||
|
|
||||||
// Gamma correction
|
// Gamma correction
|
||||||
fragmentColor = pow(fragmentColor, vec3(1.0/GAMMA));
|
fragmentColor = pow(fragmentColor, vec3(1.0/GAMMA));
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ add_executable(Fall-Fever
|
|||||||
Light.cpp
|
Light.cpp
|
||||||
World.cpp
|
World.cpp
|
||||||
Framebuffer.cpp
|
Framebuffer.cpp
|
||||||
|
Widget.cpp
|
||||||
|
Screen.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
@@ -22,6 +24,7 @@ target_link_libraries(
|
|||||||
stb
|
stb
|
||||||
${GLFW3_LIBRARY}
|
${GLFW3_LIBRARY}
|
||||||
${OPENGL_LIBRARIES}
|
${OPENGL_LIBRARIES}
|
||||||
|
${FREETYPE_LIBRARIES}
|
||||||
imgui
|
imgui
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
|
#include "Widget.h"
|
||||||
|
#include "Screen.h"
|
||||||
|
|
||||||
Controller::Controller()
|
Controller::Controller()
|
||||||
{
|
{
|
||||||
@@ -95,32 +97,21 @@ void Controller::run()
|
|||||||
// Show loading screen...
|
// Show loading screen...
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
Texture loadingScreenTex("res/textures/loading.png", textureType::texture_diffuse);
|
Texture loadingScreenTex("res/textures/loading.png", textureType::texture_diffuse);
|
||||||
std::vector<Vertex> loadingScreenVertices = VertexArray::createVertices(loadingScreenVerticesData, 12, loadingScreenTextureCoordinates);
|
Widget loadingScreenWidget(&loadingScreenTex, 0.f, 0.f, 1.f, 1.f);
|
||||||
std::vector<uint32_t> loadingScreenIndices;
|
Screen loadingScreen(pp_framebuffer, &menuProgram);
|
||||||
std::vector<Texture*> loadingScreenTextures;
|
loadingScreen.addWidget(&loadingScreenWidget);
|
||||||
loadingScreenTextures.push_back(&loadingScreenTex);
|
loadingScreen.draw();
|
||||||
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();
|
|
||||||
glfwSwapBuffers(gameWindow->getGLFWwindow());
|
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_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");
|
Model model_ground("res/models/wood_floor.ffo");
|
||||||
|
|
||||||
Entity dragon(&model_dragon, &shaderProgram);
|
Entity backpack(&model_backpack, &shaderProgram);
|
||||||
Entity ground(&model_ground, &shaderProgram);
|
Entity ground(&model_ground, &shaderProgram);
|
||||||
Entity lightSource(&model_cube, &lightProgram);
|
Entity lightSource(&model_cube, &lightProgram);
|
||||||
|
|
||||||
dragon.setRotation(glm::vec3(0.0f));
|
|
||||||
dragon.setScale(0.2f);
|
|
||||||
lightSource.setScale(0.1f);
|
lightSource.setScale(0.1f);
|
||||||
lightSource.setRotation(glm::vec3(0.f));
|
lightSource.setRotation(glm::vec3(0.f));
|
||||||
lightSource.setPosition(glm::vec3(-2.f, 1.5f, 2.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/");
|
Skybox skybox(&model_cube, &skyboxProgram, "res/textures/skybox/");
|
||||||
|
|
||||||
World world(&shaderProgram);
|
World world(&shaderProgram);
|
||||||
world.addEntity(dragon);
|
world.addEntity(backpack);
|
||||||
world.addEntity(lightSource);
|
world.addEntity(lightSource);
|
||||||
world.addEntity(ground);
|
world.addEntity(ground);
|
||||||
|
|
||||||
@@ -269,9 +260,9 @@ void Controller::renderImGui(std::vector<Entity> *entites, PointLight *pointLigh
|
|||||||
ImGui::Text("Object");
|
ImGui::Text("Object");
|
||||||
static float rotation = 0.0;
|
static float rotation = 0.0;
|
||||||
ImGui::SliderFloat("Rotation", &rotation, 0, 2 * M_PI);
|
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);
|
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::SliderFloat("Scale", &scale, 0.02, 2.0);
|
||||||
ImGui::Checkbox("Rotate Object", rotateEntity);
|
ImGui::Checkbox("Rotate Object", rotateEntity);
|
||||||
|
|
||||||
|
|||||||
@@ -42,21 +42,4 @@ private:
|
|||||||
bool wireFrameMode = 0;
|
bool wireFrameMode = 0;
|
||||||
|
|
||||||
float exposure = 1.0f;
|
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
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -73,6 +73,13 @@ void Framebuffer::render(GLuint customTextureId)
|
|||||||
shaderProgram->unbind();
|
shaderProgram->unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Framebuffer::setExposureCorrection(bool exposureCorrection)
|
||||||
|
{
|
||||||
|
shaderProgram->bind();
|
||||||
|
shaderProgram->setUniform("u_exposureCorrection", exposureCorrection);
|
||||||
|
shaderProgram->unbind();
|
||||||
|
}
|
||||||
|
|
||||||
DepthMap::DepthMap(int TYPE, int RESOLUTION) :
|
DepthMap::DepthMap(int TYPE, int RESOLUTION) :
|
||||||
cubeMap(RESOLUTION)
|
cubeMap(RESOLUTION)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public:
|
|||||||
{
|
{
|
||||||
return textures[0];
|
return textures[0];
|
||||||
}
|
}
|
||||||
|
void setExposureCorrection(bool exposureCorrection);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLuint FBO;
|
GLuint FBO;
|
||||||
|
|||||||
33
src/Screen.cpp
Normal file
33
src/Screen.cpp
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
21
src/Screen.h
Normal file
21
src/Screen.h
Normal file
@@ -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<Widget*> widgets;
|
||||||
|
};
|
||||||
@@ -48,7 +48,7 @@ void VertexArray::unbind()
|
|||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Vertex> VertexArray::createVertices(float *vertices, uint32_t numVertices, float *textureCoordinates) {
|
std::vector<Vertex> VertexArray::createVertices(double *vertices, uint32_t numVertices, float *textureCoordinates) {
|
||||||
std::vector<Vertex> vertexVec;
|
std::vector<Vertex> vertexVec;
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
uint32_t k = 0;
|
uint32_t k = 0;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public:
|
|||||||
void bind();
|
void bind();
|
||||||
void unbind();
|
void unbind();
|
||||||
|
|
||||||
static std::vector<Vertex> createVertices(float *vertices, uint32_t numVertices, float *textureCoordinates);
|
static std::vector<Vertex> createVertices(double *vertices, uint32_t numVertices, float *textureCoordinates);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLuint VAO;
|
GLuint VAO;
|
||||||
|
|||||||
46
src/Widget.cpp
Normal file
46
src/Widget.cpp
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
23
src/Widget.h
Normal file
23
src/Widget.h
Normal file
@@ -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<Vertex> widgetVertices;
|
||||||
|
std::vector<uint32_t> widgetIndices;
|
||||||
|
std::vector<Texture*> widgetTextures;
|
||||||
|
|
||||||
|
Mesh *widgetMesh;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user