Add loading screen

This commit is contained in:
2021-01-09 20:15:01 +01:00
parent 23e5f549ca
commit 6ecf2011bc
10 changed files with 106 additions and 10 deletions

View File

@@ -9,7 +9,7 @@ Size=894,195
Collapsed=0
[Window][Debug Utils]
Pos=12,15
Pos=13,7
Size=871,365
Collapsed=0

15
res/shaders/menu.frag Normal file
View File

@@ -0,0 +1,15 @@
#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);
}

12
res/shaders/menu.vert Normal file
View File

@@ -0,0 +1,12 @@
#version 330 core
layout(location = 0) in vec3 a_position;
layout(location = 2) in vec2 a_texCoord;
out vec2 v_texCoord;
void main()
{
v_texCoord = a_texCoord;
gl_Position = vec4(a_position, 1.0);
}

View File

@@ -20,6 +20,7 @@
#endif
#include "Controller.h"
#include "VertexArray.h"
#include "Texture.h"
#include "Model.h"
#include "Entity.h"
@@ -84,10 +85,30 @@ void Controller::run()
ShaderProgram lightProgram("res/shaders/light.vert", "res/shaders/light.frag");
ShaderProgram skyboxProgram("res/shaders/skybox.vert", "res/shaders/skybox.frag");
ShaderProgram postProcessingProgram("res/shaders/postprocessing.vert", "res/shaders/postprocessing.frag");
ShaderProgram menuProgram("res/shaders/menu.vert", "res/shaders/menu.frag");
ShaderProgram directionalShadowDepthProgram("res/shaders/directionalShadowDepth.vert", "res/shaders/directionalShadowDepth.frag");
ShaderProgram pointShadowDepthProgram("res/shaders/pointShadowDepth.vert", "res/shaders/pointShadowDepth.geom", "res/shaders/pointShadowDepth.frag");
updateExposure(&postProcessingProgram);
pp_framebuffer = new Framebuffer(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT, &postProcessingProgram);
// Show loading screen...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Texture loadingScreenTex("res/textures/loading.png", textureType::texture_diffuse);
std::vector<Vertex> loadingScreenVertices = VertexArray::createVertices(loadingScreenVerticesData, 12, loadingScreenTextureCoordinates);
std::vector<uint32_t> loadingScreenIndices;
std::vector<Texture*> 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();
glfwSwapBuffers(gameWindow->getGLFWwindow());
//Model model_backpack("res/models/backpack.ffo");
Model model_cube("res/models/cube.ffo");
@@ -114,8 +135,6 @@ void Controller::run()
camera->translate(glm::vec3(0.0f, 1.5f, 5.0f));
pp_framebuffer = new Framebuffer(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT, &postProcessingProgram);
// This is the game loop
while (!glfwWindowShouldClose(gameWindow->getGLFWwindow())) {
// --- Timing ---
@@ -141,17 +160,20 @@ void Controller::run()
lightProgram.unbind();
// --- Render and buffer swap ---
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Calc shadows
static bool drawShadows = true;
static bool drawShadows = false;
static bool firstRun = true;
shaderProgram.bind();
shaderProgram.setUniform("b_drawShadows", (int)drawShadows);
shaderProgram.unbind();
if (drawShadows) {
if (drawShadows || firstRun) {
firstRun = false;
world.calculateShadows(&directionalShadowDepthProgram, &pointShadowDepthProgram);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
pp_framebuffer->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

View File

@@ -42,4 +42,21 @@ 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
};
};

View File

@@ -45,7 +45,7 @@ void Framebuffer::unbind()
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void Framebuffer::render()
void Framebuffer::render(GLuint customTextureId)
{
// Disable wireframe mode
GLint wireframe;
@@ -54,7 +54,11 @@ void Framebuffer::render()
shaderProgram->bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTextureId());
if(customTextureId) {
glBindTexture(GL_TEXTURE_2D, customTextureId);
} else {
glBindTexture(GL_TEXTURE_2D, getTextureId());
}
GLint location = glGetUniformLocation(shaderProgram->getShaderProgramId(), "u_texture");
glUniform1i(location, 0);

View File

@@ -13,7 +13,7 @@ public:
void bind();
void unbind();
void render();
void render(GLuint customTextureId = 0);
GLuint getTextureId()
{

View File

@@ -29,6 +29,10 @@ public:
{
return texturePath;
}
GLuint getTextureId()
{
return textureId;
}
private:
std::string texturePath;

View File

@@ -1,4 +1,5 @@
#include <cstddef>
#include <vector>
#include "VertexArray.h"
#include "defines.h"
@@ -46,3 +47,20 @@ void VertexArray::unbind()
{
glBindVertexArray(0);
}
std::vector<Vertex> VertexArray::createVertices(float *vertices, uint32_t numVertices, float *textureCoordinates) {
std::vector<Vertex> vertexVec;
uint32_t i = 0;
uint32_t k = 0;
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.textureCoords.x = textureCoordinates[k];
currentVertex.textureCoords.y = textureCoordinates[k+1];
k+=2;
vertexVec.push_back(currentVertex);
}
return vertexVec;
}

View File

@@ -2,6 +2,8 @@
#include <glad/glad.h>
#include "defines.h"
class VertexArray
{
public:
@@ -10,6 +12,8 @@ public:
void bind();
void unbind();
static std::vector<Vertex> createVertices(float *vertices, uint32_t numVertices, float *textureCoordinates);
private:
GLuint VAO;