master
parent
056b0b307b
commit
dbc2000434
@ -0,0 +1,62 @@ |
||||
#include <fmt/core.h> |
||||
#include "dbc.hpp" |
||||
#include <SFML/Graphics.hpp> |
||||
#include <SFML/Graphics/RenderWindow.hpp> |
||||
#include "constants.hpp" |
||||
|
||||
int main() { |
||||
unsigned int font_size = 30; |
||||
sf::Vector2u size{32, 32}; |
||||
|
||||
sf::RenderTexture render{size}; |
||||
render.setSmooth(false); |
||||
|
||||
sf::Font font{FONT_FILE_NAME}; |
||||
font.setSmooth(false); |
||||
|
||||
wchar_t display_char = 3848; |
||||
std::wstring content{display_char}; |
||||
sf::Text icon{font, content, font_size}; |
||||
|
||||
icon.setFillColor({0, 0, 0, 255}); |
||||
render.draw(icon); |
||||
render.clear({0,0,0,0}); |
||||
|
||||
// fit the glyph in our box height
|
||||
auto glyph = font.getGlyph(content[0], font_size, false); |
||||
|
||||
while(glyph.textureRect.size.y < int(size.y)-1) { |
||||
font_size++; |
||||
glyph = font.getGlyph(content[0], font_size, false); |
||||
} |
||||
|
||||
auto font_texture = font.getTexture(font_size); |
||||
sf::Sprite sprite{font_texture, glyph.textureRect}; |
||||
auto t_size = glyph.textureRect.size; |
||||
|
||||
dbc::check(int(size.x - t_size.x) > 0, "font too big on x"); |
||||
dbc::check(int(size.y - t_size.y) > 0, "font too big on y"); |
||||
|
||||
sf::Vector2f center{ |
||||
(float(size.x) - float(t_size.x)) / 2.0f, |
||||
(float(size.y) - float(t_size.y)) / 2.0f}; |
||||
|
||||
sf::Vector2f scale{float(size.x) / float(t_size.x), float(size.y) / float(t_size.y)}; |
||||
|
||||
fmt::println("scale={},{}; t_size={},{}; size={},{}", |
||||
scale.x, scale.y, t_size.x, t_size.y, size.x, size.y); |
||||
|
||||
sprite.setScale(scale); |
||||
|
||||
sprite.setPosition({0,0}); |
||||
sprite.setColor({0, 0, 0, 255}); |
||||
|
||||
render.draw(sprite); |
||||
render.display(); |
||||
sf::Image out_img = render.getTexture().copyToImage(); |
||||
|
||||
bool worked = out_img.saveToFile("./screenshot.png"); |
||||
dbc::check(worked, "Failed to write screenshot.png"); |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue