Rendering sprites
This commit is contained in:
+6
-3
@@ -104,14 +104,17 @@ void GameWorld::Initialize()
|
||||
emitter->SpawnCount = 1;
|
||||
emitter->SpreadAngle = glm::pi<float>()/20;
|
||||
emitter->SpawnFrequency = 1.008;
|
||||
emitter->ScaleSpectrum.push_back(glm::vec3(1));
|
||||
emitter->ScaleSpectrum.push_back(glm::vec3(0));
|
||||
auto model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
||||
|
||||
auto particleEnt = CreateEntity();
|
||||
AddComponent<Components::Transform>(particleEnt, "Transform");
|
||||
model = AddComponent<Components::Model>(particleEnt, "Model");
|
||||
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
||||
|
||||
// model = AddComponent<Components::Model>(particleEnt, "Model");
|
||||
// model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
||||
auto spriteComponent = AddComponent<Components::Sprite>(particleEnt, "Sprite");
|
||||
spriteComponent->SpriteFile = "Textures/Sprites/SeriousParticle.png";
|
||||
emitter->ParticleTemplate = particleEnt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
int HEIGHT, WIDTH;
|
||||
|
||||
std::list<std::tuple<Model*, glm::mat4, bool, bool>> ModelsToRender;
|
||||
std::list<std::tuple<Texture*, glm::mat4>> TexturesToRender;
|
||||
int Lights;
|
||||
std::vector<float> Light_position;
|
||||
std::vector<float> 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,
|
||||
|
||||
@@ -111,7 +111,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
|
||||
|
||||
auto particle = m_World->AddComponent<Components::Particle>(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
|
||||
|
||||
@@ -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<Components::Sprite>(entity, "Sprite");
|
||||
if(spriteComponent != nullptr)
|
||||
{
|
||||
//TEMP
|
||||
Texture* texture = m_World->GetResourceManager()->Load<Texture>("Texture", spriteComponent->SpriteFile);
|
||||
//glBindTexture(GL_TEXTURE_2D, texture);
|
||||
auto transform = m_World->GetComponent<Components::Transform>(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()
|
||||
|
||||
Reference in New Issue
Block a user