diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 7d25c46..801cd6e 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -104,14 +104,17 @@ void GameWorld::Initialize() emitter->SpawnCount = 1; emitter->SpreadAngle = glm::pi()/20; emitter->SpawnFrequency = 1.008; + emitter->ScaleSpectrum.push_back(glm::vec3(1)); + emitter->ScaleSpectrum.push_back(glm::vec3(0)); auto model = AddComponent(ent, "Model"); model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj"; auto particleEnt = CreateEntity(); AddComponent(particleEnt, "Transform"); - model = AddComponent(particleEnt, "Model"); - model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj"; - +// model = AddComponent(particleEnt, "Model"); +// model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj"; + auto spriteComponent = AddComponent(particleEnt, "Sprite"); + spriteComponent->SpriteFile = "Textures/Sprites/SeriousParticle.png"; emitter->ParticleTemplate = particleEnt; } } diff --git a/src/Renderer.cpp b/src/Renderer.cpp index e7dfed6..c8cf06e 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -267,6 +267,29 @@ void Renderer::DrawScene() } } + for (auto tuple : TexturesToRender) + { + Texture* texture; + glm::mat4 modelMatrix; + std::tie(texture, modelMatrix) = tuple; + + //MVP = m_Camera->ProjectionMatrix() * glm::translate(glm::mat4(), m_Camera->Position()) * modelMatrix; + MVP = cameraMatrix * glm::inverse(glm::toMat4(m_Camera->Orientation())) * modelMatrix ; + depthMVP = depthCameraMatrix * modelMatrix; + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP)); + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, *texture); + glBindVertexArray(m_ScreenQuad); + glDrawArrays(GL_TRIANGLES, 0, 6); + } + + + + #ifdef DEBUG // Debug draw model normals if (m_DrawNormals) @@ -318,6 +341,8 @@ void Renderer::DrawShadowMap() glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); } } + + } void Renderer::DrawDebugShadowMap() @@ -376,6 +401,12 @@ void Renderer::AddModelToDraw(Model* model, glm::vec3 position, glm::quat orient ModelsToRender.push_back(std::make_tuple(model, modelMatrix, visible, shadowCaster)); } +void Renderer::AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat orientation, glm::vec3 scale) +{ + glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale); + TexturesToRender.push_back(std::make_tuple(texture, modelMatrix)); +} + void Renderer::AddPointLightToDraw( glm::vec3 _position, glm::vec3 _specular, @@ -536,6 +567,7 @@ void Renderer::ClearStuff() { AABBsToRender.clear(); ModelsToRender.clear(); + TexturesToRender.clear(); Light_position.clear(); Light_specular.clear(); Light_diffuse.clear(); diff --git a/src/Renderer.h b/src/Renderer.h index 8d0da1f..7d00b13 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -23,6 +23,7 @@ public: int HEIGHT, WIDTH; std::list> ModelsToRender; + std::list> TexturesToRender; int Lights; std::vector Light_position; std::vector Light_specular; @@ -40,6 +41,7 @@ public: void DrawText(); void AddModelToDraw(Model* model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible, bool shadowCaster); + void AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat orientation, glm::vec3 scale); void AddTextToDraw(); void AddPointLightToDraw( glm::vec3 _position, diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index 48a1a91..660e39c 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -111,7 +111,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) auto particle = m_World->AddComponent(ent, "Particle"); particle->LifeTime = emitterComponent->LifeTime; - particle->ScaleSpectrum.push_back(glm::vec3(1)); //TEMP + particle->ScaleSpectrum = emitterComponent->ScaleSpectrum; //TEMP //particle->ScaleSpectrum.push_back(glm::vec3(1,4,1)); //TEMP particle->VelocitySpectrum.push_back(particleTransform->Velocity); //TEMP particle->VelocitySpectrum.push_back(testVel); //TEMP diff --git a/src/Systems/RenderSystem.cpp b/src/Systems/RenderSystem.cpp index 9e2b426..d2102d1 100755 --- a/src/Systems/RenderSystem.cpp +++ b/src/Systems/RenderSystem.cpp @@ -55,6 +55,17 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa m_Renderer->GetCamera()->NearClip(cameraComponent->NearClip); m_Renderer->GetCamera()->FarClip(cameraComponent->FarClip); } + + auto spriteComponent = m_World->GetComponent(entity, "Sprite"); + if(spriteComponent != nullptr) + { + //TEMP + Texture* texture = m_World->GetResourceManager()->Load("Texture", spriteComponent->SpriteFile); + //glBindTexture(GL_TEXTURE_2D, texture); + auto transform = m_World->GetComponent(spriteComponent->Entity, "Transform"); + glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1)); + m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale); + } } void Systems::RenderSystem::Initialize()