Colors now working correcly.

This commit is contained in:
Tleety
2014-05-30 22:45:00 +02:00
parent ed803733da
commit 0e612cb3f3
6 changed files with 47 additions and 39 deletions
+2 -3
View File
@@ -4,16 +4,15 @@
#include <string> #include <string>
#include "Component.h" #include "Component.h"
#include "Color.h"
namespace Components namespace Components
{ {
struct Model : Component struct Model : Component
{ {
Model() : Visible(true), ShadowCaster(true), Transparent(false) { } Model() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)), Visible(true), ShadowCaster(true), Transparent(false) { }
std::string ModelFile; std::string ModelFile;
Color Color; glm::vec4 Color;
bool Visible; bool Visible;
bool ShadowCaster; bool ShadowCaster;
bool Transparent; bool Transparent;
+3 -2
View File
@@ -4,15 +4,16 @@
#include <string> #include <string>
#include "Component.h" #include "Component.h"
#include "Color.h"
namespace Components namespace Components
{ {
struct Sprite : Component struct Sprite : Component
{ {
Sprite() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)) { }
std::string SpriteFile; std::string SpriteFile;
Color Color; glm::vec4 Color;
virtual Sprite* Clone() const override { return new Sprite(*this); } virtual Sprite* Clone() const override { return new Sprite(*this); }
}; };
+2 -2
View File
@@ -25,13 +25,13 @@ public:
vp1->X = 0; vp1->X = 0;
vp1->Width = 640; vp1->Width = 640;
vp1->Height = 720 / 2; vp1->Height = 720 / 2;
new PlayerHUD(vp1, "PlayerHUD", m_World, 1); //new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
vp2 = new Viewport(worldFrame, "Viewport2", m_World); vp2 = new Viewport(worldFrame, "Viewport2", m_World);
vp2->X = vp1->Right(); vp2->X = vp1->Right();
vp2->Width = 640; vp2->Width = 640;
vp2->Height = 720 / 2; vp2->Height = 720 / 2;
new PlayerHUD(vp2, "PlayerHUD", m_World, 2); //new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
auto vpc = new Viewport(worldFrame, "ViewportFreeCam", m_World); auto vpc = new Viewport(worldFrame, "ViewportFreeCam", m_World);
vpc->Y = 720 / 2; vpc->Y = 720 / 2;
+14 -7
View File
@@ -44,6 +44,10 @@ public:
{ {
EntityID entity = pair.first; EntityID entity = pair.first;
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
if (templateComponent)
continue;
auto transform = m_World->GetComponent<Components::Transform>(entity); auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!transform) if (!transform)
continue; continue;
@@ -78,12 +82,11 @@ public:
float textureRepeat = blendmapComponent->TextureRepeats; float textureRepeat = blendmapComponent->TextureRepeats;
EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix); EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix, modelComponent->Color);
} }
else else
{ {
float transparent = modelComponent->Transparent; EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color);
EnqueueModel(modelAsset, modelMatrix, transparent);
} }
} }
@@ -100,7 +103,7 @@ public:
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position) glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
* glm::toMat4(orientation2D) * glm::toMat4(orientation2D)
* glm::scale(absoluteTransform.Scale); * glm::scale(absoluteTransform.Scale);
EnqueueSprite(textureAsset, modelMatrix); EnqueueSprite(textureAsset, modelMatrix, spriteComponent->Color);
} }
} }
@@ -152,7 +155,7 @@ private:
std::shared_ptr<Systems::TransformSystem> m_TransformSystem; std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent) void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color)
{ {
for (auto texGroup : model->TextureGroups) for (auto texGroup : model->TextureGroups)
{ {
@@ -166,6 +169,8 @@ private:
job.EndIndex = texGroup.EndIndex; job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix; job.ModelMatrix = modelMatrix;
job.Transparent = transparent; job.Transparent = transparent;
job.Color = color;
if(job.Transparent) if(job.Transparent)
{ {
RenderQueue.Forward.Add(job); RenderQueue.Forward.Add(job);
@@ -177,7 +182,7 @@ private:
} }
} }
void EnqueueBlendMapModel(Model* model, BlendMapTexture textureRed, BlendMapTexture textureGreen, BlendMapTexture textureBlue, float textureRepeat, glm::mat4 modelMatrix) void EnqueueBlendMapModel(Model* model, BlendMapTexture textureRed, BlendMapTexture textureGreen, BlendMapTexture textureBlue, float textureRepeat, glm::mat4 modelMatrix, glm::vec4 color)
{ {
for (auto texGroup : model->TextureGroups) for (auto texGroup : model->TextureGroups)
{ {
@@ -200,17 +205,19 @@ private:
job.StartIndex = texGroup.StartIndex; job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex; job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix; job.ModelMatrix = modelMatrix;
job.Color = color;
RenderQueue.Deferred.Add(job); RenderQueue.Deferred.Add(job);
} }
} }
void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix) void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix, glm::vec4 color)
{ {
SpriteJob job; SpriteJob job;
job.TextureID = texture->ResourceID; job.TextureID = texture->ResourceID;
job.Texture = *texture; job.Texture = *texture;
job.ModelMatrix = modelMatrix; job.ModelMatrix = modelMatrix;
job.Color = color;
RenderQueue.Forward.Add(job); RenderQueue.Forward.Add(job);
} }
+20 -16
View File
@@ -750,14 +750,16 @@ EntityID GameWorld::CreateTank(int playerID)
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
CommitEntity(entity); CommitEntity(entity);
auto particleEntity = CreateEntity(entity); {
auto TEMP = AddComponent<Components::Transform>(particleEntity); auto particleEntity = CreateEntity(entity);
TEMP->Scale = glm::vec3(0); auto templateComponent = AddComponent<Components::Template>(particleEntity);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity); auto TEMP = AddComponent<Components::Transform>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; TEMP->Scale = glm::vec3(0);
emitterComponent->ParticleTemplate = particleEntity; auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
CommitEntity(particleEntity); CommitEntity(particleEntity);
emitterComponent->ParticleTemplate = particleEntity;
}
} }
{ {
@@ -835,14 +837,16 @@ EntityID GameWorld::CreateTank(int playerID)
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
CommitEntity(entity); CommitEntity(entity);
auto particleEntity = CreateEntity(entity); {
auto TEMP = AddComponent<Components::Transform>(particleEntity); auto particleEntity = CreateEntity(entity);
TEMP->Scale = glm::vec3(0); auto templateComponent = AddComponent<Components::Template>(particleEntity);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity); auto TEMP = AddComponent<Components::Transform>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; TEMP->Scale = glm::vec3(0);
emitterComponent->ParticleTemplate = particleEntity; auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
CommitEntity(particleEntity); CommitEntity(particleEntity);
emitterComponent->ParticleTemplate = particleEntity;
}
} }
CommitEntity(tank); CommitEntity(tank);
+6 -9
View File
@@ -490,7 +490,7 @@ void Renderer::ForwardRendering(RenderQueue &rq)
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection)); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(modelJob->Color)); glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
glBindVertexArray(modelJob->VAO); glBindVertexArray(modelJob->VAO);
@@ -514,11 +514,11 @@ void Renderer::ForwardRendering(RenderQueue &rq)
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job); auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (spriteJob) if (spriteJob)
{ {
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(spriteJob->Color)); glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, spriteJob->Texture); glBindTexture(GL_TEXTURE_2D, spriteJob->Texture);
@@ -557,8 +557,6 @@ void Renderer::ForwardRendering(RenderQueue &rq)
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_TRIANGLES, 0, 6);
//for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender //for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender
//{ //{
// Model* model; // Model* model;
@@ -589,7 +587,6 @@ void Renderer::Swap()
glfwSwapBuffers(m_Window); glfwSwapBuffers(m_Window);
} }
void Renderer::DrawSkybox() void Renderer::DrawSkybox()
{ {
//glBindFramebuffer(GL_FRAMEBUFFER, 0); //glBindFramebuffer(GL_FRAMEBUFFER, 0);