added card background
This commit is contained in:
parent
b7f4174085
commit
c6a262a57f
BIN
res/card_backside.png
Normal file
BIN
res/card_backside.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 736 KiB |
|
@ -71,11 +71,15 @@ Application::Application() :
|
|||
|
||||
lol::Image image((unsigned char*)card_atlas_png, card_atlas_png_size);
|
||||
manager.Create<lol::Texture2D>(TEXTURE_CARD_ATLAS, image, lol::TextureFormat::RGBA);
|
||||
|
||||
lol::Image backsideImage((unsigned char*)card_backside_png, card_backside_png_size);
|
||||
manager.Create<lol::Texture2D>(TEXTURE_BACKSIDE, backsideImage, lol::TextureFormat::RGBA);
|
||||
|
||||
manager.Create<lol::Shader>(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<CardStack>(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);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <vector>
|
||||
#include <lol/lol.hpp>
|
||||
|
||||
#include "CardStack.hpp"
|
||||
|
||||
|
||||
class Window;
|
||||
|
||||
|
|
|
@ -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<CardStack> stack = manager.Get<CardStack>(CARD_STACK);
|
||||
for (int y = 0; y < 2; y++)
|
||||
{
|
||||
for (int x = 0; x < 4; x++)
|
||||
{
|
||||
std::shared_ptr<Card> card = stack->Draw();
|
||||
std::shared_ptr<Card> 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> card : openCards)
|
||||
card->Draw(camera);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <lol/lol.hpp>
|
||||
#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<std::shared_ptr<Card>> openCards;
|
||||
};
|
12
src/Card.cpp
12
src/Card.cpp
|
@ -12,16 +12,16 @@ Card::Card(lol::ObjectManager& manager, Month month, int type)
|
|||
catch (const lol::ObjectNotFoundException& err)
|
||||
{
|
||||
std::shared_ptr<lol::VertexBuffer> vbo = std::make_shared<lol::VertexBuffer>(std::vector<float>{
|
||||
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<lol::ElementBuffer> ebo = std::make_shared<lol::ElementBuffer>(std::vector<unsigned int>{ 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,44 @@
|
|||
#include <chrono>
|
||||
#include <random>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "ObjectIDs.hpp"
|
||||
|
||||
CardStack::CardStack(lol::ObjectManager& manager)
|
||||
{
|
||||
try
|
||||
{
|
||||
vao = manager.Get<lol::VertexArray>(VAO_STACK);
|
||||
}
|
||||
catch (const lol::ObjectNotFoundException& err)
|
||||
{
|
||||
std::shared_ptr<lol::VertexBuffer> vbo = std::make_shared<lol::VertexBuffer>(std::vector<float>{
|
||||
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<lol::ElementBuffer> ebo = std::make_shared<lol::ElementBuffer>(std::vector<unsigned int>{ 0, 1, 2, 0, 2, 3 });
|
||||
|
||||
vao = manager.Create<lol::VertexArray>(VAO_STACK, vbo, ebo);
|
||||
}
|
||||
catch (const std::exception& err)
|
||||
{
|
||||
spdlog::critical("Unknown error in constructor of CardStack");
|
||||
throw err;
|
||||
}
|
||||
|
||||
shader = manager.Get<lol::Shader>(SHADER_CARD);
|
||||
backside = manager.Get<lol::Texture2D>(TEXTURE_BACKSIDE);
|
||||
|
||||
// Create a full stack of cards
|
||||
for (int month = 0; month < 11; month++)
|
||||
{
|
||||
|
@ -24,9 +60,19 @@ CardStack::~CardStack()
|
|||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<Card> CardStack::Draw()
|
||||
std::shared_ptr<Card> CardStack::DrawCard()
|
||||
{
|
||||
std::shared_ptr<Card> 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());
|
||||
}
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <lol/lol.hpp>
|
||||
#include "Card.hpp"
|
||||
|
||||
class CardStack
|
||||
class CardStack : public lol::Transformable, public lol::Drawable
|
||||
{
|
||||
public:
|
||||
CardStack(lol::ObjectManager& manager);
|
||||
~CardStack();
|
||||
|
||||
std::shared_ptr<Card> Draw();
|
||||
std::shared_ptr<Card> 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<lol::Texture2D> backside;
|
||||
std::vector<std::shared_ptr<Card>> stack;
|
||||
};
|
|
@ -4,3 +4,5 @@
|
|||
#define SHADER_CARD 1
|
||||
#define VAO_CARD 2
|
||||
#define CARD_STACK 3
|
||||
#define TEXTURE_BACKSIDE 4
|
||||
#define VAO_STACK 5
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue