diff --git a/res/card_backside.png b/res/card_backside.png new file mode 100644 index 0000000..b1c23c0 Binary files /dev/null and b/res/card_backside.png differ diff --git a/src/Application.cpp b/src/Application.cpp index 1cd258e..71bf0a9 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -71,11 +71,15 @@ Application::Application() : lol::Image image((unsigned char*)card_atlas_png, card_atlas_png_size); manager.Create(TEXTURE_CARD_ATLAS, image, lol::TextureFormat::RGBA); + + lol::Image backsideImage((unsigned char*)card_backside_png, card_backside_png_size); + manager.Create(TEXTURE_BACKSIDE, backsideImage, lol::TextureFormat::RGBA); + manager.Create(SHADER_CARD, std::string((char*)card_vs, card_vs_size), std::string((char*)card_fs, card_fs_size)); spdlog::debug("Done!"); spdlog::debug("Creating card stack"); - manager.Create(CARD_STACK, manager); + spdlog::debug("Setting up board"); layerStack.push_back(new Board(manager)); @@ -84,6 +88,7 @@ Application::Application() : // Enable transparency glEnable(GL_BLEND); + glEnable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } diff --git a/src/Application.hpp b/src/Application.hpp index 1d7c04a..dd7f607 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -3,6 +3,8 @@ #include #include +#include "CardStack.hpp" + class Window; diff --git a/src/Board.cpp b/src/Board.cpp index 57644be..fe8f33a 100644 --- a/src/Board.cpp +++ b/src/Board.cpp @@ -4,15 +4,21 @@ #include "ObjectIDs.hpp" Board::Board(lol::ObjectManager& manager) : - Layer("Board") + Layer("Board"), stack(manager) { + stack.SetScale(glm::vec3(0.2f)); + stack.SetPosition(glm::vec3( + 0.25f - (stack.GetSize().x + 0.05f), + 0.5f - (stack.GetSize().y * 0.5f), + 0.0f + )); + // Draw 8 cards from stack - std::shared_ptr stack = manager.Get(CARD_STACK); for (int y = 0; y < 2; y++) { for (int x = 0; x < 4; x++) { - std::shared_ptr card = stack->Draw(); + std::shared_ptr card = stack.DrawCard(); card->SetScale(glm::vec3(0.2f)); glm::vec3 cardSize = card->GetSize(); @@ -37,6 +43,8 @@ void Board::OnUpdate() void Board::OnRender(lol::CameraBase& camera) { + stack.Draw(camera); + for (std::shared_ptr card : openCards) card->Draw(camera); } diff --git a/src/Board.hpp b/src/Board.hpp index 9116600..d7ce5bf 100644 --- a/src/Board.hpp +++ b/src/Board.hpp @@ -2,6 +2,7 @@ #include #include "Card.hpp" +#include "CardStack.hpp" class Board : public lol::Layer { @@ -13,5 +14,6 @@ public: void OnRender(lol::CameraBase& camera) override; private: + CardStack stack; std::vector> openCards; }; \ No newline at end of file diff --git a/src/Card.cpp b/src/Card.cpp index 7ac0b31..cdae13a 100644 --- a/src/Card.cpp +++ b/src/Card.cpp @@ -8,20 +8,20 @@ Card::Card(lol::ObjectManager& manager, Month month, int type) try { vao = manager.Get(VAO_CARD); - } + } catch (const lol::ObjectNotFoundException& err) { std::shared_ptr vbo = std::make_shared(std::vector{ - 0.0f, 0.0f, 0.0f, 1.0f / 4.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.61035f, 1.0f, 1.0f / 12.0f, 0.0f, - 0.61035f, 0.0f, 1.0f / 12.0f, 1.0f / 4.0f + 0.0f, 0.0f, 0.0f, 1.0f / 4.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.61035f, 1.0f, 1.0f / 12.0f, 0.0f, + 0.61035f, 0.0f, 1.0f / 12.0f, 1.0f / 4.0f }); - + lol::BufferLayout layout({ lol::VertexAttribute(lol::Type::Float, 2, false), lol::VertexAttribute(lol::Type::Float, 2, false) - }); + }); vbo->SetLayout(layout); std::shared_ptr ebo = std::make_shared(std::vector{ 0, 1, 2, 0, 2, 3 }); @@ -30,7 +30,7 @@ Card::Card(lol::ObjectManager& manager, Month month, int type) } catch (const std::exception& err) { - spdlog::critical("Unknown error in constructor of Card"); + spdlog::critical("Unknown error in constructor of CardStack"); throw err; } diff --git a/src/CardStack.cpp b/src/CardStack.cpp index 8dad0fc..372398b 100644 --- a/src/CardStack.cpp +++ b/src/CardStack.cpp @@ -4,8 +4,44 @@ #include #include +#include + +#include "ObjectIDs.hpp" + CardStack::CardStack(lol::ObjectManager& manager) { + try + { + vao = manager.Get(VAO_STACK); + } + catch (const lol::ObjectNotFoundException& err) + { + std::shared_ptr vbo = std::make_shared(std::vector{ + 0.0f, 0.0f, 0.0f, 1.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.61035f, 1.0f, 1.0f, 0.0f, + 0.61035f, 0.0f, 1.0f, 1.0f + }); + + lol::BufferLayout layout({ + lol::VertexAttribute(lol::Type::Float, 2, false), + lol::VertexAttribute(lol::Type::Float, 2, false) + }); + vbo->SetLayout(layout); + + std::shared_ptr ebo = std::make_shared(std::vector{ 0, 1, 2, 0, 2, 3 }); + + vao = manager.Create(VAO_STACK, vbo, ebo); + } + catch (const std::exception& err) + { + spdlog::critical("Unknown error in constructor of CardStack"); + throw err; + } + + shader = manager.Get(SHADER_CARD); + backside = manager.Get(TEXTURE_BACKSIDE); + // Create a full stack of cards for (int month = 0; month < 11; month++) { @@ -24,9 +60,19 @@ CardStack::~CardStack() { } -std::shared_ptr CardStack::Draw() +std::shared_ptr CardStack::DrawCard() { std::shared_ptr drawnCard = stack.back(); stack.pop_back(); return drawnCard; } + +void CardStack::PreRender(const lol::CameraBase& camera) +{ + backside->Bind(); + shader->SetUniform("offset", glm::vec2(0.0f)); + + shader->SetUniform("model", transformation); + shader->SetUniform("view", camera.GetView()); + shader->SetUniform("projection", camera.GetProjection()); +} diff --git a/src/CardStack.hpp b/src/CardStack.hpp index 8eeba8f..f0a4058 100644 --- a/src/CardStack.hpp +++ b/src/CardStack.hpp @@ -1,16 +1,22 @@ #pragma once +#include #include "Card.hpp" -class CardStack +class CardStack : public lol::Transformable, public lol::Drawable { public: CardStack(lol::ObjectManager& manager); ~CardStack(); - std::shared_ptr Draw(); + std::shared_ptr DrawCard(); inline bool Empty() { return stack.empty(); } + glm::vec3 GetSize() { return glm::vec3(0.61035f, 1.0f, 0.0f) * GetScale(); } private: + void PreRender(const lol::CameraBase& camera) override; + +private: + std::shared_ptr backside; std::vector> stack; }; \ No newline at end of file diff --git a/src/ObjectIDs.hpp b/src/ObjectIDs.hpp index 02ec4a5..ec29175 100644 --- a/src/ObjectIDs.hpp +++ b/src/ObjectIDs.hpp @@ -3,4 +3,6 @@ #define TEXTURE_CARD_ATLAS 0 #define SHADER_CARD 1 #define VAO_CARD 2 -#define CARD_STACK 3 \ No newline at end of file +#define CARD_STACK 3 +#define TEXTURE_BACKSIDE 4 +#define VAO_STACK 5 \ No newline at end of file diff --git a/src/Window.cpp b/src/Window.cpp index 86554ea..cc2c260 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -47,7 +47,7 @@ Window::~Window() void Window::Clear() { glClearColor(7.0f / 255.0f, 1.0f / 255.0f, 15.0f / 255.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } void Window::Draw(lol::Layer& layer)