diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index 83d72881..81fe2649 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -22,6 +22,8 @@ #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif +#define BITMAP_FONT_TEST 1 + int main(int, char**) { // Setup SDL @@ -104,6 +106,41 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); +#if BITMAP_FONT_TEST + static ImWchar const ranges[] = { 0x20, 0x7f, 0 }; + + ImFontAtlas *atlas = IM_NEW(ImFontAtlas)(); + atlas->TexWidth = 128; + atlas->TexHeight = 128; + atlas->TexUvScale = ImVec2(1.f / 128, 1.f / 128); + + ImFontConfig config; + config.FontData = malloc(1); + config.FontDataSize = 1; + config.FontDataOwnedByAtlas = false; + config.SizePixels = 8; + config.GlyphRanges = ranges; + ImFont *font = atlas->AddFont(&config); + + // Operations copied from ImFontAtlasBuildSetupFont() + font->FontSize = config.SizePixels; + font->ConfigData = &atlas->ConfigData[0]; + font->ContainerAtlas = atlas; + font->Ascent = 0; + font->Descent = config.SizePixels; + font->ConfigDataCount++; + + // Add some glyphs from a hypothetical regular grid + for (int ch = 0x20; ch < 0x80; ++ch) + { + font->AddGlyph(ch, 0, 0, 6, 8, (ch % 0x10) * 8.f / 128, (ch / 0x10) * 8.f / 128, (ch % 0x10 + 1) * 8.f / 128, (ch / 0x10 + 1) * 8.f / 128, 6); + } + font->BuildLookupTable(); + + // Fake texture ID for testing purposes + atlas->TexID = io.Fonts->TexID; +#endif + bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); @@ -132,6 +169,10 @@ int main(int, char**) ImGui_ImplSDL2_NewFrame(window); ImGui::NewFrame(); +#if BITMAP_FONT_TEST + ImGui::PushFont(font); +#endif + // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). if (show_demo_window) ImGui::ShowDemoWindow(&show_demo_window); @@ -169,6 +210,10 @@ int main(int, char**) ImGui::End(); } +#if BITMAP_FONT_TEST + ImGui::PopFont(); +#endif + // Rendering ImGui::Render(); SDL_GL_MakeCurrent(window, gl_context);