larger font hack + linear texture filter for images

This commit is contained in:
Green Sky 2024-01-21 13:58:22 +01:00
parent b1062e701e
commit e76e56e025
No known key found for this signature in database
5 changed files with 33 additions and 5 deletions

View File

@ -58,6 +58,23 @@ int main(int argc, char** argv) {
//ImGui::StyleColorsDark(); //ImGui::StyleColorsDark();
setThemeGreen(); setThemeGreen();
{
ImGui::GetIO().Fonts->ClearFonts();
ImFontConfig fontcfg;
// upsampling to int looks almost ok
const float font_size_scale = 1.3f;
const float font_oversample = 4.f;
// default font is pixel perfect at 13
fontcfg.SizePixels = 13.f * font_size_scale;
fontcfg.RasterizerDensity = font_oversample/font_size_scale;
// normally density would be set to dpi scale of the display
ImGui::GetIO().Fonts->AddFontDefault(&fontcfg);
ImGui::GetIO().Fonts->Build();
}
ImGui_ImplSDL3_InitForSDLRenderer(window.get(), renderer.get()); ImGui_ImplSDL3_InitForSDLRenderer(window.get(), renderer.get());
auto imgui_sdl_scope = std::async(std::launch::deferred, &ImGui_ImplSDL3_Shutdown); auto imgui_sdl_scope = std::async(std::launch::deferred, &ImGui_ImplSDL3_Shutdown);
ImGui_ImplSDLRenderer3_Init(renderer.get()); ImGui_ImplSDLRenderer3_Init(renderer.get());

View File

@ -7,7 +7,7 @@ SDLRendererTextureUploader::SDLRendererTextureUploader(SDL_Renderer* renderer_)
{ {
} }
uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height) { uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter) {
// TODO: test if pitch is 4 or 4*width // TODO: test if pitch is 4 or 4*width
SDL_Surface* surf = SDL_CreateSurfaceFrom( SDL_Surface* surf = SDL_CreateSurfaceFrom(
(void*)data, (void*)data,
@ -17,6 +17,13 @@ uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t wi
); );
assert(surf); // TODO: add error reporting assert(surf); // TODO: add error reporting
// TODO: this touches global state, reset?
if (filter == NEAREST) {
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
} else if (filter == LINEAR) {
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
}
SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, surf); SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, surf);
assert(tex); // TODO: add error reporting assert(tex); // TODO: add error reporting

View File

@ -10,7 +10,7 @@ struct SDLRendererTextureUploader : public TextureUploaderI {
SDLRendererTextureUploader(SDL_Renderer* renderer_); SDLRendererTextureUploader(SDL_Renderer* renderer_);
~SDLRendererTextureUploader(void) = default; ~SDLRendererTextureUploader(void) = default;
uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height) override; uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter) override;
void destroy(uint64_t tex_id) override; void destroy(uint64_t tex_id) override;
}; };

View File

@ -5,10 +5,14 @@
struct TextureUploaderI { struct TextureUploaderI {
static constexpr const char* version {"1"}; static constexpr const char* version {"1"};
enum Filter {
NEAREST,
LINEAR,
};
virtual ~TextureUploaderI(void) {} virtual ~TextureUploaderI(void) {}
//virtual uint64_t uploadRGBA(const uint8_t* data, uint64_t data_size) = 0; virtual uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter = LINEAR) = 0;
virtual uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height) = 0;
virtual void destroy(uint64_t tex_id) = 0; virtual void destroy(uint64_t tex_id) = 0;
}; };

View File

@ -203,7 +203,7 @@ std::optional<TextureEntry> ToxAvatarLoader::load(TextureUploaderI& tu, Contact3
new_entry.timestamp_last_rendered = Message::getTimeMS(); new_entry.timestamp_last_rendered = Message::getTimeMS();
new_entry.current_texture = 0; new_entry.current_texture = 0;
const auto n_t = tu.uploadRGBA(pixels.data(), 5, 5); const auto n_t = tu.uploadRGBA(pixels.data(), 5, 5, TextureUploaderI::NEAREST);
new_entry.textures.push_back(n_t); new_entry.textures.push_back(n_t);
new_entry.frame_duration.push_back(250); new_entry.frame_duration.push_back(250);