larger font hack + linear texture filter for images
This commit is contained in:
parent
b1062e701e
commit
e76e56e025
17
src/main.cpp
17
src/main.cpp
@ -58,6 +58,23 @@ int main(int argc, char** argv) {
|
||||
//ImGui::StyleColorsDark();
|
||||
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());
|
||||
auto imgui_sdl_scope = std::async(std::launch::deferred, &ImGui_ImplSDL3_Shutdown);
|
||||
ImGui_ImplSDLRenderer3_Init(renderer.get());
|
||||
|
@ -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
|
||||
SDL_Surface* surf = SDL_CreateSurfaceFrom(
|
||||
(void*)data,
|
||||
@ -17,6 +17,13 @@ uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t wi
|
||||
);
|
||||
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);
|
||||
assert(tex); // TODO: add error reporting
|
||||
|
||||
|
@ -10,7 +10,7 @@ struct SDLRendererTextureUploader : public TextureUploaderI {
|
||||
SDLRendererTextureUploader(SDL_Renderer* renderer_);
|
||||
~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;
|
||||
};
|
||||
|
||||
|
@ -5,10 +5,14 @@
|
||||
struct TextureUploaderI {
|
||||
static constexpr const char* version {"1"};
|
||||
|
||||
enum Filter {
|
||||
NEAREST,
|
||||
LINEAR,
|
||||
};
|
||||
|
||||
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) = 0;
|
||||
virtual uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter = LINEAR) = 0;
|
||||
|
||||
virtual void destroy(uint64_t tex_id) = 0;
|
||||
};
|
||||
|
@ -203,7 +203,7 @@ std::optional<TextureEntry> ToxAvatarLoader::load(TextureUploaderI& tu, Contact3
|
||||
new_entry.timestamp_last_rendered = Message::getTimeMS();
|
||||
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.frame_duration.push_back(250);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user