Text component added and Text render queue
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include "../GLM.h"
|
#include "../GLM.h"
|
||||||
#include "../Core/Util/Rectangle.h"
|
#include "../Core/Util/Rectangle.h"
|
||||||
#include "../Core/Entity.h"
|
#include "../Core/Entity.h"
|
||||||
|
#include "Font.h"
|
||||||
|
|
||||||
class Model;
|
class Model;
|
||||||
class Skeleton;
|
class Skeleton;
|
||||||
@@ -80,6 +81,19 @@ struct SpriteJob : RenderJob
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct TextJob : RenderJob
|
||||||
|
{
|
||||||
|
glm::mat4 ModelMatrix;
|
||||||
|
glm::vec4 Color;
|
||||||
|
std::string Content;
|
||||||
|
Font* Resource;
|
||||||
|
|
||||||
|
void CalculateHash() override
|
||||||
|
{
|
||||||
|
Hash = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct PointLightJob : RenderJob
|
struct PointLightJob : RenderJob
|
||||||
{
|
{
|
||||||
glm::vec3 Position;
|
glm::vec3 Position;
|
||||||
@@ -137,17 +151,20 @@ struct RenderQueueCollection
|
|||||||
{
|
{
|
||||||
RenderQueue Forward;
|
RenderQueue Forward;
|
||||||
RenderQueue Lights;
|
RenderQueue Lights;
|
||||||
|
RenderQueue Text;
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
Forward.Clear();
|
Forward.Clear();
|
||||||
Lights.Clear();
|
Lights.Clear();
|
||||||
|
Text.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sort()
|
void Sort()
|
||||||
{
|
{
|
||||||
Forward.Sort();
|
Forward.Sort();
|
||||||
Lights.Sort();
|
Lights.Sort();
|
||||||
|
Text.Sort();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ private:
|
|||||||
|
|
||||||
void FillModels(World* world, RenderQueue* renderQueue);
|
void FillModels(World* world, RenderQueue* renderQueue);
|
||||||
void FillLights(World* world, RenderQueue* renderQueue);
|
void FillLights(World* world, RenderQueue* renderQueue);
|
||||||
|
void FillText(World* world, RenderQueue* renderQueue);
|
||||||
|
|
||||||
glm::mat4 ModelMatrix(World* world, EntityID entity);
|
glm::mat4 ModelMatrix(World* world, EntityID entity);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "ShaderProgram.h"
|
#include "ShaderProgram.h"
|
||||||
#include "Font.h"
|
#include "Font.h"
|
||||||
#include "../Core/ResourceManager.h"
|
#include "../Core/ResourceManager.h"
|
||||||
|
#include "RenderQueue.h"
|
||||||
|
|
||||||
class TextRenderer
|
class TextRenderer
|
||||||
{
|
{
|
||||||
@@ -16,14 +17,14 @@ public:
|
|||||||
TextRenderer();
|
TextRenderer();
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Update();
|
void Update();
|
||||||
void Draw(glm::mat4 projection, glm::mat4 view);
|
void Draw(RenderQueue &rq, glm::mat4 projection, glm::mat4 view);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Font* font;
|
Font* font;
|
||||||
|
|
||||||
GLuint VAO, VBO;
|
GLuint VAO, VBO;
|
||||||
|
|
||||||
void RenderText(std::string text, GLfloat x, GLfloat y, GLfloat scale, glm::vec3 color, glm::mat4 projection, glm::mat4 view);
|
void RenderText(std::string text, Font* font, GLfloat scale, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix);
|
||||||
|
|
||||||
ShaderProgram m_TextProgram;
|
ShaderProgram m_TextProgram;
|
||||||
|
|
||||||
|
|||||||
@@ -5,4 +5,5 @@
|
|||||||
<xs:include schemaLocation="Components/Model.xsd"/>
|
<xs:include schemaLocation="Components/Model.xsd"/>
|
||||||
<xs:include schemaLocation="Components/Test.xsd"/>
|
<xs:include schemaLocation="Components/Test.xsd"/>
|
||||||
<xs:include schemaLocation="Components/RaptorCopter.xsd"/>
|
<xs:include schemaLocation="Components/RaptorCopter.xsd"/>
|
||||||
|
<xs:include schemaLocation="Components/Text.xsd"/>
|
||||||
</xs:schema>
|
</xs:schema>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<c:Text>
|
||||||
|
<Content></Content>
|
||||||
|
<Resource></Resource>
|
||||||
|
<Color R="1" G="1" B="1" A="1"/>
|
||||||
|
<Visible>true</Visible>
|
||||||
|
</c:Text>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||||
|
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||||
|
|
||||||
|
<xs:element name="Text">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>A visible font loaded from disk</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:all>
|
||||||
|
<xs:element name="Content" type="t:string" minOccurs="0">
|
||||||
|
<xs:annotation><xs:documentation>the content of the string printed</xs:documentation></xs:annotation>
|
||||||
|
</xs:element>
|
||||||
|
<xs:element name="Resource" type="t:string" minOccurs="0">
|
||||||
|
<xs:annotation><xs:documentation>font file</xs:documentation></xs:annotation>
|
||||||
|
</xs:element>
|
||||||
|
<xs:element name="Color" type="t:Color" minOccurs="0">
|
||||||
|
<xs:annotation><xs:documentation>Color</xs:documentation></xs:annotation>
|
||||||
|
</xs:element>
|
||||||
|
<xs:element name="Visible" type="t:bool" minOccurs="0">
|
||||||
|
<xs:annotation><xs:documentation>Wether the text is visible or not</xs:documentation></xs:annotation>
|
||||||
|
</xs:element>
|
||||||
|
</xs:all>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
@@ -21,6 +21,17 @@
|
|||||||
</c:Model>
|
</c:Model>
|
||||||
</Components>
|
</Components>
|
||||||
</Entity>
|
</Entity>
|
||||||
|
<Entity>
|
||||||
|
<Components>
|
||||||
|
<c:Transform>
|
||||||
|
<Scale X="1" Y="1" Z="1"/>
|
||||||
|
</c:Transform>
|
||||||
|
<c:Text>
|
||||||
|
<Resource>Fonts/arial.ttf</Resource>
|
||||||
|
<Content>Hej I am component text</Content>
|
||||||
|
</c:Text>
|
||||||
|
</Components>
|
||||||
|
</Entity>
|
||||||
<Entity>
|
<Entity>
|
||||||
<Components>
|
<Components>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
<xs:element ref="c:Model" minOccurs="0"/>
|
<xs:element ref="c:Model" minOccurs="0"/>
|
||||||
<xs:element ref="c:Test" minOccurs="0"/>
|
<xs:element ref="c:Test" minOccurs="0"/>
|
||||||
<xs:element ref="c:RaptorCopter" minOccurs="0"/>
|
<xs:element ref="c:RaptorCopter" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:Text" minOccurs="0"/>
|
||||||
</xs:all>
|
</xs:all>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ Font::Font(std::string path)
|
|||||||
if (FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
if (FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
printf("Char: %c\n", c);
|
|
||||||
//Generate texture
|
//Generate texture
|
||||||
GLuint texture;
|
GLuint texture;
|
||||||
glGenTextures(1, &texture);
|
glGenTextures(1, &texture);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ void RenderQueueFactory::Update(World* world)
|
|||||||
m_RenderQueues.Clear();
|
m_RenderQueues.Clear();
|
||||||
FillModels(world, &m_RenderQueues.Forward);
|
FillModels(world, &m_RenderQueues.Forward);
|
||||||
FillLights(world, &m_RenderQueues.Lights);
|
FillLights(world, &m_RenderQueues.Lights);
|
||||||
|
FillText(world, &m_RenderQueues.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 RenderQueueFactory::ModelMatrix(World* world, EntityID entity)
|
glm::mat4 RenderQueueFactory::ModelMatrix(World* world, EntityID entity)
|
||||||
@@ -71,6 +72,9 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto& modelC : *models) {
|
for (auto& modelC : *models) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string resource = modelC["Resource"];
|
std::string resource = modelC["Resource"];
|
||||||
if (resource.empty()) {
|
if (resource.empty()) {
|
||||||
continue;
|
continue;
|
||||||
@@ -103,3 +107,32 @@ void RenderQueueFactory::FillLights(World* world, RenderQueue* renderQueue)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderQueueFactory::FillText(World* world, RenderQueue* renderQueue)
|
||||||
|
{
|
||||||
|
auto texts = world->GetComponents("Text");
|
||||||
|
if (texts == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& textC : *texts) {
|
||||||
|
|
||||||
|
|
||||||
|
std::string resource = textC["Resource"];
|
||||||
|
if (resource.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Font* font = ResourceManager::Load<Font>(resource);
|
||||||
|
|
||||||
|
glm::vec4 color = textC["Color"];
|
||||||
|
std::string content = textC["Content"];
|
||||||
|
|
||||||
|
TextJob job;
|
||||||
|
job.Color = color;
|
||||||
|
job.Content = content;
|
||||||
|
job.Resource = font;
|
||||||
|
job.ModelMatrix = ModelMatrix(world, textC.EntityID);
|
||||||
|
|
||||||
|
renderQueue->Add(job);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ void Renderer::Draw(RenderQueueCollection& rq)
|
|||||||
// DrawScreenQuad(m_PickingTexture);
|
// DrawScreenQuad(m_PickingTexture);
|
||||||
|
|
||||||
DrawScene(rq);
|
DrawScene(rq);
|
||||||
m_TextRenderer->Draw(m_Camera->ProjectionMatrix(), m_Camera->ViewMatrix());
|
m_TextRenderer->Draw(rq.Text,m_Camera->ProjectionMatrix(), m_Camera->ViewMatrix());
|
||||||
glfwSwapBuffers(m_Window);
|
glfwSwapBuffers(m_Window);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,6 +272,7 @@ void Renderer::PickingPass(RenderQueueCollection& rq)
|
|||||||
|
|
||||||
m_EventBroker->Publish(pickEvent);
|
m_EventBroker->Publish(pickEvent);
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ TextRenderer::TextRenderer()
|
|||||||
|
|
||||||
void TextRenderer::Initialize()
|
void TextRenderer::Initialize()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glGenVertexArrays(1, &VAO);
|
glGenVertexArrays(1, &VAO);
|
||||||
glGenBuffers(1, &VBO);
|
glGenBuffers(1, &VBO);
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
@@ -22,8 +17,6 @@ void TextRenderer::Initialize()
|
|||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m_TextProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Text.vert.glsl")));
|
m_TextProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Text.vert.glsl")));
|
||||||
m_TextProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Text.frag.glsl")));
|
m_TextProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Text.frag.glsl")));
|
||||||
m_TextProgram.Compile();
|
m_TextProgram.Compile();
|
||||||
@@ -35,40 +28,33 @@ void TextRenderer::Update()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextRenderer::Draw(glm::mat4 projection, glm::mat4 view)
|
void TextRenderer::Draw(RenderQueue &rq, glm::mat4 projection, glm::mat4 view)
|
||||||
{
|
{
|
||||||
if(counter > 2) {
|
for (auto &job : rq) {
|
||||||
if (text == "") {
|
auto textJob = std::dynamic_pointer_cast<TextJob>(job);
|
||||||
text = text + "~wub ";
|
if (textJob) {
|
||||||
} else if (text == "~wub ") {
|
RenderText(textJob->Content, textJob->Resource, 0.01f, textJob->Color, textJob->ModelMatrix, projection, view);
|
||||||
text = text + "wub ";
|
|
||||||
} else if (text == "~wub wub ") {
|
|
||||||
text = "";
|
|
||||||
}
|
}
|
||||||
counter = 0;
|
|
||||||
} else {
|
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderText(text, 0.f, 0.f, 1.0f, glm::vec3(1.f, 1.f, 1.f), projection, view);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextRenderer::RenderText(std::string text, GLfloat x, GLfloat y, GLfloat scale, glm::vec3 color, glm::mat4 projection, glm::mat4 view)
|
void TextRenderer::RenderText(std::string text, Font* font, GLfloat scale, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix)
|
||||||
{
|
{
|
||||||
font = ResourceManager::Load<Font>("fonts/arial.ttf");
|
GLfloat x = 0;
|
||||||
|
GLfloat y = 0;
|
||||||
|
|
||||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(), glm::vec3(0.5f, 0.3f, 0.f)) * glm::toMat4(glm::quat()) * glm::scale(glm::vec3(0.01f));
|
|
||||||
|
|
||||||
// Activate corresponding render state
|
// Activate corresponding render state
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
m_TextProgram.Bind();
|
m_TextProgram.Bind();
|
||||||
glUniform3f(glGetUniformLocation(m_TextProgram.GetHandle(), "textColor"), color.x, color.y, color.z);
|
glUniform3f(glGetUniformLocation(m_TextProgram.GetHandle(), "textColor"), color.x, color.y, color.z);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(view));
|
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(projection));
|
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix));
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user