From 0e612cb3f3d6df721729abf80313b1a8ec23a7a4 Mon Sep 17 00:00:00 2001 From: Tleety Date: Fri, 30 May 2014 22:45:00 +0200 Subject: [PATCH] Colors now working correcly. --- src/Components/Model.h | 5 ++--- src/Components/Sprite.h | 5 +++-- src/GUI/GameFrame.h | 4 ++-- src/GUI/WorldFrame.h | 21 ++++++++++++++------- src/GameWorld.cpp | 36 ++++++++++++++++++++---------------- src/Renderer.cpp | 15 ++++++--------- 6 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/Components/Model.h b/src/Components/Model.h index 7c116d4..7ac792f 100755 --- a/src/Components/Model.h +++ b/src/Components/Model.h @@ -4,16 +4,15 @@ #include #include "Component.h" -#include "Color.h" namespace Components { 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; - Color Color; + glm::vec4 Color; bool Visible; bool ShadowCaster; bool Transparent; diff --git a/src/Components/Sprite.h b/src/Components/Sprite.h index 29c930f..d28f058 100755 --- a/src/Components/Sprite.h +++ b/src/Components/Sprite.h @@ -4,15 +4,16 @@ #include #include "Component.h" -#include "Color.h" namespace Components { struct Sprite : Component { + Sprite() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)) { } + std::string SpriteFile; - Color Color; + glm::vec4 Color; virtual Sprite* Clone() const override { return new Sprite(*this); } }; diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index 8286997..d99bc64 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -25,13 +25,13 @@ public: vp1->X = 0; vp1->Width = 640; 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->X = vp1->Right(); vp2->Width = 640; 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); vpc->Y = 720 / 2; diff --git a/src/GUI/WorldFrame.h b/src/GUI/WorldFrame.h index a0c76e8..5aa3746 100644 --- a/src/GUI/WorldFrame.h +++ b/src/GUI/WorldFrame.h @@ -44,6 +44,10 @@ public: { EntityID entity = pair.first; + auto templateComponent = m_World->GetComponent(entity); + if (templateComponent) + continue; + auto transform = m_World->GetComponent(entity); if (!transform) continue; @@ -78,12 +82,11 @@ public: float textureRepeat = blendmapComponent->TextureRepeats; - EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix); + EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix, modelComponent->Color); } else { - float transparent = modelComponent->Transparent; - EnqueueModel(modelAsset, modelMatrix, transparent); + EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color); } } @@ -100,7 +103,7 @@ public: glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position) * glm::toMat4(orientation2D) * glm::scale(absoluteTransform.Scale); - EnqueueSprite(textureAsset, modelMatrix); + EnqueueSprite(textureAsset, modelMatrix, spriteComponent->Color); } } @@ -152,7 +155,7 @@ private: std::shared_ptr 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) { @@ -166,6 +169,8 @@ private: job.EndIndex = texGroup.EndIndex; job.ModelMatrix = modelMatrix; job.Transparent = transparent; + job.Color = color; + if(job.Transparent) { 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) { @@ -200,17 +205,19 @@ private: job.StartIndex = texGroup.StartIndex; job.EndIndex = texGroup.EndIndex; job.ModelMatrix = modelMatrix; + job.Color = color; RenderQueue.Deferred.Add(job); } } - void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix) + void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix, glm::vec4 color) { SpriteJob job; job.TextureID = texture->ResourceID; job.Texture = *texture; job.ModelMatrix = modelMatrix; + job.Color = color; RenderQueue.Forward.Add(job); } diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 3f2d2b9..27fa9fd 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -750,14 +750,16 @@ EntityID GameWorld::CreateTank(int playerID) emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); CommitEntity(entity); - auto particleEntity = CreateEntity(entity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - emitterComponent->ParticleTemplate = particleEntity; - - CommitEntity(particleEntity); + { + auto particleEntity = CreateEntity(entity); + auto templateComponent = AddComponent(particleEntity); + auto TEMP = AddComponent(particleEntity); + TEMP->Scale = glm::vec3(0); + auto spriteComponent = AddComponent(particleEntity); + spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; + CommitEntity(particleEntity); + emitterComponent->ParticleTemplate = particleEntity; + } } { @@ -835,14 +837,16 @@ EntityID GameWorld::CreateTank(int playerID) emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); CommitEntity(entity); - auto particleEntity = CreateEntity(entity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - emitterComponent->ParticleTemplate = particleEntity; - - CommitEntity(particleEntity); + { + auto particleEntity = CreateEntity(entity); + auto templateComponent = AddComponent(particleEntity); + auto TEMP = AddComponent(particleEntity); + TEMP->Scale = glm::vec3(0); + auto spriteComponent = AddComponent(particleEntity); + spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; + CommitEntity(particleEntity); + emitterComponent->ParticleTemplate = particleEntity; + } } CommitEntity(tank); diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 1476306..1ce74aa 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -490,7 +490,7 @@ void Renderer::ForwardRendering(RenderQueue &rq) 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, "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); @@ -514,11 +514,11 @@ void Renderer::ForwardRendering(RenderQueue &rq) auto spriteJob = std::dynamic_pointer_cast(job); if (spriteJob) { - glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "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(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); - glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); - glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(spriteJob->Color)); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(spriteJob->Color)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, spriteJob->Texture); @@ -557,8 +557,6 @@ void Renderer::ForwardRendering(RenderQueue &rq) glEnableVertexAttribArray(0); glDrawArrays(GL_TRIANGLES, 0, 6); - - //for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender //{ // Model* model; @@ -589,7 +587,6 @@ void Renderer::Swap() glfwSwapBuffers(m_Window); } - void Renderer::DrawSkybox() { //glBindFramebuffer(GL_FRAMEBUFFER, 0);