78 lines
2.3 KiB
C++
78 lines
2.3 KiB
C++
/**
|
|
This file is a part of our_dick
|
|
Copyright (C) 2022 rexy712
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef OUR_DICK_ENGINE_FONT_HPP
|
|
#define OUR_DICK_ENGINE_FONT_HPP
|
|
|
|
#include <freetype2/ft2build.h>
|
|
#include FT_FREETYPE_H
|
|
#include <map>
|
|
#include <optional>
|
|
|
|
#include "graphics/texture.hpp"
|
|
#include "config.hpp"
|
|
|
|
namespace egn{
|
|
|
|
class font
|
|
{
|
|
private:
|
|
//ascii texture atlas
|
|
const char* m_bitmap_handle;
|
|
//When rendering unicode, load up new textures per code page to create many atlases
|
|
std::map<int, const char*> m_extra_codepages;
|
|
//stb or freetype font handle
|
|
|
|
public:
|
|
//load the font file and process it with stb/freetype lib
|
|
//render out basic ascii characters to bitmap texture atlas
|
|
//maybe do signed distance fonts? example: https://github.com/ShoYamanishi/SDFont
|
|
//dynamically add new codepage textures for rendering non-ascii
|
|
};
|
|
|
|
class font_generator
|
|
{
|
|
private:
|
|
static inline bool s_initialized = false;
|
|
static inline FT_Library s_ft;
|
|
|
|
private:
|
|
FT_Face m_face = nullptr;
|
|
|
|
public:
|
|
font_generator(const char* file);
|
|
~font_generator(void);
|
|
|
|
//params:
|
|
// start_codepoint: unicode character at which the atlas starts
|
|
// count: number of characters to make in the atlas
|
|
// glyph_width: requested pixel width of glyph
|
|
// glyph_height: requested pixel height of glyph
|
|
// atlas_width: requested pixel width of atlas
|
|
// atlas_height: requested pixel height of atlas
|
|
std::optional<gfx::texture> generate_atlas(int start_codepoint, int count, int glyph_width, int glyph_height, int atlas_width, int atlas_height);
|
|
std::optional<gfx::texture> generate_glyph(char character, int width, int height);
|
|
|
|
private:
|
|
static bool initialize_freetype_(void);
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|