Added sprite mesh

This commit is contained in:
Antoine Pilote
2023-08-01 18:50:04 -04:00
parent b69d71d0eb
commit e5603c5111
3 changed files with 29 additions and 8 deletions

View File

@@ -1,6 +1,9 @@
#include "SpriteComponent.h"
#include "src/Core/FileSystem.h"
#include "src/Rendering/Textures/TextureManager.h"
#include "src/Rendering/Textures/MaterialManager.h"
#include "src/Rendering/Vertex.h"
namespace Nuake
{
@@ -14,8 +17,22 @@ namespace Nuake
bool SpriteComponent::LoadSprite()
{
const auto texture = TextureManager::Get()->GetTexture(SpritePath);
Sprite = texture;
std::vector<Vertex> quadVertices =
{
{ Vector3(-1.0f, -1.0f, 0.0f), Vector2(0, 0), Vector3(0, 0, -1) },
{ Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f), Vector3(0, 0, -1) },
{ Vector3(-1.0f, 1.0f, 0.0f), Vector2(0.0f, 1.0f), Vector3(0, 0, -1) },
{ Vector3(1.0f, -1.0f, 0.0f), Vector2(1.0f, 0.0f), Vector3(0, 0, -1) },
{ Vector3(-1.0f, -1.0f, 0.0f), Vector2(0.0f, 0.0f), Vector3(0, 0, -1) },
{ Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f), Vector3(0, 0, -1) }
};
SpriteMesh = CreateRef<Mesh>();
SpriteMesh->AddSurface(quadVertices, { 0, 1, 2, 3, 4, 5 });
auto& material = MaterialManager::Get()->GetMaterial(FileSystem::Root + SpritePath);
SpriteMesh->SetMaterial(material);
return true;
}