Chronos 0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
text.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2024 Rahul Satish Vadhyar
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
21*/
22
28#pragma once
29#ifndef WIN32
30#pragma GCC diagnostic push
31#pragma GCC diagnostic ignored "-Wunused-function"
32#ifdef __clang__
33#pragma clang diagnostic ignored "-Weverything"
34#endif
35#endif
36#include "stb_font_consolas_24_latin1.inl"
37#ifndef WIN32
38#pragma GCC diagnostic pop
39#endif
40
41#include "object.hpp"
42#include "texture.hpp"
43#include "engineStructs.hpp"
44namespace Chronos {
45namespace Engine {
46
58 struct FontTypes {
59 uint32_t fontWidth;
60 uint32_t fontHeight;
61 void (*getFontData)(stb_fontchar*, unsigned char[][256], int);
62 uint32_t firstChar;
64 };
65
87 public:
102
109 void destroy() override;
110
116 void clear();
117
129 void render(uint32_t currentFrame, uint32_t imageIndex,
130 float bgColor[3], VkViewport& viewport, VkRect2D& scissor,
131 std::vector<VkCommandBuffer>& commandBuffers) override;
139 void update(uint32_t currentFrame) override;
140
144 VkBuffer vertexBuffer;
145
149 uint32_t numLetters;
150
155
156 private:
157 stb_fontchar stbFontData[STB_FONT_consolas_24_latin1_NUM_CHARS];
161 uint32_t maxTextLength = 2048;
165 VkDeviceMemory vertexBufferMemory;
170
171 std::vector<Chronos::Engine::ColorBuffer> colorBuffers;
172
173 uint32_t firstChar = 'a';
174
176
184 void createDescriptorSets() override;
185
189 std::vector<VkDescriptorType> getDescriptorTypes() override;
190
194 std::vector<VkShaderStageFlagBits> getDescriptorStages() override;
195
201
205 void updateBuffer();
206
210 glm::vec4* mappedMemory;
211
212 unsigned char (*fontpixels)[256];
213 };
214
215};
216};
This initializes, manages and destroys the logical and physical devices(GPU).
Definition device.hpp:47
Abstract class for creating and managing generic graphical objects.
Definition object.hpp:66
VkCommandPool commandPool
Definition object.hpp:143
Chronos::Engine::SwapChain * swapChain
Definition object.hpp:141
Chronos::Engine::Device * device
Definition object.hpp:140
VkRenderPass * renderPass
Definition object.hpp:147
Class for creating a text object for rendering text.
Definition text.hpp:86
void destroy() override
Destroys the font object and frees the memory.
Definition text.cpp:210
Chronos::Engine::Texture fontTexture
Definition text.hpp:169
std::vector< VkShaderStageFlagBits > getDescriptorStages() override
Gets the descriptor stages in which the descriptor sets are used.
Definition text.cpp:88
uint32_t maxTextLength
Maximum number of characters that can be rendered.
Definition text.hpp:161
std::vector< VkDescriptorType > getDescriptorTypes() override
Gets the descriptor types needed for rendering the text.
Definition text.cpp:80
glm::vec4 * mappedMemory
Definition text.hpp:210
Chronos::Engine::TextParams params
Various parameters of the text that are set by the user.
Definition text.hpp:154
VkDeviceMemory vertexBufferMemory
The vertex buffer memory.
Definition text.hpp:165
std::vector< Chronos::Engine::ColorBuffer > colorBuffers
Definition text.hpp:171
void clear()
Clears the text stored in the font object.
Definition text.cpp:296
void update(uint32_t currentFrame) override
Updates the attributes(like position, color, etc) of the text.
Definition text.cpp:310
void init(Chronos::Engine::Device *device, VkCommandPool commandPool, Chronos::Engine::SwapChain *swapChain, VkSampler textureSampler, VkRenderPass *renderPass, Chronos::Engine::FontTypes fontStyle)
Initializes the font object and creates the necessary objects.
Definition text.cpp:28
stb_fontchar stbFontData[STB_FONT_consolas_24_latin1_NUM_CHARS]
Definition text.hpp:157
void createDescriptorSets() override
Creates the descriptor sets needed for rendering the text.
Definition text.cpp:94
unsigned char(* fontpixels)[256]
Definition text.hpp:212
PipelineAttributes getPipelineAttributes() override
Returns the pipeline attributes that are set for the graphics pipeline.
Definition text.cpp:160
uint32_t numLetters
The total number of letters to render.
Definition text.hpp:149
VkBuffer vertexBuffer
The vertices of each character used for rendering.
Definition text.hpp:144
FontTypes fontStyle
Definition text.hpp:175
void render(uint32_t currentFrame, uint32_t imageIndex, float bgColor[3], VkViewport &viewport, VkRect2D &scissor, std::vector< VkCommandBuffer > &commandBuffers) override
Records the commands needed for rendering the text .
Definition text.cpp:319
void updateBuffer()
Updates the buffer with the new text.
Definition text.cpp:222
This class holds the Vulkan data and objects needed for a texture.
Definition texture.hpp:134
Contains ShapeParams and UniformBufferObject structs.
Contains the class for creating a generic object.
The parameters needed for the font style.
Definition text.hpp:58
void(* getFontData)(stb_fontchar *, unsigned char[][256], int)
Definition text.hpp:61
Structure defining attributes required for creating a graphics pipeline.
Definition object.hpp:43
Parameters for rendering text.
Contains the functions for image manipulation along with the Texture class.