git.haldean.org qb / main fonts.cpp
main

Tree @main (Download .tar.gz)

fonts.cpp @mainraw · history · blame

#include "cimgui/imgui/imgui.h"
#include "sokol/sokol_gfx.h"

namespace qb {
  void initfonts() {
    ImGui::GetIO().Fonts->AddFontFromFileTTF("data/InputMono-Regular.ttf", 14);

    unsigned char* font_pixels;
    int font_width, font_height;
    ImGui::GetIO().Fonts->GetTexDataAsRGBA32(
      &font_pixels, &font_width, &font_height);

    sg_image_desc img_desc;
    memset(&img_desc, 0, sizeof(img_desc));
    img_desc.width = font_width;
    img_desc.height = font_height;
    img_desc.pixel_format = SG_PIXELFORMAT_RGBA8;
    img_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE;
    img_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE;
    img_desc.min_filter = SG_FILTER_LINEAR;
    img_desc.mag_filter = SG_FILTER_LINEAR;
    img_desc.data.subimage[0][0].ptr = font_pixels;
    img_desc.data.subimage[0][0].size =
      (size_t)(font_width * font_height) * sizeof(uint32_t);
    img_desc.label = "input-serif-12";
    sg_image img = sg_make_image(&img_desc);
    ImGui::GetIO().Fonts->TexID = (ImTextureID)(uintptr_t) img.id;
  }
}