Improvement to coordinate system
- Flip coordinate system for SwapChain passthrough - Normalize MouseMoveEvent coordination - Add RemoveSystem to Ecs
This commit is contained in:
@@ -8,4 +8,5 @@ void main()
|
|||||||
{
|
{
|
||||||
gl_Position = vec4(inPosition, 0.0, 1.0);
|
gl_Position = vec4(inPosition, 0.0, 1.0);
|
||||||
outTexCoord = inPosition * 0.5 + 0.5;
|
outTexCoord = inPosition * 0.5 + 0.5;
|
||||||
|
outTexCoord.y = 1.0 - outTexCoord.y;
|
||||||
}
|
}
|
||||||
@@ -19,13 +19,13 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
const std::vector<Vertex> vertices = {
|
const std::vector<Vertex> vertices = {
|
||||||
Vertex{{-0.5f, 0.5f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
|
Vertex{{-0.5f, 0.5f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
|
||||||
Vertex{{ 0.5f, 0.5f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
|
|
||||||
Vertex{{ 0.5f, 0.5f, 0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
|
|
||||||
Vertex{{-0.5f, 0.5f, 0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}},
|
Vertex{{-0.5f, 0.5f, 0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}},
|
||||||
|
Vertex{{ 0.5f, 0.5f, 0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
|
||||||
|
Vertex{{ 0.5f, 0.5f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
|
||||||
Vertex{{-0.5f, 0.0f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
|
Vertex{{-0.5f, 0.0f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
|
||||||
Vertex{{ 0.5f, 0.0f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
|
|
||||||
Vertex{{ 0.5f, 0.0f, 0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
|
|
||||||
Vertex{{-0.5f, 0.0f, 0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}},
|
Vertex{{-0.5f, 0.0f, 0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}},
|
||||||
|
Vertex{{ 0.5f, 0.0f, 0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
|
||||||
|
Vertex{{ 0.5f, 0.0f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::vector<uint16_t> indices = {
|
const std::vector<uint16_t> indices = {
|
||||||
@@ -77,14 +77,6 @@ namespace Copium
|
|||||||
Vulkan::GetSwapChain().SubmitToGraphicsQueue(*commandBuffer);
|
Vulkan::GetSwapChain().SubmitToGraphicsQueue(*commandBuffer);
|
||||||
|
|
||||||
Vulkan::GetSwapChain().EndPresent();
|
Vulkan::GetSwapChain().EndPresent();
|
||||||
if (timer.Elapsed() >= 1.0)
|
|
||||||
{
|
|
||||||
fps = frameCounter;
|
|
||||||
frameCounter = 0;
|
|
||||||
timer.Start(); // Not quite accurate since the elapsed time might me 1.1, then we lose 0.1 precision
|
|
||||||
}
|
|
||||||
frameCounter++;
|
|
||||||
|
|
||||||
return !glfwWindowShouldClose(Vulkan::GetWindow().GetWindow());
|
return !glfwWindowShouldClose(Vulkan::GetWindow().GetWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,16 +93,6 @@ namespace Copium
|
|||||||
|
|
||||||
return EventResult::Continue;
|
return EventResult::Continue;
|
||||||
}
|
}
|
||||||
case EventType::MouseMove:
|
|
||||||
{
|
|
||||||
const MouseMoveEvent& mouseMoveEvent = static_cast<const MouseMoveEvent&>(event);
|
|
||||||
|
|
||||||
float aspect = Vulkan::GetSwapChain().GetExtent().width / (float)Vulkan::GetSwapChain().GetExtent().height;
|
|
||||||
mousePos = {(mouseMoveEvent.GetPos().x / Vulkan::GetSwapChain().GetExtent().width - 0.5) * 2.0 * aspect,
|
|
||||||
-(mouseMoveEvent.GetPos().y / Vulkan::GetSwapChain().GetExtent().height - 0.5) * 2.0};
|
|
||||||
|
|
||||||
return EventResult::Continue;
|
|
||||||
}
|
|
||||||
case EventType::MousePress:
|
case EventType::MousePress:
|
||||||
{
|
{
|
||||||
const MousePressEvent& mousePressEvent = static_cast<const MousePressEvent&>(event);
|
const MousePressEvent& mousePressEvent = static_cast<const MousePressEvent&>(event);
|
||||||
@@ -231,11 +213,8 @@ namespace Copium
|
|||||||
float aspect = fb.GetWidth() / (float)fb.GetHeight();
|
float aspect = fb.GetWidth() / (float)fb.GetHeight();
|
||||||
|
|
||||||
{
|
{
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(45.0f), aspect, 0.1f, 10.0f);
|
|
||||||
projection[1][1] *= -1;
|
|
||||||
|
|
||||||
UniformBuffer& uniformBuffer = descriptorSet->GetUniformBuffer("ubo");
|
UniformBuffer& uniformBuffer = descriptorSet->GetUniformBuffer("ubo");
|
||||||
uniformBuffer.Set("projection", projection);
|
uniformBuffer.Set("projection", glm::perspective(glm::radians(45.0f), aspect, 0.1f, 10.0f));
|
||||||
uniformBuffer.Set("view", glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)));
|
uniformBuffer.Set("view", glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||||
uniformBuffer.Set("model", glm::rotate(glm::mat4(1.0f), time * glm::radians(90.0f), glm::vec3(0.0f, 1.0f, 0.0f)));
|
uniformBuffer.Set("model", glm::rotate(glm::mat4(1.0f), time * glm::radians(90.0f), glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||||
uniformBuffer.Set("lightPos", (glm::vec3)(glm::rotate(glm::mat4{1.0f}, time * glm::radians(45.0f), glm::vec3(0, 1, 0)) * glm::vec4{0.3, 0.1, 0, 1}));
|
uniformBuffer.Set("lightPos", (glm::vec3)(glm::rotate(glm::mat4{1.0f}, time * glm::radians(45.0f), glm::vec3(0, 1, 0)) * glm::vec4{0.3, 0.1, 0, 1}));
|
||||||
|
|||||||
@@ -30,10 +30,6 @@ namespace Copium
|
|||||||
std::unique_ptr<Mesh> meshPassthrough;
|
std::unique_ptr<Mesh> meshPassthrough;
|
||||||
std::unique_ptr<CommandBuffer> commandBuffer;
|
std::unique_ptr<CommandBuffer> commandBuffer;
|
||||||
|
|
||||||
glm::vec2 mousePos;
|
|
||||||
int fps;
|
|
||||||
int frameCounter;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Application();
|
Application();
|
||||||
~Application();
|
~Application();
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ namespace Copium
|
|||||||
entityMouse.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("fox2.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
|
entityMouse.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("fox2.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
|
||||||
entityMouse.AddComponent<MouseFollowC>();
|
entityMouse.AddComponent<MouseFollowC>();
|
||||||
|
|
||||||
glm::vec2 pos = glm::vec2{-aspect + 0.01, 0.94};
|
|
||||||
|
|
||||||
Entity entityText = Entity::Create(ecs.get());
|
Entity entityText = Entity::Create(ecs.get());
|
||||||
entityText.AddComponent<TransformC>(glm::vec2{-aspect + 0.01, 0.94}, glm::vec2{1.0});
|
entityText.AddComponent<TransformC>(glm::vec2{-aspect + 0.01, 0.94}, glm::vec2{1.0});
|
||||||
entityText.AddComponent<TextC>(AssetRef{AssetManager::LoadAsset("font.meta")}, std::to_string(0) + " fps", 0.06f);
|
entityText.AddComponent<TextC>(AssetRef{AssetManager::LoadAsset("font.meta")}, std::to_string(0) + " fps", 0.06f);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
Window::Window(const std::string& windowName, int width, int height, WindowMode mode)
|
Window::Window(const std::string& windowName, int width, int height, WindowMode mode)
|
||||||
|
: width{width}, height{height}
|
||||||
{
|
{
|
||||||
InitializeWindow(windowName, width, height, mode);
|
InitializeWindow(windowName, width, height, mode);
|
||||||
InitializeSurface();
|
InitializeSurface();
|
||||||
@@ -46,6 +47,8 @@ namespace Copium
|
|||||||
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
||||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||||
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), monitor, nullptr);
|
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), monitor, nullptr);
|
||||||
|
width = mode->width;
|
||||||
|
height = mode->height;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WindowMode::BorderlessWindowed:
|
case WindowMode::BorderlessWindowed:
|
||||||
@@ -54,6 +57,8 @@ namespace Copium
|
|||||||
|
|
||||||
glfwWindowHint(GLFW_DECORATED, false);
|
glfwWindowHint(GLFW_DECORATED, false);
|
||||||
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), nullptr, nullptr);
|
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), nullptr, nullptr);
|
||||||
|
width = mode->width;
|
||||||
|
height = mode->height;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WindowMode::Windowed:
|
case WindowMode::Windowed:
|
||||||
@@ -85,11 +90,14 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
if (width == 0 || height == 0)
|
if (width == 0 || height == 0)
|
||||||
return;
|
return;
|
||||||
|
Window* window = (Window*)glfwGetWindowUserPointer(glfwWindow);
|
||||||
|
window->width = width;
|
||||||
|
window->height = height;
|
||||||
Vulkan::GetSwapChain().ResizeFramebuffer();
|
Vulkan::GetSwapChain().ResizeFramebuffer();
|
||||||
EventDispatcher::QueueEvent(WindowResizeEvent{width, height});
|
EventDispatcher::QueueEvent(WindowResizeEvent{width, height});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
void Window::KeyCallback(GLFWwindow* glfwWindow, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
if (action == GLFW_PRESS)
|
if (action == GLFW_PRESS)
|
||||||
EventDispatcher::QueueEvent(KeyPressEvent(key));
|
EventDispatcher::QueueEvent(KeyPressEvent(key));
|
||||||
@@ -97,7 +105,7 @@ namespace Copium
|
|||||||
EventDispatcher::QueueEvent(KeyReleaseEvent(key));
|
EventDispatcher::QueueEvent(KeyReleaseEvent(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
void Window::MouseButtonCallback(GLFWwindow* glfwWindow, int button, int action, int mods)
|
||||||
{
|
{
|
||||||
if (action == GLFW_PRESS)
|
if (action == GLFW_PRESS)
|
||||||
EventDispatcher::QueueEvent(MousePressEvent{button});
|
EventDispatcher::QueueEvent(MousePressEvent{button});
|
||||||
@@ -105,17 +113,18 @@ namespace Copium
|
|||||||
EventDispatcher::QueueEvent(MouseReleaseEvent{button});
|
EventDispatcher::QueueEvent(MouseReleaseEvent{button});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::MouseMoveCallback(GLFWwindow* window, double xpos, double ypos)
|
void Window::MouseMoveCallback(GLFWwindow* glfwWindow, double xpos, double ypos)
|
||||||
{
|
{
|
||||||
EventDispatcher::QueueEvent(MouseMoveEvent{glm::vec2{xpos, ypos}}); // TODO: Convert to Vulkan coordinates
|
Window* window = (Window*)glfwGetWindowUserPointer(glfwWindow);
|
||||||
|
EventDispatcher::QueueEvent(MouseMoveEvent{glm::vec2{xpos / window->width * 2.0 - 1.0, -(ypos / window->height * 2.0 - 1.0)}});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::WindowFocusCallback(GLFWwindow* window, int focused)
|
void Window::WindowFocusCallback(GLFWwindow* glfwWindow, int focused)
|
||||||
{
|
{
|
||||||
EventDispatcher::QueueEvent(WindowFocusEvent{focused == GLFW_TRUE});
|
EventDispatcher::QueueEvent(WindowFocusEvent{focused == GLFW_TRUE});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::MouseScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
void Window::MouseScrollCallback(GLFWwindow* glfwWindow, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
EventDispatcher::QueueEvent(MouseScrollEvent{(int)xoffset, (int)yoffset});
|
EventDispatcher::QueueEvent(MouseScrollEvent{(int)xoffset, (int)yoffset});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ namespace Copium
|
|||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
VkSurfaceKHR surface;
|
VkSurfaceKHR surface;
|
||||||
|
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Window(const std::string& windowName, int width, int height, WindowMode mode);
|
Window(const std::string& windowName, int width, int height, WindowMode mode);
|
||||||
~Window();
|
~Window();
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ namespace Copium
|
|||||||
return systemPool->AddSystem(typeid(SystemClass), new SystemClass{args...});
|
return systemPool->AddSystem(typeid(SystemClass), new SystemClass{args...});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename SystemClass>
|
||||||
|
void RemoveSystem()
|
||||||
|
{
|
||||||
|
systemPool->MoveSystemBefore(typeid(SystemClass));
|
||||||
|
}
|
||||||
|
|
||||||
void UpdateSystems();
|
void UpdateSystems();
|
||||||
void UpdateSystems(const Signal& signal);
|
void UpdateSystems(const Signal& signal);
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,27 @@ namespace Copium
|
|||||||
SystemOrderer SystemPool::AddSystem(const std::type_index& systemId, SystemBase* system)
|
SystemOrderer SystemPool::AddSystem(const std::type_index& systemId, SystemBase* system)
|
||||||
{
|
{
|
||||||
system->manager = manager;
|
system->manager = manager;
|
||||||
|
CP_ASSERT(systems.find(systemId) == systems.end(), "System already exist in Ecs");
|
||||||
systems.emplace(systemId, system);
|
systems.emplace(systemId, system);
|
||||||
systemOrder.emplace_back(system);
|
systemOrder.emplace_back(system);
|
||||||
return SystemOrderer{systemId, this};
|
return SystemOrderer{systemId, this};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SystemPool::RemoveSystem(const std::type_index& systemId)
|
||||||
|
{
|
||||||
|
auto it = systems.find(systemId);
|
||||||
|
if (it == systems.end())
|
||||||
|
{
|
||||||
|
CP_WARN("System does not exist in Ecs");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto itOrder = std::find(systemOrder.begin(), systemOrder.end(), it->second);
|
||||||
|
delete it->second;
|
||||||
|
systems.erase(it);
|
||||||
|
systemOrder.erase(itOrder);
|
||||||
|
}
|
||||||
|
|
||||||
void SystemPool::Update()
|
void SystemPool::Update()
|
||||||
{
|
{
|
||||||
for (auto& system : systemOrder)
|
for (auto& system : systemOrder)
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ namespace Copium
|
|||||||
public:
|
public:
|
||||||
SystemPool(ECSManager* manager);
|
SystemPool(ECSManager* manager);
|
||||||
~SystemPool();
|
~SystemPool();
|
||||||
|
|
||||||
SystemOrderer AddSystem(const std::type_index& systemId, SystemBase* system);
|
SystemOrderer AddSystem(const std::type_index& systemId, SystemBase* system);
|
||||||
|
void RemoveSystem(const std::type_index& systemId);
|
||||||
void Update();
|
void Update();
|
||||||
void Update(const Signal& signal);
|
void Update(const Signal& signal);
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include "copium/event/MouseMoveEvent.h"
|
#include "copium/event/MouseMoveEvent.h"
|
||||||
#include "copium/example/Components.h"
|
#include "copium/example/Components.h"
|
||||||
|
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class MouseFollowSystem : public System<MouseFollowC, TransformC>
|
class MouseFollowSystem : public System<MouseFollowC, TransformC>
|
||||||
@@ -21,8 +23,8 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
const MouseMoveEvent& mouseMoveEvent = static_cast<const MouseMoveEvent&>(eventSignal.GetEvent());
|
const MouseMoveEvent& mouseMoveEvent = static_cast<const MouseMoveEvent&>(eventSignal.GetEvent());
|
||||||
float aspect = Vulkan::GetSwapChain().GetExtent().width / (float)Vulkan::GetSwapChain().GetExtent().height;
|
float aspect = Vulkan::GetSwapChain().GetExtent().width / (float)Vulkan::GetSwapChain().GetExtent().height;
|
||||||
transform.position = {(mouseMoveEvent.GetPos().x / Vulkan::GetSwapChain().GetExtent().width - 0.5) * 2.0 * aspect,
|
// TODO: Get projectionViewMatrix from camera
|
||||||
-(mouseMoveEvent.GetPos().y / Vulkan::GetSwapChain().GetExtent().height - 0.5) * 2.0};
|
transform.position = glm::inverse(glm::ortho(-aspect, aspect, -1.0f, 1.0f)) * glm::vec4{mouseMoveEvent.GetPos().x, mouseMoveEvent.GetPos().y, 0.0f, 0.0f};
|
||||||
transform.position -= transform.size * glm::vec2{0.5f};
|
transform.position -= transform.size * glm::vec2{0.5f};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,8 +47,7 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
float aspect = Vulkan::GetSwapChain().GetExtent().width / (float)Vulkan::GetSwapChain().GetExtent().height;
|
float aspect = Vulkan::GetSwapChain().GetExtent().width / (float)Vulkan::GetSwapChain().GetExtent().height;
|
||||||
UniformBuffer& uniformBuffer = descriptorSet->GetUniformBuffer("ubo");
|
UniformBuffer& uniformBuffer = descriptorSet->GetUniformBuffer("ubo");
|
||||||
uniformBuffer.Set("projection", glm::ortho(-aspect, aspect, 1.0f, -1.0f));
|
uniformBuffer.Set("projection", glm::ortho(-aspect, aspect, -1.0f, 1.0f));
|
||||||
// uniformBuffer.Set("view", glm::translate(glm::mat4(1), glm::vec3(0.1 * glm::sin(4 * time), 0.1 * glm::cos(4 * time), 0.0)));
|
|
||||||
uniformBuffer.Set("view", glm::mat4(1));
|
uniformBuffer.Set("view", glm::mat4(1));
|
||||||
uniformBuffer.Update();
|
uniformBuffer.Update();
|
||||||
|
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
AllocateQuad();
|
AllocateQuad();
|
||||||
AddVertex(pos, color, -1, glm::vec2{0, 0}, RendererVertex::TYPE_QUAD);
|
AddVertex(pos, color, -1, glm::vec2{0, 0}, RendererVertex::TYPE_QUAD);
|
||||||
AddVertex(glm::vec2{pos.x + size.x, pos.y}, color, -1, glm::vec2{0, 0}, RendererVertex::TYPE_QUAD);
|
|
||||||
AddVertex(pos + size, color, -1, glm::vec2{0, 0}, RendererVertex::TYPE_QUAD);
|
|
||||||
AddVertex(glm::vec2{pos.x, pos.y + size.y}, color, -1, glm::vec2{0, 0}, RendererVertex::TYPE_QUAD);
|
AddVertex(glm::vec2{pos.x, pos.y + size.y}, color, -1, glm::vec2{0, 0}, RendererVertex::TYPE_QUAD);
|
||||||
|
AddVertex(pos + size, color, -1, glm::vec2{0, 0}, RendererVertex::TYPE_QUAD);
|
||||||
|
AddVertex(glm::vec2{pos.x + size.x, pos.y}, color, -1, glm::vec2{0, 0}, RendererVertex::TYPE_QUAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -43,9 +43,9 @@ namespace Copium
|
|||||||
AllocateQuad();
|
AllocateQuad();
|
||||||
int texIndex = AllocateSampler(sampler);
|
int texIndex = AllocateSampler(sampler);
|
||||||
AddVertex(pos, glm::vec3{1,1,1}, texIndex, texCoord1, RendererVertex::TYPE_QUAD);
|
AddVertex(pos, glm::vec3{1,1,1}, texIndex, texCoord1, RendererVertex::TYPE_QUAD);
|
||||||
AddVertex(glm::vec2{pos.x + size.x, pos.y}, glm::vec3{1, 1, 1}, texIndex, glm::vec2{texCoord2.x, texCoord1.y}, RendererVertex::TYPE_QUAD);
|
|
||||||
AddVertex(pos + size, glm::vec3{1,1,1}, texIndex, texCoord2, RendererVertex::TYPE_QUAD);
|
|
||||||
AddVertex(glm::vec2{pos.x, pos.y + size.y}, glm::vec3{1, 1, 1}, texIndex, glm::vec2{texCoord1.x, texCoord2.y}, RendererVertex::TYPE_QUAD);
|
AddVertex(glm::vec2{pos.x, pos.y + size.y}, glm::vec3{1, 1, 1}, texIndex, glm::vec2{texCoord1.x, texCoord2.y}, RendererVertex::TYPE_QUAD);
|
||||||
|
AddVertex(pos + size, glm::vec3{1,1,1}, texIndex, texCoord2, RendererVertex::TYPE_QUAD);
|
||||||
|
AddVertex(glm::vec2{pos.x + size.x, pos.y}, glm::vec3{1, 1, 1}, texIndex, glm::vec2{texCoord2.x, texCoord1.y}, RendererVertex::TYPE_QUAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 Renderer::Text(const std::string& str, const glm::vec2& position, const Font& font, float size, const glm::vec3& color)
|
glm::vec2 Renderer::Text(const std::string& str, const glm::vec2& position, const Font& font, float size, const glm::vec3& color)
|
||||||
@@ -75,9 +75,9 @@ namespace Copium
|
|||||||
AllocateQuad();
|
AllocateQuad();
|
||||||
int texIndex = AllocateSampler(font);
|
int texIndex = AllocateSampler(font);
|
||||||
AddVertex(offset + glm::vec2{glyph.boundingBox.l * size, glyph.boundingBox.b * size}, color, texIndex, glyph.texCoordBoundingBox.lb, RendererVertex::TYPE_TEXT);
|
AddVertex(offset + glm::vec2{glyph.boundingBox.l * size, glyph.boundingBox.b * size}, color, texIndex, glyph.texCoordBoundingBox.lb, RendererVertex::TYPE_TEXT);
|
||||||
AddVertex(offset + glm::vec2{glyph.boundingBox.r * size, glyph.boundingBox.b * size}, color, texIndex, glm::vec2{glyph.texCoordBoundingBox.r, glyph.texCoordBoundingBox.b}, RendererVertex::TYPE_TEXT);
|
|
||||||
AddVertex(offset + glm::vec2{glyph.boundingBox.r * size, glyph.boundingBox.t * size}, color, texIndex, glyph.texCoordBoundingBox.rt, RendererVertex::TYPE_TEXT);
|
|
||||||
AddVertex(offset + glm::vec2{glyph.boundingBox.l * size, glyph.boundingBox.t * size}, color, texIndex, glm::vec2{glyph.texCoordBoundingBox.l, glyph.texCoordBoundingBox.t}, RendererVertex::TYPE_TEXT);
|
AddVertex(offset + glm::vec2{glyph.boundingBox.l * size, glyph.boundingBox.t * size}, color, texIndex, glm::vec2{glyph.texCoordBoundingBox.l, glyph.texCoordBoundingBox.t}, RendererVertex::TYPE_TEXT);
|
||||||
|
AddVertex(offset + glm::vec2{glyph.boundingBox.r * size, glyph.boundingBox.t * size}, color, texIndex, glyph.texCoordBoundingBox.rt, RendererVertex::TYPE_TEXT);
|
||||||
|
AddVertex(offset + glm::vec2{glyph.boundingBox.r * size, glyph.boundingBox.b * size}, color, texIndex, glm::vec2{glyph.texCoordBoundingBox.r, glyph.texCoordBoundingBox.b}, RendererVertex::TYPE_TEXT);
|
||||||
offset.x += glyph.advance * size;
|
offset.x += glyph.advance * size;
|
||||||
}
|
}
|
||||||
return offset;
|
return offset;
|
||||||
|
|||||||
Reference in New Issue
Block a user