renaming shaderDrawable to shaderDrawable 2d

This commit is contained in:
Clément Le Bihan
2021-06-08 16:10:20 +02:00
parent 7bff82a5c9
commit 3e9037ed92
4 changed files with 27 additions and 22 deletions
@@ -42,7 +42,7 @@ namespace BBM
{
}
ShaderComponentDrawable::ShaderComponentDrawable(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath)
ShaderComponentDrawable2D::ShaderComponentDrawable2D(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath)
: ShaderComponent(entity, std::move(fragmentFilePath), std::move(vertexFilePath))
{
}
@@ -62,17 +62,17 @@ namespace BBM
ShaderComponentModel &operator=(const ShaderComponentModel &) = delete;
};
class ShaderComponentDrawable : public ShaderComponent
class ShaderComponentDrawable2D : public ShaderComponent
{
public:
//! @brief ctor
//! @note use empty string to omit a file
ShaderComponentDrawable(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath = "");
ShaderComponentDrawable2D(WAL::Entity &entity, std::string fragmentFilePath, std::string vertexFilePath = "");
//! @brief Default copy ctor
ShaderComponentDrawable(const ShaderComponentDrawable &) = default;
ShaderComponentDrawable2D(const ShaderComponentDrawable2D &) = default;
//! @brief Default dtor
~ShaderComponentDrawable() override = default;
~ShaderComponentDrawable2D() override = default;
//! @brief Default assignment operator
ShaderComponentDrawable &operator=(const ShaderComponentDrawable &) = delete;
ShaderComponentDrawable2D &operator=(const ShaderComponentDrawable2D &) = delete;
};
}
+10 -6
View File
@@ -8,6 +8,7 @@
#include "System/Renderer/RenderSystem.hpp"
#include <Model/Model.hpp>
#include <Drawables/3D/Cube.hpp>
#include <Drawables/2D/Rectangle.hpp>
#include <TraceLog.hpp>
#include <System/Keyboard/KeyboardSystem.hpp>
#include <System/Controllable/ControllableSystem.hpp>
@@ -24,12 +25,14 @@
#include <Model/ModelAnimations.hpp>
#include <Component/Animator/AnimatorComponent.hpp>
#include <System/Animator/AnimatorSystem.hpp>
#include <Component/Renderer/Drawable2DComponent.hpp>
#include "Component/Animation/AnimationsComponent.hpp"
#include "System/Animation/AnimationsSystem.hpp"
#include "Component/Shaders/ShaderComponent.hpp"
#include "Map/Map.hpp"
namespace RAY3D = RAY::Drawables::Drawables3D;
namespace RAY2D = RAY::Drawables::Drawables2D;
namespace BBM
{
@@ -70,7 +73,7 @@ namespace BBM
.addComponent<ControllableComponent>()
.addComponent<AnimatorComponent>()
.addComponent<KeyboardComponent>()
.addComponent<ShaderComponentModel>("assets/shaders/glsl330/grayscale.fs")
.addComponent<ShaderComponentModel>("assets/shaders/glsl330/predator.fs")
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)
.addComponent<CollisionComponent>(1)
.addComponent<MovableComponent>()
@@ -81,15 +84,16 @@ namespace BBM
scene->addEntity("camera")
.addComponent<PositionComponent>(8, 20, 7)
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
scene->addEntity("cube")
/*scene->addEntity("cube")
.addComponent<PositionComponent>(5, 0, 5)
.addComponent<ShaderComponentDrawable>("assets/shaders/glsl330/grayscale.fs")
.addComponent<Drawable3DComponent, RAY3D::Cube>(Vector3f(-5, 0, -5), Vector3f(3, 3, 3), RED)
.addComponent<ShaderComponentDrawable2D>("assets/shaders/glsl330/grayscale.fs")
//.addComponent<Drawable3DComponent, RAY3D::Cube>(Vector3f(-5, 0, -5), Vector3f(3, 3, 3), RED)
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(BBM::Vector2f{200,200}, BBM::Vector2f{200, 200}, RED)
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>()
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, 3);
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, 3); */
std::srand(std::time(nullptr));
//MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene);
MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene);
return scene;
}
+11 -10
View File
@@ -30,33 +30,34 @@ namespace BBM
this->_window.clear();
this->_window.useCamera(this->_camera);
for (auto &[_, pos, drawable] : this->_wal.scene->view<PositionComponent, Drawable3DComponent>()) {
auto *modelShader = _.tryGetComponent<ShaderComponentModel>();
auto *shader = _.tryGetComponent<ShaderComponentModel>();
for (auto &[entity, pos, drawable] : this->_wal.scene->view<PositionComponent, Drawable3DComponent>()) {
auto *modelShader = entity.tryGetComponent<ShaderComponentModel>();
if (modelShader) {
auto &model = dynamic_cast<RAY::Drawables::Drawables3D::Model &>(*drawable.drawable);
model.setShader(modelShader->getShader());
}
if (shader) {
RAY::Shader::BeginUsingCustomShader(shader->getShader());
}
drawable.drawable->setPosition(pos.position);
drawable.drawable->drawOn(this->_window);
if (modelShader) {
auto &model = dynamic_cast<RAY::Drawables::Drawables3D::Model &>(*drawable.drawable);
model.resetShader();
}
if (shader) {
RAY::Shader::EndUsingCustomShader();
}
}
this->_window.unuseCamera();
// TODO sort entities based on the Z axis
for (auto &[_, pos, drawable] : this->_wal.scene->view<PositionComponent, Drawable2DComponent>()) {
for (auto &[entity, pos, drawable] : this->_wal.scene->view<PositionComponent, Drawable2DComponent>()) {
auto *shader = entity.tryGetComponent<ShaderComponentDrawable2D>();
if (shader) {
RAY::Shader::BeginUsingCustomShader(shader->getShader());
}
drawable.drawable->setPosition(Vector2f(pos.position.x, pos.position.y));
drawable.drawable->drawOn(this->_window);
if (shader) {
RAY::Shader::EndUsingCustomShader();
}
}
if (this->_debugMode)
this->_window.drawFPS(Vector2f());