First phase moving from STBTT to FreeType
This commit is contained in:
		| @@ -15,7 +15,7 @@ TrueTypeAsset::TrueTypeAsset(AssetManager *assMan, std::string name) : | ||||
|  | ||||
| void TrueTypeAsset::updateSync() { | ||||
|   if(this->state != 0x04) return; | ||||
|   this->font.texture.setSize(this->width, this->height, TEXTURE_FORMAT_RGBA); | ||||
|   this->font.texture.setSize(this->width, this->height, TEXTURE_FORMAT_R); | ||||
|   this->font.texture.buffer(this->pixels); | ||||
|   auto i = this->pixels; | ||||
|   memoryCopy( | ||||
| @@ -71,9 +71,9 @@ void TrueTypeAsset::updateAsync() { | ||||
|  | ||||
|   this->state = 0x03; | ||||
|   this->font.fontSize = fontSize; | ||||
|   this->pixels = (struct Color*)(this->buffer + i); | ||||
|   this->pixels = (uint8_t*)(this->buffer + i); | ||||
|   this->characterData = (truetypechar_t*)( | ||||
|     (uint8_t*)this->pixels + (this->width * this->height * sizeof(struct Color)) | ||||
|     (uint8_t*)this->pixels + (this->width * this->height * sizeof(uint8_t)) | ||||
|   ); | ||||
|   this->state = 0x04; | ||||
| } | ||||
|   | ||||
| @@ -14,7 +14,7 @@ namespace Dawn { | ||||
|       AssetLoader loader; | ||||
|       uint8_t *buffer = nullptr; | ||||
|       truetypechar_t *characterData = nullptr; | ||||
|       struct Color *pixels = nullptr; | ||||
|       uint8_t *pixels = nullptr; | ||||
|       int32_t width, height; | ||||
|  | ||||
|     public: | ||||
|   | ||||
| @@ -10,6 +10,9 @@ | ||||
|  | ||||
| #include <stb_truetype.h> | ||||
|  | ||||
| #include <ft2build.h> | ||||
| #include FT_FREETYPE_H | ||||
|  | ||||
| #include <glm/glm.hpp> | ||||
| #include <glm/vec3.hpp> | ||||
| #include <glm/vec4.hpp> | ||||
|   | ||||
| @@ -18,6 +18,81 @@ RenderPipeline::RenderPipeline(RenderManager *renderManager) { | ||||
| } | ||||
|  | ||||
| void RenderPipeline::init() { | ||||
|   // FT_Face face; | ||||
|   // if(FT_New_Face(ft, "C:\\Windows\\Fonts\\Arial.ttf", 0, &face)) { | ||||
|   //   std::cout << "ERROR::FREETYPE: Failed to load font" << std::endl; | ||||
|   //   assertUnreachable(); | ||||
|   // } | ||||
|   // // TESTING FONT | ||||
|   // // glGenTextures(1, &texture); | ||||
|   // // glBindTexture(GL_TEXTURE_2D, texture); | ||||
|   // // glTexImage2D( | ||||
|   // //     GL_TEXTURE_2D, | ||||
|   // //     0, | ||||
|   // //     GL_RED, | ||||
|   // //     face->glyph->bitmap.width, | ||||
|   // //     face->glyph->bitmap.rows, | ||||
|   // //     0, | ||||
|   // //     GL_RED, | ||||
|   // //     GL_UNSIGNED_BYTE, | ||||
|   // //     face->glyph->bitmap.buffer | ||||
|   // // ); | ||||
|   // // // set texture options | ||||
|   // // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||||
|   // // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||||
|   // // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||
|   // // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||||
|   // Mesh glyphMesh; | ||||
|   // FT_Set_Pixel_Sizes(face, 0, 36); | ||||
|   // FT_UInt glyph_index = FT_Get_Char_Index(face, 'B'); | ||||
|   // auto error = FT_Load_Glyph( | ||||
|   //         face,          /* handle to face object */ | ||||
|   //         glyph_index,   /* glyph index           */ | ||||
|   //         FT_LOAD_DEFAULT  );  /* load flags, see below */ | ||||
|   // if(error) { | ||||
|   //   std::cout << "Error loading glyph" << std::endl; | ||||
|   //   assertUnreachable(); | ||||
|   // } | ||||
|  | ||||
|   // /* convert to an anti-aliased bitmap */ | ||||
|   // error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL ); | ||||
|   // if(error) { | ||||
|   //   std::cout << "Error rendering glyph" << std::endl; | ||||
|   //   assertUnreachable(); | ||||
|   // } | ||||
|  | ||||
|   // // Shader | ||||
|   // auto shdr = &this->renderManager->simpleTexturedShader->program; | ||||
|   // shdr->bind(); | ||||
|   // shdr->setMatrix(shdr->paramProjection, camera->getProjection()); | ||||
|   // shdr->setMatrix(shdr->paramView, camera->transform->getWorldTransform()); | ||||
|   // shdr->setMatrix(shdr->paramModel, glm::mat4(1.0f)); | ||||
|   // shdr->setColor(shdr->paramColor, COLOR_WHITE); | ||||
|    | ||||
|   // // Texture | ||||
|   // Texture texture; | ||||
|   // texture.setSize( | ||||
|   //   face->glyph->bitmap.width, | ||||
|   //   face->glyph->bitmap.rows, | ||||
|   //   TEXTURE_FORMAT_R | ||||
|   // ); | ||||
|   // texture.wrapModeX = TEXTURE_WRAP_MODE_CLAMP_TO_EDGE; | ||||
|   // texture.wrapModeY = TEXTURE_WRAP_MODE_CLAMP_TO_EDGE; | ||||
|   // texture.buffer((uint8_t*)face->glyph->bitmap.buffer); | ||||
|  | ||||
|   // shdr->setBoolean(shdr->paramHasTexture, true); | ||||
|   // shdr->setTexture(shdr->paramTexture, 0); | ||||
|   // texture.bind(0); | ||||
|  | ||||
|   // this->renderManager->setRenderFlags(RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST | RENDER_MANAGER_RENDER_FLAG_BLEND); | ||||
|  | ||||
|   // auto faceCloneForDebugging = face; | ||||
|   // QuadMesh::initQuadMesh(&glyphMesh, | ||||
|   //   glm::vec2(face->glyph->bitmap.width, face->glyph->bitmap.rows), glm::vec2(1, 0), | ||||
|   //   glm::vec2(0, 0), glm::vec2(0, 1), | ||||
|   //   0.0f | ||||
|   // ); | ||||
|   // glyphMesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1); | ||||
| } | ||||
|  | ||||
| void RenderPipeline::render() { | ||||
| @@ -196,6 +271,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) { | ||||
|     RENDER_TARGET_CLEAR_FLAG_COLOR | ||||
|   ); | ||||
|  | ||||
|   // Shader items | ||||
|   itPassItem = shaderPassItems.begin(); | ||||
|   while(itPassItem != shaderPassItems.end()) { | ||||
|     auto item = *itPassItem; | ||||
|   | ||||
| @@ -15,6 +15,7 @@ namespace Dawn { | ||||
|   class DawnGame; | ||||
|   class RenderPipeline; | ||||
|   class ShaderManager; | ||||
|   class FontManager; | ||||
|  | ||||
|   class IRenderManager { | ||||
|     protected: | ||||
| @@ -55,6 +56,13 @@ namespace Dawn { | ||||
|        * @return Reference to the shader manager. | ||||
|        */ | ||||
|       virtual ShaderManager * getShaderManager() = 0; | ||||
|  | ||||
|       /** | ||||
|        * Returns the font manager that this render manager uses. | ||||
|        *  | ||||
|        * @return Reference ot the font manager. | ||||
|        */ | ||||
|       virtual FontManager * getFontManager() = 0; | ||||
|        | ||||
|       /** | ||||
|        * Sets the render flags for the render manager to use. | ||||
|   | ||||
| @@ -95,5 +95,6 @@ namespace Dawn { | ||||
|        * @return The amount of bytes buffered to the texture. | ||||
|        */ | ||||
|       virtual void buffer(struct Color pixels[]) = 0; | ||||
|       virtual void buffer(uint8_t pixels[]) = 0; | ||||
|   }; | ||||
| } | ||||
| @@ -6,6 +6,7 @@ | ||||
| # Sources | ||||
| target_sources(${DAWN_TARGET_NAME} | ||||
|   PRIVATE | ||||
|     FontManager.cpp | ||||
|     BitmapFont.cpp | ||||
|     ExampleFont.cpp | ||||
|     TrueTypeFont.cpp | ||||
|   | ||||
							
								
								
									
										15
									
								
								src/dawn/display/font/FontManager.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/dawn/display/font/FontManager.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| // Copyright (c) 2023 Dominic Masters | ||||
| //  | ||||
| // This software is released under the MIT License. | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #include "FontManager.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| void FontManager::init() { | ||||
|   if(FT_Init_FreeType(&fontLibrary)) { | ||||
|     std::cout << "ERROR::FREETYPE: Could not init FreeType Library" << std::endl; | ||||
|     assertUnreachable(); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										19
									
								
								src/dawn/display/font/FontManager.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/dawn/display/font/FontManager.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| // Copyright (c) 2023 Dominic Masters | ||||
| //  | ||||
| // This software is released under the MIT License. | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #pragma once | ||||
| #include "dawnlibs.hpp" | ||||
| #include "assert/assert.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
|   class FontManager { | ||||
|     protected: | ||||
|  | ||||
|     public: | ||||
|       FT_Library fontLibrary; | ||||
|  | ||||
|       void init(); | ||||
|   }; | ||||
| } | ||||
| @@ -74,13 +74,12 @@ std::vector<struct ShaderPassItem> UILabel::getPassItems( | ||||
|   this->updateMesh(); | ||||
|  | ||||
|   struct ShaderPassItem item; | ||||
|   auto shader = &getGame()->renderManager.uiShader->program; | ||||
|   auto shader = &getGame()->renderManager.fontShader->program; | ||||
|   item.shaderProgram = shader; | ||||
|   item.colorValues[shader->paramColor] = textColor; | ||||
|   item.matrixValues[shader->paramProjection] = proj; | ||||
|   item.matrixValues[shader->paramView] = view; | ||||
|   item.matrixValues[shader->paramModel] = this->transform->getWorldTransform(); | ||||
|   item.boolValues[shader->paramHasTexture] = true; | ||||
|   item.textureSlots[0] = this->font->getTexture(); | ||||
|   item.textureValues[shader->paramTexture] = 0; | ||||
|   item.start = this->startQuad * QUAD_INDICE_COUNT; | ||||
|   | ||||
| @@ -19,7 +19,7 @@ add_subdirectory(save) | ||||
| # Assets | ||||
| set(LIMINAL_ASSETS_DIR ${DAWN_ASSETS_DIR}/games/liminal) | ||||
|  | ||||
| tool_truetype(font_main ${LIMINAL_ASSETS_DIR}/fonts/Ysabeau-Medium.ttf) | ||||
| tool_truetype(font_main FILE=${LIMINAL_ASSETS_DIR}/fonts/Ysabeau-Medium.ttf) | ||||
| tool_texture(texture_eth FILE=${LIMINAL_ASSETS_DIR}/textures/eth.png) | ||||
| tool_texture(texture_border FILE=${LIMINAL_ASSETS_DIR}/textures/texture_test.png) | ||||
|  | ||||
|   | ||||
| @@ -5,6 +5,7 @@ | ||||
|  | ||||
| #include "game/DawnGame.hpp" | ||||
| #include "vnscenes/Scene1Prologue.hpp" | ||||
| #include "scenes/HelloWorldScene.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
|   | ||||
							
								
								
									
										36
									
								
								src/dawnliminal/scenes/HelloWorldScene.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/dawnliminal/scenes/HelloWorldScene.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| // Copyright (c) 2023 Dominic Masters | ||||
| //  | ||||
| // This software is released under the MIT License. | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #pragma once | ||||
| #include "scene/Scene.hpp" | ||||
| #include "prefabs/SimpleSpinningCubePrefab.hpp" | ||||
| #include "prefabs/ui/debug/FPSLabel.hpp" | ||||
| #include "scene/components/ui/UIImage.hpp" | ||||
| #include "display/font/BitmapFont.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
|   class HelloWorldScene : public Scene { | ||||
|     protected: | ||||
|       Camera *camera; | ||||
|       SimpleSpinningCubePrefab *cube; | ||||
|  | ||||
|       void stage() override { | ||||
|         camera = Camera::create(this); | ||||
|         camera->transform->lookAt(glm::vec3(100, 100, 100), glm::vec3(0, 0, 0)); | ||||
|  | ||||
|         // cube = SimpleSpinningCubePrefab::create(this); | ||||
|       } | ||||
|        | ||||
|       std::vector<Asset*> getRequiredAssets() override { | ||||
|         auto assMan = &this->game->assetManager; | ||||
|         std::vector<Asset*> assets; | ||||
|         vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan)); | ||||
|         return assets; | ||||
|       } | ||||
|  | ||||
|     public: | ||||
|       HelloWorldScene(DawnGame *game) : Scene(game) {} | ||||
|   }; | ||||
| } | ||||
| @@ -24,10 +24,14 @@ void RenderManager::init() { | ||||
|   this->lockUIShaderProgram = this->shaderManager.lockShader<SimpleTexturedShader>(); | ||||
|   this->uiShader = this->shaderManager.getShader<SimpleTexturedShader>(this->lockUIShaderProgram); | ||||
|  | ||||
|   this->lockFontShader = this->shaderManager.lockShader<FontShader>(); | ||||
|   this->fontShader = this->shaderManager.getShader<FontShader>(this->lockFontShader); | ||||
|  | ||||
|   this->renderPipeline.init(); | ||||
|  | ||||
|   // Prepare the initial values | ||||
|   glEnable(GL_TEXTURE_2D); | ||||
|   glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | ||||
|   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||||
|   glDepthMask(GL_TRUE); | ||||
|   glDepthFunc(GL_LESS); | ||||
| @@ -47,6 +51,10 @@ ShaderManager * RenderManager::getShaderManager() { | ||||
|   return &this->shaderManager; | ||||
| } | ||||
|  | ||||
| FontManager * RenderManager::getFontManager() { | ||||
|   return &this->fontManager;  | ||||
| } | ||||
|  | ||||
| void RenderManager::setRenderFlags(renderflag_t flags) { | ||||
|   this->renderFlags = flags; | ||||
|    | ||||
| @@ -70,4 +78,5 @@ void RenderManager::update() { | ||||
| RenderManager::~RenderManager() { | ||||
|   this->shaderManager.releaseShader<SimpleTexturedShader>(this->lockSimpleTextured); | ||||
|   this->shaderManager.releaseShader<SimpleTexturedShader>(this->lockUIShaderProgram); | ||||
|   this->shaderManager.releaseShader<FontShader>(this->lockFontShader); | ||||
| } | ||||
| @@ -8,8 +8,10 @@ | ||||
| #include "display/BackBufferRenderTarget.hpp" | ||||
| #include "display/shader/ShaderManager.hpp" | ||||
| #include "display/shader/SimpleTexturedShader.hpp" | ||||
| #include "display/shader/FontShader.hpp" | ||||
| #include "display/shader/UIShaderProgram.hpp" | ||||
| #include "display/RenderPipeline.hpp" | ||||
| #include "display/font/FontManager.hpp" | ||||
| #include "display/font/ExampleFont.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
| @@ -17,13 +19,16 @@ namespace Dawn { | ||||
|     private: | ||||
|       RenderPipeline renderPipeline; | ||||
|       ShaderManager shaderManager; | ||||
|       FontManager fontManager; | ||||
|       shaderlock_t lockSimpleTextured = -1; | ||||
|       shaderlock_t lockUIShaderProgram = -1; | ||||
|       shaderlock_t lockFontShader = -1; | ||||
|  | ||||
|     public: | ||||
|       BackBufferRenderTarget backBuffer; | ||||
|       SimpleTexturedShader *simpleTexturedShader = nullptr; | ||||
|       SimpleTexturedShader *uiShader = nullptr; | ||||
|       FontShader *fontShader = nullptr; | ||||
|       ExampleFont defaultFont; | ||||
|  | ||||
|       /** | ||||
| @@ -34,6 +39,7 @@ namespace Dawn { | ||||
|       RenderTarget * getBackBuffer() override; | ||||
|       RenderPipeline * getRenderPipeline() override; | ||||
|       ShaderManager * getShaderManager() override; | ||||
|       FontManager * getFontManager() override; | ||||
|       void setRenderFlags(renderflag_t renderFlags) override; | ||||
|       void init() override; | ||||
|       void update() override; | ||||
|   | ||||
| @@ -30,7 +30,10 @@ int32_t Texture::getHeight() { | ||||
| } | ||||
|  | ||||
| void Texture::setSize(int32_t width, int32_t height, enum TextureFormat format) { | ||||
|   if(this->id != -1) glDeleteTextures(1, &this->id); | ||||
|   if(this->id != -1) { | ||||
|     glDeleteTextures(1, &this->id); | ||||
|     this->id = -1; | ||||
|   } | ||||
|  | ||||
|   this->width = width; | ||||
|   this->height = height; | ||||
| @@ -101,11 +104,13 @@ void Texture::updateTextureProperties() { | ||||
|  | ||||
|   switch(((enum TextureFilterMode)this->filterModeMin)) { | ||||
|     case TEXTURE_FILTER_MODE_NEAREST: | ||||
|       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); | ||||
|       // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); | ||||
|       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||||
|       break; | ||||
|      | ||||
|     case TEXTURE_FILTER_MODE_LINEAR: | ||||
|       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); | ||||
|       // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); | ||||
|       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||||
|       break; | ||||
|  | ||||
|     default: | ||||
| @@ -114,11 +119,13 @@ void Texture::updateTextureProperties() { | ||||
|  | ||||
|   switch(((enum TextureFilterMode)this->filterModeMag)) { | ||||
|     case TEXTURE_FILTER_MODE_NEAREST: | ||||
|       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); | ||||
|       // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); | ||||
|       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||||
|       break; | ||||
|      | ||||
|     case TEXTURE_FILTER_MODE_LINEAR: | ||||
|       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); | ||||
|       // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); | ||||
|       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||||
|       break; | ||||
|  | ||||
|     default: | ||||
| @@ -157,7 +164,7 @@ void Texture::bufferRaw(void *data) { | ||||
|     this->width, this->height, | ||||
|     0, format, GL_UNSIGNED_BYTE, data | ||||
|   ); | ||||
|   glGenerateMipmap(GL_TEXTURE_2D); | ||||
|   // glGenerateMipmap(GL_TEXTURE_2D); | ||||
|   this->texturePropertiesNeedUpdating = true; | ||||
| } | ||||
|  | ||||
| @@ -165,6 +172,10 @@ void Texture::buffer(struct Color pixels[]) { | ||||
|   this->bufferRaw((void*)pixels); | ||||
| } | ||||
|  | ||||
| void Texture::buffer(uint8_t pixels[]) { | ||||
|   this->bufferRaw((void*)pixels); | ||||
| } | ||||
|  | ||||
| Texture::~Texture() { | ||||
|   if(this->id != -1) glDeleteTextures(1, &this->id); | ||||
| } | ||||
| @@ -32,6 +32,7 @@ namespace Dawn { | ||||
|       void fill(struct Color) override; | ||||
|       bool_t isReady() override; | ||||
|       void buffer(struct Color pixels[]) override; | ||||
|       void buffer(uint8_t pixels[]) override; | ||||
|        | ||||
|       /** | ||||
|        * Binds the texture to the given slot (for use by the shaders). | ||||
|   | ||||
| @@ -7,6 +7,7 @@ | ||||
| target_sources(${DAWN_TARGET_NAME} | ||||
|   PRIVATE | ||||
|     ShaderProgram.cpp | ||||
|     FontShader.cpp | ||||
|     SimpleTexturedShader.cpp | ||||
|     SimpleBillboardedShader.cpp | ||||
| ) | ||||
							
								
								
									
										69
									
								
								src/dawnopengl/display/shader/FontShader.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								src/dawnopengl/display/shader/FontShader.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| // Copyright (c) 2023 Dominic Masters | ||||
| //  | ||||
| // This software is released under the MIT License. | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #include "FontShader.hpp" | ||||
| #include "scene/components/display/mesh/MeshRenderer.hpp" | ||||
| #include "scene/components/display/Camera.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| void FontShaderProgram::compile() { | ||||
|   #if DAWN_OPENGL_GLSL | ||||
|     this->compileShader( | ||||
|       { | ||||
|         { "aPos", 0 }, | ||||
|         { "aTexCoord", 1 } | ||||
|       }, | ||||
|       // Vertex Shader | ||||
|       "#version 330 core\n" | ||||
|       "layout (location = 0) in vec3 aPos;\n" | ||||
|       "layout (location = 1) in vec2 aTexCoord;\n" | ||||
|  | ||||
|       "uniform mat4 u_Proj;\n" | ||||
|       "uniform mat4 u_View;\n" | ||||
|       "uniform mat4 u_Model;\n" | ||||
|  | ||||
|       "out vec2 o_TextCoord;\n" | ||||
|       "void main() {\n" | ||||
|         "gl_Position = u_Proj * u_View * u_Model * vec4(aPos, 1.0);\n" | ||||
|         "o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n" | ||||
|       "}", | ||||
|  | ||||
|       // Fragment Shader | ||||
|       "#version 330 core\n" | ||||
|       "in vec2 o_TextCoord;\n" | ||||
|       "out vec4 o_Color;\n" | ||||
|       "uniform vec4 u_Color;\n" | ||||
|       "uniform bool u_HasTexture;\n" | ||||
|       "uniform sampler2D u_Text;\n" | ||||
|  | ||||
|       "void main() {\n" | ||||
|         "o_Color = u_Color;\n" | ||||
|         "o_Color.a *= texture(u_Text, o_TextCoord).r;\n" | ||||
|       "}\n" | ||||
|     ); | ||||
|   #else | ||||
|     #error Shader Type unknown | ||||
|   #endif | ||||
|  | ||||
|   this->paramProjection = this->getParameterByName("u_Proj"); | ||||
|   this->paramView = this->getParameterByName("u_View"); | ||||
|   this->paramModel = this->getParameterByName("u_Model"); | ||||
|   this->paramColor = this->getParameterByName("u_Color"); | ||||
|   this->paramTexture = this->getParameterByName("u_Text"); | ||||
| } | ||||
|  | ||||
| void FontShader::compile() { | ||||
|   this->program.compile(); | ||||
| } | ||||
|  | ||||
| std::vector<struct ShaderPassItem> FontShader::getPassItems( | ||||
|   Mesh *mesh, | ||||
|   Material *material, | ||||
|   Camera *camera | ||||
| ) { | ||||
|   std::vector<struct ShaderPassItem> passes; | ||||
|   return passes; | ||||
| } | ||||
							
								
								
									
										39
									
								
								src/dawnopengl/display/shader/FontShader.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/dawnopengl/display/shader/FontShader.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| // Copyright (c) 2023 Dominic Masters | ||||
| //  | ||||
| // This software is released under the MIT License. | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #pragma once | ||||
| // Copyright (c) 2023 Dominic Masters | ||||
| //  | ||||
| // This software is released under the MIT License. | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #pragma once | ||||
| #include "display/shader/ShaderManager.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
|   class FontShaderProgram : public ShaderProgram { | ||||
|     public: | ||||
|       shaderparameter_t paramProjection; | ||||
|       shaderparameter_t paramView; | ||||
|       shaderparameter_t paramModel; | ||||
|       shaderparameter_t paramColor; | ||||
|       shaderparameter_t paramTexture; | ||||
|  | ||||
|       void compile() override; | ||||
|   }; | ||||
|  | ||||
|   class FontShader : public Shader { | ||||
|     public: | ||||
|       FontShaderProgram program; | ||||
|  | ||||
|       void compile() override; | ||||
|  | ||||
|       std::vector<struct ShaderPassItem> getPassItems( | ||||
|         Mesh *mesh, | ||||
|         Material *material, | ||||
|         Camera *camera | ||||
|       ) override; | ||||
|   }; | ||||
| } | ||||
| @@ -36,14 +36,33 @@ target_link_libraries(truetypetool | ||||
| ) | ||||
|  | ||||
| # Tool Function | ||||
| function(tool_truetype target in) | ||||
| function(tool_truetype target) | ||||
|   # Defaults | ||||
|   set(FILE "" ) | ||||
|  | ||||
|   # Parse Args | ||||
|   foreach(_PAIR IN LISTS ARGN) | ||||
|     if (_PAIR MATCHES "^([^:]+)=(.*)$") | ||||
|       set(${CMAKE_MATCH_1} ${CMAKE_MATCH_2}) | ||||
|     else() | ||||
|       message(FATAL_ERROR "Invalid pair: ${_PAIR}") | ||||
|     endif() | ||||
|   endforeach() | ||||
|  | ||||
|   # Check for missing args | ||||
|   if(NOT DEFINED FILE) | ||||
|     message(FATAL_ERROR "Missing FILE input") | ||||
|   endif() | ||||
|  | ||||
|   set(DEPS "") | ||||
|   if(DAWN_BUILD_TOOLS) | ||||
|     set(DEPS truetypetool) | ||||
|   endif() | ||||
|  | ||||
|   add_custom_target(${target} | ||||
|     COMMAND truetypetool --input="${DAWN_ASSETS_SOURCE_DIR}/${in}" --output="${DAWN_ASSETS_BUILD_DIR}/${target}" | ||||
|     COMMAND truetypetool | ||||
|       --input="${DAWN_ASSETS_SOURCE_DIR}/${FILE}" | ||||
|       --output="${DAWN_ASSETS_BUILD_DIR}/${target}" | ||||
|     COMMENT "Generating truetype font ${target} from ${in}" | ||||
|     DEPENDS ${DEPS} | ||||
|   ) | ||||
|   | ||||
| @@ -56,13 +56,10 @@ int32_t TrueTypeTool::start() { | ||||
|  | ||||
|   // Write data | ||||
|   fileOut.writeString(std::to_string(width) + "|" + std::to_string(height) + "|" + std::to_string(fontSize) + "|"); | ||||
|   uint8_t pixels[4]; | ||||
|   uint8_t pixels[1]; | ||||
|   for(size_t i = 0; i < textureSize; i++) { | ||||
|     pixels[0] = 255; | ||||
|     pixels[1] = 255; | ||||
|     pixels[2] = 255; | ||||
|     pixels[3] = bitmapData[i]; | ||||
|     fileOut.writeRaw((char*)pixels, 4); | ||||
|     pixels[0] = bitmapData[i]; | ||||
|     fileOut.writeRaw((char*)pixels, 1); | ||||
|   } | ||||
|  | ||||
|   // Write quads | ||||
|   | ||||
		Reference in New Issue
	
	Block a user